Announcement

Collapse
No announcement yet.

number of devices on

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

    number of devices on

    Is there a native variable in HS3 which can display the total number of lights that are on (and/or off) in real time? So far my research has yielded this post: https://forums.homeseer.com/showthread.php?t=175003
    however it requires me to run a script manually (ie, not real time / automatic).

    Thanks,
    CJ

    #2
    Originally posted by cjr18 View Post
    Is there a native variable in HS3 which can display the total number of lights that are on (and/or off) in real time? So far my research has yielded this post: https://forums.homeseer.com/showthread.php?t=175003

    however it requires me to run a script manually (ie, not real time / automatic).



    Thanks,

    CJ


    If you have instant status switches, you could use the change of state of any of them to trigger the script. It's particularly easy with Spud's Easy Trigger plugin:

    IF any device whose type is [say] "Z-wave Binary Switch" has its value changed

    THEN Run the script.
    cheeryfool

    Comment


      #3
      Originally posted by cjr18 View Post
      Is there a native variable in HS3 which can display the total number of lights that are on (and/or off) in real time?
      AFAIK there is no built-in way to do this. As your reference notes, you could use a counter, but it will require some work, mostly because there is no universal way to distinguish a light switch from other loads. Since you know which switches you want to include, you could add a couple of events for each switch (or add actions to existing events, in some cases). If the switch changes and becomes on, increment the counter. If the switch changes and becomes off, decrement the counter. You'll probably want to reset the counter to a known, accurate value periodically, like once a day, just to avoid having it drift over time from missed switch changes.
      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


        #4
        I wrote a script to count my lights and ceiling fans then update a virtual device with the number.

        At some point in the future I'll also have it make a list of the devices that are on; or perhaps just the rooms....

        Code:
            Public Sub Main(ByVal Parms As Object)
                ''This will count the number of lights and celing fans which are on and update the appropriate virtual device with the number
                ''This script assumes all ceiling fans have "ceiling fan" in the name and all lights have "light" in the name
                ''The exception is the "north pendent light" which is listed as "north pendent"
        
                ''in the future I may elect to expand this to act on the specified floor; It might be useful to separate outside from inside devices
                ''In my device setup 'first' floor = inside, 'outside' floor is outside
                ''dv.location2 = floor
        
                ''if we are going to specify the floor/location; pass it as a parm and uncomment the next line
                ''Dim FloorName As String = CType(Parms, String)
        
                ''Active_number_lights and Active_number_fan will act as our counters
                Dim Active_number_lights As Integer = 0
                Dim Active_number_fans As Integer = 0
        
        
                ''light and fan virtual device ref numbers
                Dim Global_fan_device_ref As Integer = 150
                Dim Global_light_device_ref As Integer = 149
        
                ''get a list of devices
                Try
                    Dim dv As Scheduler.Classes.DeviceClass
                    Dim EN As Scheduler.Classes.clsDeviceEnumeration
                    EN = hs.GetDeviceEnumerator
                    If EN Is Nothing Then
                        hs.WriteLog("count_active_devices", "Error getting Enumerator")
                        Exit Sub
                    End If
        
                    ''Loop through each device and see if it's a ceiling fan or a light
                    Do
                        dv = EN.GetNext
                        If dv Is Nothing Then Continue Do
        
                        ''If we decide To specify the floor Then add In "And dv.Location2(Nothing).Contains(FloorName)" for the main if/then statement
                        ''Scan for devices which are on, and are either zwave multilevel (fans and dimmers) or binary switches (non dimming switches).  Then decide if it's a fan or a light and update the appropriate counter
                        If hs.IsON(dv.Ref(Nothing)) AndAlso (dv.Device_Type_String(Nothing) = "Z-Wave Switch Multilevel" Or dv.Device_Type_String(Nothing) = "Z-Wave Switch Binary") Then
        
                            ''check to see if it's a light or if it's a fan and increment as needed
                            ''check for the north pendant light, and exclude bidet fan and exhaust fan
                            If (dv.Name(Nothing).ToLower.Contains("light") Or dv.Name(Nothing) = "North Pendant") AndAlso Not dv.Name(Nothing).ToLower.Contains("fan") Then
                                Active_number_lights = Active_number_lights + 1
                            ElseIf dv.Name(Nothing).ToLower.Contains("ceiling fan") AndAlso Not dv.Name(Nothing).ToLower.Contains("light") Then
                                Active_number_fans = Active_number_fans + 1
                            End If
                            End If
        
                    Loop Until EN.Finished
        
                    ''Update the virtual devices, 0 = off and we need to set the device to 'off' not just 0
                    ''set lights
                    If Active_number_lights = 0 Then
                        hs.CAPIControlHandler(hs.CAPIGetSingleControl(Global_light_device_ref, True, "Off", False, False))
                    Else
                        Dim cc As HomeSeerAPI.CAPIControl = hs.CAPIGetSingleControl(Global_light_device_ref, True, "Number: (value)", False, False)
                        cc.ControlValue = Active_number_lights
                        Dim cr As HomeSeerAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                    End If
        
                    ''set ceiling fans
                    If Active_number_fans = 0 Then
                        hs.CAPIControlHandler(hs.CAPIGetSingleControl(Global_fan_device_ref, True, "Off", False, False))
                    Else
                        Dim cc = hs.CAPIGetSingleControl(Global_fan_device_ref, True, "Number: (value)", False, False)
                        cc.ControlValue = Active_number_fans
                        Dim cr = hs.CAPIControlHandler(cc)
                    End If
        
                Catch ex As Exception
                    hs.WriteLog("Error", "Exception in script Count Active Devices:  " & ex.Message)
                End Try
        
                hs.SaveEventsDevices()
            End Sub
        HS4 Pro on Shuttle NC10U, Win10; Z-NET
        Number of Devices: 1005
        Number of Events: 293

        Plug-Ins: BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, Marquis monoprice Amp, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, rnbWeather, Worx Landroid, Z-Wave

        External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

        Comment


          #5
          Thank you for your responses. I was able to get this to work by utilizing Spud's Easy Trigger plugin to run the following script whenever a device in a predefined group (I made a group of light devices) has a status change. Thank you cheeryfool for that suggestion. Of note, I do have instant status switches.

          Code:
          Dim DeviceList() As Integer = {197, 101, 87}
          Dim CurrentStatus As CAPIStatus
          Dim NumberOfOnDevices As Integer = 0
          
          Sub Main(Parm As Object)
              
              For Each DevRef As Integer In DeviceList
                  CurrentStatus = hs.CAPIGetStatus(DevRef)
                  If CurrentStatus.Status.ToLower <> "off" Then NumberOfOnDevices += 1
              Next
          
              hs.SetDeviceValueByRef(123, NumberOfOnDevices, True)
              NumberOfOnDevices = 0
          End Sub
          Ref ID "123" is the ID of a counter.

          Comment


            #6
            Thank you for your responses. I was able to get this to work by utilizing Spud's Easy Trigger plugin to run the following script whenever a device in a predefined group (I made a group of light devices) has a status change. Thank you cheeryfool for that suggestion. Of note, I do have instant status switches.
            I'm using this script to count the number of lights turned on, triggered by EasyTrigger to run each time a device in my group has changed.

            I've got some Zigbee lights through JowiHue where 0=off, 1-99=dim and 255=on. It won't count those lights. Any way to include them?

            Comment

            Working...
            X