So I’m very new to this, but I’ve played with code a bit before. What I’m trying to accomplish seems simple, but I’m stuck.
I have a virtual switch triggering an Alexa Routine. For example, to turn all my lights on. The problem is, I can’t get the button to recognize whether the device is already in a state. ie: An All Lights On switch that gets left “on” after using it, so I have to effectively turn it off (which does nothing) and then turn it back on for it to work.
I want the button to reset without triggering another function, or to turn on automatically if the lights are turned on through a voice command instead.
Even if I had 4 different “scene” switches, and when I clicked another one, the first turns off and the scene changes.
You can make a virtual momentary switch if I understand correctly. Or add in a rule that switches your virtual switch off after 2 seconds after it turns on.
As I understand it, every time you run the routine, the lights go on and then off, so above should work for that.
If you want the status for the lights, I used to do this by make any of all the lights a trigger, let it wait 2 seconds and if after the 2 seconds all the lights are ON, it would change a variable I could use to show all the lights being on.
Adding that variable tile to a dashboard and making the tap action a rule that triggers the virtual switch, you have a tile that shows the status and operates the scene.
You can also use that variable to check and use in a rule to turn it off when you change scene.
Rules and variables are a bit of a rabbit hole. I’ve been replacing rules still after a few months, just because I came up with a more logical or easier way to make them.
Example, used to have the rule I mentioned above, now I made a group of lights in Smartthings and a virtual switch that controls the group. This switch also controls a variable to check if all the lights are on or off.
For my evening lights which turn on daily, I used to have 2 rules for them, now I just use an if condition to check on the time, so if it’s morning they turn off and evening on, eliminating a rule.
Hi my friend, I am not sure if I am getting your goal, but I will try to share what I did for something like you are looking for.
Virtual Device: Garage Light Switch
Automation 1: IF: Garage Light Switch ON, THEN: Hue 1 ON, Hue 2 ON
Automation 2: IF: Garage Light Switch OFF, THEN: Hue 1 OFF, Hue 2 OFF
Automation 3: IF Hue 1 OFF and Hue 2 OFF, THEN: Garage Light Switch OFF
Automation 4: IF Hue 1 ON and Hue 2 ON, THEN: Garage Light Switch ON