Virtual Switch on/off flow setting?

I have a virtual switch called TV Lights. Am I able to create one rule that will set lighting for watching TV when I turn it on and then return the lighting to certain settings when I turn it off. I believe I could do this with two rules, just curious if it’s possible with one. Thanks!

You can probably do it with one rule, but whether or not it’s more simple is a separate question.

For the trigger, you’ll need to have your virtual switch added twice, once for on and once for off. Since triggers are ANY, then the rule will fire when it’s turned on and when it’s turned off.

For the Flow, you’ll need an if statement that evaluates the present lighting and acts accordingly. For example, let’s say you have a bulb that you want to dim when you turn the virtual on and then get brighter when you turn the virtual off. Your Flow statement would be IF the bulb is bright, dim it ELSE set it to bright.

Evaluating the IF conditions will be the most difficult, as that statement needs to assess the current state of the bulb (in this example) in order to know how to proceed, which can get awkward. In this scenario, you are using the IF to determine which virtual switch was flipped. For that reason, it might be cleaner to use two rules, as that will get you around using an IF to evaluate the current configuration of what you are about to act upon.

As an alternative, you can evaluate the virtual switch itself via the IF to see if it’s off on on and the proceed accordingly. But this may be more verbose than just using two rules.

1 Like

How about something like this as Bry mentioned.

TRIGGER:

TV Lights CHANGES TO ON

TV Lights CHANGES TO OFF

FLOW:

IF TV Lights

SWITCH

IS ON

THEN

SET LIGHTS TO WHATEVER

SELECT DEVICE

SELECT COMMAND (EX. SET LEVEL)

INPUT ARGUMENT #1 (EX. 25)

ELSE

SET LIGHTS TO SOMETHING ELSE

SELECT DEVICE

SELECT COMMAND (EX. SET LEVEL)

INPUT ARGUMENT #1 (EX. 100)

1 Like

Thanks for the replies, I need to dig into these techniques just so I can continue to learn. My two rule solution is working for now. Really appreciate it!

In the above example, you can use context variables.

Instead of IF TV Lights, you can select If “variable”, “context variable”.
You can select the device there and the state (you need to enter the state manually, on or off, no capitals).

This will execute faster.

3 Likes