Switch statements in rules

Rather than wrapping lots of if-else statements it would sometimes be a whole lot easier with switch statements.

For example if triggers are if any lamp is switched on, then execute an activity depending on the lamp being switched on. Then each of the lamps that are also triggers could be a case in a switch statements, rather than having to wrap a lot of if-then-else.

I’m not sure this is what you mean, but you can do it with variables.

Add all the lights you want as triggers, in the flow add an If condition.
Select variable, context variable, event, location/device, device name.

Now you can select from all the triggering devices and set the rest of your If argument, for every seperate light.

Context variables are cool. But I will still need to do an If statement for each device that may have triggered the rule? That will still be a lot of wrapping if-then-else for each device.

If I could select the triggering device via the context variable and perform the action only on that device, then it would have been more like switch-case in a shorter version and I wouldn’t need any if-then-else and only one action that will be performed on whatever device that triggered the rule.

That is, I only want to apply color temperature on devices that are already on, or else they will be switched on (which I don’t want).

My main use case is to run the action on devices that are on, but not on the ones that are off.


Oh, I see, nope, can’t think of something for that :rofl:

Rephrasing my original question, there is currently no way to use one rule to execute actions on all lights that are currently on? I’d like to slowly dim all lights down to 0 during 30 minutes when it’s late at night. But do I really need to create one rule per light for that?

Best thing I can come up with is to make a lighting group in the Smartthings app and set a virtual switch to those. But that would only make thel turn on or off. I’m not sure how it would work with a virtual dimmer switch maybe. You’d still have to link them somehow the first time I guess.

I don’t own any dimmable lights, so not too sure.