Count Devices On
Posted: Sun Sep 03, 2017 7:23 am
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.
Software Support and Home Automation Forum
https://forums.indigodomo.com/
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))