Link two types of devices in a list


#1

Is there a way to loop a list of devices? E.g.

for switch, sensor in list_of_devices:
if sensor is active:
switch.off()

Sorry for the non-CoRE psuedo code.

-M


#2

Simple

Define the variable:

Device mydevices = switch, sensor, light

For each $device in mydevices
Do whatever
End for

Unless they all have the same attributes, however, hard to do th3 same th8ng to each device in the list. This is normally for a list of sensors or lights but not a mix.

What exactly are you trying to do?


#3

That’s not quite what I’m looking for… I want to check a sensor and turn off a light in the loop. For example. Check the motion in the bathroom and if so turn off the light for that bathroom. But I want to do it for all the bathrooms.

I can make a statement for each bathroom, but Im trying to see if there is a way to pair a light and a bathroom.

-M


#4

Ok, now I understand. Unfortunately, it doesn’t look like you can use an index on a device list variable. I was wanting to do that myself for another purpose and could not find a way to do it. Perhaps @WCmore or @ipaterson could confirm. Might be a good feature suggestion.


#5

Untested here.


#6

OK Thanks folks- a few if statements it is I guess.