Iterating through all lights

Posted on
Thu Nov 16, 2017 3:33 pm
Turribeach offline
Posts: 429
Joined: Feb 06, 2015
Location: London, UK

Iterating through all lights

I have a script that I want to run every time a light device changes state to restart an All Lights timer and keep it active. I manage to code it (see below) and do what I wanted but I got some follow up questions:

1) I couldn't compare the device class using device.__class__ = "<class 'indigo.DimmerDevice'>". I managed to work around this by using the .iter filter but is there a way to compare the device class directly?
2) Among the list of devices that this script finds are some virtual devices which also have the indigo.relay class. How can I exclude them? Do virtual devices have anything in particular I can use to exclude them?
3) How can I get the device's folder? (i.e. in which folder my device is located)

Thanks!

Code: Select all
## Convenience log function
def log(msg):
indigo.server.log(msg, type="Reset All Lights Timer Script")

## Loop through devices looking for light devices
for device in indigo.devices.iter("indigo.relay, indigo.dimmer"):
    if device.enabled and "Lights " in device.name and hasattr(device, 'onState'):
        if device.onState:
            tId = "com.perceptiveautomation.indigoplugin.timersandpesters"
            timerPlugin = indigo.server.getPlugin(tId)
            if timerPlugin.isEnabled():
                timerPlugin.executeAction("restartTimer", deviceId=1657820952) # "Timer All Lights"
                log("Restarted Timer All Lights")
                break

Posted on
Thu Nov 16, 2017 6:45 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Iterating through all lights

Turribeach wrote:
1) I couldn't compare the device class using device.__class__ = "<class 'indigo.DimmerDevice'>". I managed to work around this by using the .iter filter but is there a way to compare the device class directly?


Code: Select all
isinstance(device, indigo.DimmerDevice)


Turribeach wrote:
2) Among the list of devices that this script finds are some virtual devices which also have the indigo.relay class. How can I exclude them? Do virtual devices have anything in particular I can use to exclude them?


Code: Select all
if device.pluginId != u"com.perceptiveautomation.indigoplugin.devicecollection"


Turribeach wrote:
3) How can I get the device's folder? (i.e. in which folder my device is located)


Code: Select all
device.folderId

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Nov 18, 2017 1:58 am
Turribeach offline
Posts: 429
Joined: Feb 06, 2015
Location: London, UK

Re: Iterating through all lights

Thanks Jay!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest