Whenever I push the button the lights come on. On the second press lights start to turn off and then immediately turn back on. If I turn off the virtual switch Lights turn off. I cant see what is wrong.
The button press with the lights on executes the ELSE-IF block. In that block, it turns the virtual switch to off. Turning the virtual switch to off triggers the rule a second time. Since State got changed on the first execution, the ELSE block gets executed on the second execution.
My suggestion to get the behavior you want:
- one rule toggles the virtual switch when the button is pushed
- a second rule turns the lights on when the virtual switch is turned on
- a third rule turns the lights off when the virtual switch is turned off
Thank you!! That makes sense I see the problem. It is weird that turning off the virtual switch worked with that rule.
The statement within the rule that turns off the virtual switch doesn't have any effect if the switch is already off.
I see. Thank you.
Good job. Separate rules for on and off and a single rule with an if condition both work. It is mostly a matter of which seems more logical to you.