Announcement

Collapse
No announcement yet.

vDevice state based on states from multiple devices - easier way?

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

    vDevice state based on states from multiple devices - easier way?

    I like to have vDevices that show Status (and Control for relevant devices) for multiple like-devices. I call these Composite Devices

    For instance:

    Door Locks ... single device to show if any doors are unlocked or all doors are locked; and with a single button press it can lock/unlock all of them

    Door and/or Motion Sensors... single device will show motion if ANY of the sensors in the group have motion

    these are very useful for setting Home Modes, checking Occupancy, quickly locking all doors, or simply seeing status.


    thx for the help
    Is there an easier way to do this that I'm missing or must I do it like the attached screen shot?
    Attached Files

    #2
    This post describes the most efficient way I've seen so far to determine if all devices are in a given state using just events.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Originally posted by Uncle Michael View Post
      This post describes the most efficient way I've seen so far to determine if all devices are in a given state using just events.
      Got it, thank you. Looks like I'm going to have to brush up on vbscript. The event engine in Homeseer is way to inefficient and tedious. Seems like a few tweaks and it could be awesome, but it's more like the pretty girl that is such a pain, no one wants to date her.

      Sent from my SAMSUNG-SM-G935A using Tapatalk

      Comment


        #4
        I treat my virtual device like a binary byte. Each of my 4 occupancy motion sensors is assigned a bit.

        Whenever a motion sensor comes on I set it's bit. When it turns off I clear it (you have to do a single line vb script to do that).

        498 is the RefID of the virtual device, mask is passed into the script from the event.

        Sub LDRsetBit(mask)
        hs.SetDeviceValueByRef(498, hs.DeviceValue(498) Or mask, True)
        End Sub

        Sub LDRclearBit(mask)
        hs.SetDeviceValueByRef(498, hs.DeviceValue(498) And mask, True)
        End Sub

        So whenever the virtual device is zero I know all the sensors are off, if non-zero, then someone is still home. I set the motion timeouts to 15 minutes.

        Additionally I need to know if a sensor has come on, or it's just timing out. I use bit 7 (128) to determine when a sensor turns on by setting it whenever a sensor turns on (don't care which one) and clearing it when ever a sensor turns off.

        So if the virtual device > 128 then I know a sensor has turned on vs timing out.

        The reason for this is because when the last person leaves the house the sensors will start timing out for which no action is needed. But if the house is supposed to be empty and the value goes > 128 then something is wrong and I need to start capturing video from inside the house and check the cameras for what might have caused a sensor to turn on.

        Haven't figured out how to handle a power failure, fortunately where I live these are rare occurrences.

        Comment


          #5
          Originally posted by andyf View Post
          I treat my virtual device like a binary byte. Each of my 4 occupancy motion sensors is assigned a bit.

          Whenever a motion sensor comes on I set it's bit. When it turns off I clear it (you have to do a single line vb script to do that).

          498 is the RefID of the virtual device, mask is passed into the script from the event.

          Sub LDRsetBit(mask)
          hs.SetDeviceValueByRef(498, hs.DeviceValue(498) Or mask, True)
          End Sub

          Sub LDRclearBit(mask)
          hs.SetDeviceValueByRef(498, hs.DeviceValue(498) And mask, True)
          End Sub

          So whenever the virtual device is zero I know all the sensors are off, if non-zero, then someone is still home. I set the motion timeouts to 15 minutes.

          Additionally I need to know if a sensor has come on, or it's just timing out. I use bit 7 (128) to determine when a sensor turns on by setting it whenever a sensor turns on (don't care which one) and clearing it when ever a sensor turns off.

          So if the virtual device > 128 then I know a sensor has turned on vs timing out.
          I like that method... Has the making of a useful plugin [emoji6]

          Sent from my SAMSUNG-SM-G935A using Tapatalk

          Comment


            #6
            I am using virtual devices to display security sensor status, TRV setpoints etc

            I use this script to display the status of my door and window status, if none of them is open, it says all doors and windows are closed. (This script is only for the windows and doors, I run another script for the TRV's, another one for my PV system etc.)
            If any of them are open it lists which are open. Easy to see what is open.
            Just create a event which triggers when any of the devices change state

            Code:
            dim array_windows() as string = {"Bedroom Right Window","Bedroom Left Window","Cloakroom window"}
            dim array_doors() as string = {"Garage Door","Porch Door","Kitchen Back Door","Patio Door","Bedroom Door"}
            dim windows_count as integer = 0
            dim doors_count as integer = 0
            dim door_name as String = ""
            dim dstr as string = ""
            dim window_name as string = ""
            dim wstr as string = ""
             
            sub windows(ByVal Parms as Object)
            Try
            windows_count = 0
            window_name = ""
            wstr = ""
             for each devw as string in array_windows
                if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
                    windows_count = windows_count + 1
                    window_name = devw
                    wstr = wstr & window_name & " Opened" & "<br>"
                Else If hs.DeviceValueByName(devw) = 0 then 'No windows open
                end if
            next
                If windows_count > 0 then 
                    hs.SetDeviceValueByRef(439,100,true)
                    hs.SetDeviceString(439, wstr,true)
                Else
                    hs.SetDeviceValueByRef(439,0,true)
                    hs.SetDeviceString(439, "All Windows Closed",true)
                End If
                
                hs.writelog("Array", "Window Count: " & windows_count)
             Catch ex As Exception
            hs.WriteLog ("Array", "Error: " & ex.Message)
            End Try
            End Sub
             sub doors(ByVal Parms as Object)
            Try
            doors_count = 0
            door_name = ""
            dstr = ""
            for each devd as string in array_doors
                if hs.DeviceValueByName(devd) = 255 or hs.DeviceValueByName(devd) = 100 or hs.DeviceValueByName(devd) = 22 then
                    doors_count = doors_count + 1
                    door_name = devd
                    dstr = dstr & door_name & " Opened" & "<br>"
                Else If hs.DeviceValueByName(devd) = 0 then 'No doors open
                end if
            next
                If doors_count > 0 then 
                    hs.SetDeviceValueByRef(438,100,true) 'was 170
                    hs.SetDeviceString(438, dstr,true) 'was 170
                Else
                    hs.SetDeviceValueByRef(438,0,true)
                    hs.SetDeviceString(438, "All Doors Closed",true)
                End If
            Catch ex As Exception
            hs.WriteLog ("Array", "Error: " & ex.Message)
            End Try
            End Sub
            Attached Files

            Comment


              #7
              Originally posted by mikee123 View Post
              I am using virtual devices to display security sensor status, TRV setpoints etc

              I use this script to display the status of my door and window status, if none of them is open, it says all doors and windows are closed. (This script is only for the windows and doors, I run another script for the TRV's, another one for my PV system etc.)
              If any of them are open it lists which are open. Easy to see what is open.
              Just create a event which triggers when any of the devices change state

              Code:
              dim array_windows() as string = {"Bedroom Right Window","Bedroom Left Window","Cloakroom window"}
              dim array_doors() as string = {"Garage Door","Porch Door","Kitchen Back Door","Patio Door","Bedroom Door"}
              dim windows_count as integer = 0
              dim doors_count as integer = 0
              dim door_name as String = ""
              dim dstr as string = ""
              dim window_name as string = ""
              dim wstr as string = ""
               
              sub windows(ByVal Parms as Object)
              Try
              windows_count = 0
              window_name = ""
              wstr = ""
               for each devw as string in array_windows
                  if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
                      windows_count = windows_count + 1
                      window_name = devw
                      wstr = wstr & window_name & " Opened" & "<br>"
                  Else If hs.DeviceValueByName(devw) = 0 then 'No windows open
                  end if
              next
                  If windows_count > 0 then 
                      hs.SetDeviceValueByRef(439,100,true)
                      hs.SetDeviceString(439, wstr,true)
                  Else
                      hs.SetDeviceValueByRef(439,0,true)
                      hs.SetDeviceString(439, "All Windows Closed",true)
                  End If
                  
                  hs.writelog("Array", "Window Count: " & windows_count)
               Catch ex As Exception
              hs.WriteLog ("Array", "Error: " & ex.Message)
              End Try
              End Sub
               sub doors(ByVal Parms as Object)
              Try
              doors_count = 0
              door_name = ""
              dstr = ""
              for each devd as string in array_doors
                  if hs.DeviceValueByName(devd) = 255 or hs.DeviceValueByName(devd) = 100 or hs.DeviceValueByName(devd) = 22 then
                      doors_count = doors_count + 1
                      door_name = devd
                      dstr = dstr & door_name & " Opened" & "<br>"
                  Else If hs.DeviceValueByName(devd) = 0 then 'No doors open
                  end if
              next
                  If doors_count > 0 then 
                      hs.SetDeviceValueByRef(438,100,true) 'was 170
                      hs.SetDeviceString(438, dstr,true) 'was 170
                  Else
                      hs.SetDeviceValueByRef(438,0,true)
                      hs.SetDeviceString(438, "All Doors Closed",true)
                  End If
              Catch ex As Exception
              hs.WriteLog ("Array", "Error: " & ex.Message)
              End Try
              End Sub
              Exactly what I was going to do... THANK YOU for saving me 2-3 hours! (my VBA is rusty)

              Comment


                #8
                Quite Good!

                Originally posted by mikee123 View Post
                I am using virtual devices to display security sensor status, TRV setpoints etc

                I use this script to display the status of my door and window status, if none of them is open, it says all doors and windows are closed. (This script is only for the windows and doors, I run another script for the TRV's, another one for my PV system etc.)
                If any of them are open it lists which are open. Easy to see what is open.
                Just create a event which triggers when any of the devices change state

                Code:
                dim array_windows() as string = {"Bedroom Right Window","Bedroom Left Window","Cloakroom window"}
                dim array_doors() as string = {"Garage Door","Porch Door","Kitchen Back Door","Patio Door","Bedroom Door"}
                dim windows_count as integer = 0
                dim doors_count as integer = 0
                dim door_name as String = ""
                dim dstr as string = ""
                dim window_name as string = ""
                dim wstr as string = ""
                 
                sub windows(ByVal Parms as Object)
                Try
                windows_count = 0
                window_name = ""
                wstr = ""
                 for each devw as string in array_windows
                    if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
                        windows_count = windows_count + 1
                        window_name = devw
                        wstr = wstr & window_name & " Opened" & "<br>"
                    Else If hs.DeviceValueByName(devw) = 0 then 'No windows open
                    end if
                next
                    If windows_count > 0 then 
                        hs.SetDeviceValueByRef(439,100,true)
                        hs.SetDeviceString(439, wstr,true)
                    Else
                        hs.SetDeviceValueByRef(439,0,true)
                        hs.SetDeviceString(439, "All Windows Closed",true)
                    End If
                    
                    hs.writelog("Array", "Window Count: " & windows_count)
                 Catch ex As Exception
                hs.WriteLog ("Array", "Error: " & ex.Message)
                End Try
                End Sub
                 sub doors(ByVal Parms as Object)
                Try
                doors_count = 0
                door_name = ""
                dstr = ""
                for each devd as string in array_doors
                    if hs.DeviceValueByName(devd) = 255 or hs.DeviceValueByName(devd) = 100 or hs.DeviceValueByName(devd) = 22 then
                        doors_count = doors_count + 1
                        door_name = devd
                        dstr = dstr & door_name & " Opened" & "<br>"
                    Else If hs.DeviceValueByName(devd) = 0 then 'No doors open
                    end if
                next
                    If doors_count > 0 then 
                        hs.SetDeviceValueByRef(438,100,true) 'was 170
                        hs.SetDeviceString(438, dstr,true) 'was 170
                    Else
                        hs.SetDeviceValueByRef(438,0,true)
                        hs.SetDeviceString(438, "All Doors Closed",true)
                    End If
                Catch ex As Exception
                hs.WriteLog ("Array", "Error: " & ex.Message)
                End Try
                End Sub

                I'm no programmer - But I feel confident I could adapt that for my occupancy uses.

                I see it is for the doors and windows only - could you share one for motion detectors? Or maybe I should be able to adapt this one..?

                I use hardwired sensors and monitor via ELK security plugin zones. This is what my current mess looks like but I don't really like it.

                Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	22.3 KB
ID:	1191051

                Comment


                  #9
                  This is what I use to display motion

                  Code:
                  dim array_motion() as string = {"Hall Motion Sensor","Front door motion sensor","Garage Motion Sensor"}
                  dim motions_count as integer = 0
                  dim motion_name as string = ""
                  dim wstr as string = ""
                   
                  sub motion(ByVal Parms as Object)
                  Try
                  motions_count = 0
                  motion_name = ""
                  wstr = ""
                   for each devw as string in array_motion
                      if hs.DeviceValueByName(devw) = 255 or hs.DeviceValueByName(devw) = 100 then
                          motions_count = motions_count + 1
                          motion_name = devw
                          wstr = wstr & motion_name & " <span style='color:red'>MOTION</span>" & "<br>"
                      Else If hs.DeviceValueByName(devw) = 0 then 
                      end if
                  next
                      If motions_count > 0 then 
                          hs.SetDeviceValueByRef(470,100,true)
                          hs.SetDeviceString(470, wstr,true)
                      Else
                          hs.SetDeviceValueByRef(470,0,true)
                          hs.SetDeviceString(470, "No Motion",true)
                      End If
                      
                      hs.writelog("Array", "Motion Sensor Count: " & motions_count)
                   Catch ex As Exception
                  hs.WriteLog ("Array", "Error: " & ex.Message)
                  End Try
                  End Sub
                  the same principle....

                  and here the event:
                  Attached Files

                  Comment


                    #10
                    Super cool. Going to work on that this weekend!
                    Thanks!!

                    Comment


                      #11
                      SO - my value for
                      hs.DeviceValueByName(devw)
                      must be something other than 100 or 255.
                      It runs and changes my virtual device to off because the Motions_count always states 0 in the log regardless of the state of the motion sensor device being off or on.

                      OK - I see I'm missing something - in testing I was manually triggering the event.
                      This might be to advanced for me
                      Last edited by Monk; June 2, 2017, 03:55 PM.

                      Comment


                        #12
                        Originally posted by Uncle Michael View Post
                        This post describes the most efficient way I've seen so far to determine if all devices are in a given state using just events.
                        Uncle Michael,
                        The post shows:

                        First event:

                        If switch 1 had its value set to off
                        Or if switch 2 had its value set to off
                        Or if switch 3 had its value set to off
                        Then, if conditions are true, run second event

                        Second event:

                        If this event is manually run
                        And if switch 1 is off
                        And if switch 2 is off
                        And if switch 3 is off
                        Then set virtual device to off

                        Note the conditional THEN in the first event. It will only run the second event if all switches are off.

                        So I'm a little confused, why is he running the second event? Can't the virtual device simply be turned off after the first event? Probably I need to study a bit on the difference of something being "set" vs. otherwise.?

                        Comment


                          #13
                          Originally posted by Monk View Post
                          So I'm a little confused, why is he running the second event? Can't the virtual device simply be turned off after the first event? Probably I need to study a bit on the difference of something being "set" vs. otherwise.?
                          The reason for the second event is that you want ALL the switches to be off. If one switch is turned off, another one can still be on. So, the first event runs when any switch is turned off, but unless all the switches are off, the second event will not turn virtual device off.

                          On the other hand, to turn the virtual device on, only one switch needs to be on, so that requires just one event. If any switch is turned on, the virtual device will turn on.
                          Mike____________________________________________________________ __________________
                          HS3 Pro Edition 3.0.0.548, NUC i3

                          HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                          Comment


                            #14
                            Originally posted by Uncle Michael View Post
                            The reason for the second event is that you want ALL the switches to be off. If one switch is turned off, another one can still be on. So, the first event runs when any switch is turned off, but unless all the switches are off, the second event will not turn virtual device off.

                            On the other hand, to turn the virtual device on, only one switch needs to be on, so that requires just one event. If any switch is turned on, the virtual device will turn on.
                            Thanks. I see it now. Haven't had to do this for a while

                            Comment


                              #15
                              Monk,
                              I recommend using the script. It works well AND FAR more efficient, flexible and faster to create/change when adding devices, functionality, etc.

                              I've figured out that HS3's event engine is fine for basic things but tedious and inefficient for most things.

                              Comment

                              Working...
                              X