I am new here. So not sure that I am helping or hindering. I would think that if you have a user selecting multiple items that the code would process each selection individually/ Wouldn’t it just cache the following selected commands until all items in the cache are satisfied?.
Inside the loop, “switch” is an individual switch in the collection. You can examine its label if you wanna know which one it is and decide what to do with it. But you can probably do easier or more efficient whatever you’re trying to do. So, what exactly are you trying to do?
You will need a for loop since you don’t know which switches were chosen. In that for loop you can have If statements to determine the switch and decide what to do. Here is an example:
for (a in switch1) {
//log.debug "switch: $a.label"
if (a.label == "Kitchen Switch") {
a.on()
}
if (a.label == "Living Room Switch") {
a.off()
}
}
I’m going to throw this example code here just to attach it to this thread. It really has nothing to do with what you’re doing @scottinpollock other than it’s a demonstration of another way to interact with multiple devices attached to one variable. I figure is someones searching the forums for help they’ll find your thread and the more examples the easier it will be for them to get the help they need.
1. cycles through all contact sensor devices selected
2. if the current selected device is open, then:
3. echo to the simulator the device's name
4. make variable 'toReplace' = the devices name.
5. make variable 'replaced' = 'toReplace' with all the spaces changed to %20
6. echo to the simulator the new name.
7.
8. Remove any previously added "ands" to make it sound natural.
9.
10. If Phrase is empty (ie, this is the first name to be added)...
11. ...then add "The%20" plus the device name.
12. If Phrase isn't empty...
13. ...then add ",%20And%20The%20".
14. Closes the IF statement.
15. Closes the doors.each cycle