Multiple objects: To loop or not to loop

I want to set multiple thermostats fanmode to on.

Should this code work?


Where thermostats is a multiple preference item.

In the big switch, they do switches.On() (which is why I think it should work).

That should work. … …

I thought it had to be


I know that thermostats?.fanOn() avoids a null condition, but I’m not familiar with the asterisk, checking groovy resources now.

I think @obycode could be right, but then how does the big switch work?

Spread Operator

I’ve used it without the asterisk in pretty much all of my apps, except for the possible null case with ?. Things like this work:

("on" in switches.currentSwitch)


Then does this work?

subscribe(thermostats*, “thermostatFanMode.fanOn”, thermostatOnHandler)

Apologize for what may be basic questions. I’m a hack.

I don’t think so. I would use collect for that:

thermostats.collect {
  subscribe(it, "thermostatFanMode.fanOn", thermostatOnHandler)


I’ve used successfully,

subscribe(motions, "", motionActiveHandler)

Try these variations. Then use the IDE to look at the app subscriptions. You will see separate subscriptions.

Oh yeah, you’re right. I’ve used that before too.

That’s the key, I always forget to look deeper in the IDE, I’ll have a look.

I think it depends. The Big Switch uses switches.On() because it has assigned the variable switches via the preferences section. It is not calling all switches a user has. Only those selected by the user during SmartApp installation.

section("Turn on or off all of these switches as well") {
		input "switches", "capability.switch", multiple: true, required: false

Well yea, but you can only get devices from preferences. In the case of multiple:true, you get a [list of devices]. Those can be handled this way when it makes sense. That is, do something to all of them.

I can confirm that:

subscribe(thermostats, "thermostatFanMode.fanOn", thermostatOnHandler)

works on multiple stats, and that I am getting them from preferences. Something else is going on in my code.

thanks all!