Announcement

Collapse
No announcement yet.

Bitmasking with a global variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bitmasking with a global variable

    Hi,

    Does anyone know of a way to do Bitmasking with a Global Variable in an Event. I am trying to simplfy how I do home presence updates, and I want to do something like:
    Every Two Minutes
    If Person_A is Home
    Home Indicator = HomeIndicator LOGICAL_OR Person_A_Home_Mask (00100)
    If Person_A is Away
    Home Indicator = HomeIndicator LOGICAL_AND Person_A_Away_Mask (11011)
    etc...

    Then I could check every few minutes to see if the HomeIndicator is Clear

    Thanks,
    Lou

    #2
    Quick follow-up

    I couldn't figure out how to do it in a Homeseer event, so I did it in Homeseer VBScript and it was super easy, and simplified my events quite a bit.

    In summary, I created a script which triggers every two minutes, and does the bit-masking on a device. Here is a snip-it of the code:
    Dim Occupany_Mask_Clear As Integer = &h0000 '0000-0000-0000-0000
    Dim Occupany_Mask_Set_Lou As Integer = &h0080 '0000-0000-1000-0000
    Dim Occupany_Mask_Clear_Lou As Integer = &hFF7F '1111-1111-0111-1111

    Dim DVRef_Home_Occupancy As Integer = 9999 'This is the Virtual Device that will trigger Alarm setting
    Dim Life360_Home_Lou As Integer = 8888

    Dim Interim_Indicator As Integer = Occupany_Mask_Clear

    If hs.DeviceValue(Life360_Home_Lou) = 1 Then
    Interim_Indicator = Interim_Indicator OR Occupany_Mask_Set_Lou
    End If

    hs.SetDeviceValueByRef(DVRef_Home_Occupancy, Interim_Indicator, True)


    Then I have another event that check the device value periodically and engages the Alarm based upon Occupancy and Time of Day.

    Comment


      #3
      You can do it in an event with an immediate command - I have a bitmasked status on one of my controls (device 1706) to show multiple things going on in parallel.

      Set: &hs.SetDeviceValueByRef(1706, hs.DeviceValue(1706) Or 1, true)
      Unset: &hs.SetDeviceValueByRef(1706, hs.DeviceValue(1706) And 254, true)

      Click image for larger version

Name:	image.png
Views:	28
Size:	11.7 KB
ID:	1597770

      To add more context, I have a device (from my ControlsPlus plugin, but that's not the point)with two buttons that trigger events to vent rooms. Each room has two events:

      * Event on button press - open window(s), start timer, set bit in device

      * Event on timer 15 mins - close window(s), stop timer, clear bit in device,

      This works nicely because if you click the button again it extends the vent time for another 15 minutes, and the device shows the status based on the bitmap.

      Click image for larger version

Name:	image.png
Views:	48
Size:	22.2 KB
ID:	1597769
      When I get another room with Velux windows I'll extend this ​to have bit 4 as well.

      Comment


        #4
        Thank you, I didn't know about the immediate commands, that will work nicely.

        Thanks!

        Comment

        Working...
        X