Switch off all devices beginning with text - if switched on

Posted on
Sun Dec 25, 2016 10:45 am
davinci offline

Switch off all devices beginning with text - if switched on

I want to switch off all devices starting with text light, only if they are on.

What would be the easiest way to do this?

Posted on
Sun Dec 25, 2016 10:53 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Switch off all devices beginning with text - if switched

What do you mean "starting with text light"?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 25, 2016 11:09 am
davinci offline

Re: Switch off all devices beginning with text - if switched

The device is called like this:

Light kitchen
or
Light bedroom
...

Posted on
Sun Dec 25, 2016 11:26 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Switch off all devices beginning with text - if switched

Something like this:

Code: Select all
for dev in indigo.devices.iter():
    if dev.name.startswith("Light"):
        indigo.device.turnOff(dev)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 25, 2016 12:43 pm
davinci offline

Re: Switch off all devices beginning with text - if switched

Thanks a lot for the quick reply. It helps a lot.

Here is my full script in case someone wants to use this as well.

The goal was to switch off all lights in an efficient way.
- only switch off if really on
- turn off all lights except one (Light Exception)
- wait 1 second between every light to avoid network overload - but only wait if one light has been switched off



Code: Select all
import time

for dev in indigo.devices.iter():
    if dev.name.startswith("Light") and indigo.devices[dev].onState and dev.name != "Light Exception":
        indigo.device.turnOff(dev)
        time.sleep(1)

Posted on
Sun Dec 25, 2016 1:58 pm
jay (support) offline
Site Admin
User avatar
Posts: 18216
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Switch off all devices beginning with text - if switched

This version is more efficient since it doesn't get the device from the server twice:

Code: Select all
import time

for dev in indigo.devices.iter():
    if dev.name.startswith("Light") and dev.onState and dev.name != "Light Exception":
        indigo.device.turnOff(dev)
        time.sleep(1)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Dec 25, 2016 3:47 pm
davinci offline

Re: Switch off all devices beginning with text - if switched

Thanks jay, for pointing that out.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests