Page 1 of 1

Count Devices On

PostPosted: Sun Sep 03, 2017 7:23 am
by Sharek326
Does anyone know if there is a way to count how many devices are in an on state to be displayed on a control page.

Re: Count Devices On

PostPosted: Sun Sep 03, 2017 9:38 am
by jay (support)
There isn't a built-in way. You'd need to write a script that periodically cycles through all devices that support on/off and count the number that are on then stick that into a variable. Alternately you could write a plugin that subscribes to device events and keeps a running total of devices that are on.

Count Devices On

PostPosted: Sun Sep 03, 2017 9:43 am
by kw123
This one should do write to log file and create 2 variables .
you need to define what "UP" is: which state and what the up value should be.

Code: Select all
statesToCheck = ["onOffState","status","up"]

valuesForUp = ["up","on","true","100"]


countUp = 0
countTotal = 0
for dev in indigo.devices:
   countTotal +=1
   for ss in statesToCheck:
      if ss in dev.states:
         indigo.server.log(dev.name.ljust(30)+"  "+ss.ljust(20)+"  "+unicode(dev.states[ss]))
         if unicode(dev.states[ss]).lower() in  valuesForUp:
            countUp+=1
            break
indigo.server.log("devices total= "+str(countTotal) )
indigo.server.log("        up=    "+str(countUp) )

try:
   var = indigo.variables["numberOfUpDevices"]
except:
   indigo.variable.create("numberOfUpDevices")
try:
   var = indigo.variables["numberOfDevices"]
except:
   indigo.variable.create("numberOfDevices")

indigo.variable.updateValue("numberOfUpDevices", str(countUp))
indigo.variable.updateValue("numberOfDevices", str(countTotal))


Put it into an action/server/script of a schedule to execute on a regular basis.

Karl

updated the code

Re: Count Devices On

PostPosted: Sun Sep 03, 2017 12:59 pm
by Sharek326
Thanks Karl ...I'll give that a shot

Re: Count Devices On

PostPosted: Mon Sep 04, 2017 10:40 am
by kw123
updated the code to include "onOffState"
and added a line that print every device to log file while it goes through.. good for testing, should be removed if you use it regularly

Karl