Toggle RGB lights on and off with virtual button


#1

1) Give a description of the problem
I’m trying to control 2 RGB zigbee bulbs with a virtual Smartthings button. The reason I’m using the virtual button is because I like controlling the bulbs with an existing Alexa (Echo) button and Alexa routines. Using those Alexa routines, I’m not able to toggle the lights on and off with a button press. I can either turn the lights on with a button press, or off with a button press, but not toggle an set the color temperature. So the workaround to get a toggle was to have the Echo button trigger a virtual Smartthings button which can then toggle the lights on and off (and set the color temperature correctly).

2) What is the expected behaviour?
I’d like to have my 2 bulbs turn on and set the color temperature when a virtual button is pushed (by pushing a real Echo button in Alexa routine). If the button is pushed again, I’d like the lights to turn off. Basically, I’d like the button to act as a on/off toggle switch for the lights (but also to set the color temperature).

3) What is happening/not happening?
When I push the button, the lights turn on and set color temperature (working). But it’s not always consistent. If I push the button again within a few seconds, the lights don’t turn off. After about a minute or so, if I push the button again then the lights toggle off like expected.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full
8/26/2019, 7:18:06 PM +11ms
+2ms ╔Received event [Alexa Bedroom Lamps Virtual Button].switch = off with a delay of 61ms
+10080ms ║RunTime Analysis CS > 19ms > PS > 10044ms > PE > 17ms > CE
+10081ms ║Piston waited at a semaphore for 10019ms
+10083ms ║Runtime (38995 bytes) successfully initialized in 10044ms (v0.3.10f.20190822) (10080ms)
+10084ms ║╔Execution stage started
+10095ms ║║Comparison (enum) on is (string) off = false (1ms)
+10097ms ║║Condition #17 evaluated false (9ms)
+10098ms ║║Condition group #1 evaluated false (state did not change) (10ms)
+10106ms ║║Comparison (enum) on is (string) on = true (1ms)
+10107ms ║║Condition #18 evaluated true (7ms)
+10110ms ║║Comparison (enum) off changes_to (string) on = false (0ms)
+10111ms ║║Condition #13 evaluated false (4ms)
+10112ms ║║Condition group #12 evaluated false (state did not change) (12ms)
+10114ms ║╚Execution stage complete. (30ms)
+10115ms ╚Event processed successfully (10115ms)
8/26/2019, 7:18:06 PM +5ms
+1ms ╔Received event [Alexa Bedroom Lamps Virtual Button].switch = on with a delay of 73ms
+64ms ║RunTime Analysis CS > 21ms > PS > 26ms > PE > 17ms > CE
+67ms ║Runtime (38913 bytes) successfully initialized in 26ms (v0.3.10f.20190822) (64ms)
+68ms ║╔Execution stage started
+79ms ║║Comparison (enum) on is (string) off = false (1ms)
+80ms ║║Cancelling condition #17’s schedules…
+81ms ║║Condition #17 evaluated false (10ms)
+82ms ║║Cancelling condition #1’s schedules…
+83ms ║║Condition group #1 evaluated false (state changed) (11ms)
+92ms ║║Comparison (enum) on is (string) on = true (2ms)
+93ms ║║Cancelling condition #18’s schedules…
+94ms ║║Condition #18 evaluated true (9ms)
+97ms ║║Comparison (enum) on changes_to (string) on = false (0ms)
+99ms ║║Condition #13 evaluated false (3ms)
+100ms ║║Condition group #12 evaluated false (state did not change) (14ms)
+102ms ║╚Execution stage complete. (34ms)
+103ms ╚Event processed successfully (103ms)
8/26/2019, 7:17:46 PM +977ms
+1ms ╔Received event [Alexa Bedroom Lamps Virtual Button].switch = off with a delay of 155ms
+75ms ║RunTime Analysis CS > 20ms > PS > 27ms > PE > 27ms > CE
+77ms ║Runtime (38918 bytes) successfully initialized in 27ms (v0.3.10f.20190822) (75ms)
+78ms ║╔Execution stage started
+93ms ║║Comparison (enum) off is (string) off = true (2ms)
+94ms ║║Condition #17 evaluated true (11ms)
+98ms ║║Comparison (enum) off changes_to (string) on = false (1ms)
+100ms ║║Condition #2 evaluated false (4ms)
+101ms ║║Condition group #1 evaluated false (state did not change) (17ms)
+113ms ║║Comparison (enum) off is (string) on = false (1ms)
+115ms ║║Condition #18 evaluated false (10ms)
+116ms ║║Condition group #12 evaluated false (state did not change) (11ms)
+118ms ║╚Execution stage complete. (39ms)
+119ms ╚Event processed successfully (119ms)

Thank you so much in advance for the help! I know this is probably something fairly straightforward, but this is my first time using webcore with my first piston and I’d appreciate all the help and expertise! Thanks!


#2

Change line 34 to
when switch changes to off
and see if that does what you are looking for.


#3

Hi,
I assume the switch is a momentary action and changes back to off.

I’d code it something like this

If switch changes to on
then
If lights off
then
turn lights on
else
turn lights off
end if
end if


#4

Yeah I forgot to mention that the virtual button is a momentary switch, so I’m not sure if that would work, since the switch would go back to “off” after a few seconds every time. And thus pushing the button again, and turning the switch to on, would not trigger it. Right? Or am I thinking about this the wrong way?


#5

Hmm, why didn’t I think of that! I’ll try it and see if that makes it easier and more consistent/responsive. Thanks!


#6

Having subscribed to the switch, the whole piston will run top to bottom every time the switch is activated, either on or off.

I’m not sure what type of switch you’re using, I’ve used a fibaro relay which has an option to switch off again several seconds after turning on. That works fine through ST & webcore as both see it turning off after a few seconds, & recognise it being turned on again when its next turned on


#7

So it’s a virtual momentary button/switch. I’ll need to see if I can tweak it some more. Still doesn’t seem to turn on or off consistently when pushing the virtual button/switch.


#8

Currently, you have no trigger. Notice the lack of the lightning bolt. The lightning bolt indicates a trigger.

image
“Something is Something” is not a trigger.

“Something become Something” is a trigger.

Switch your two IFs around.

IF
-Switch changes to ON
-and
-RGB Bulb is OFF

The switch changing to ON is a trigger.

Also, I don’t know if a momentary switch is best for this. You could simply have a virtual switch set so that when the switch turns on, the lights turn on, and when the switch turns off, the lights turn off.

IF
-Switch 1 changes to ON
THEN
-WITH
–RGB Bulb 1, RGB Bulb 2
-Set level to 100%
-End WITH
End IF

IF
-Switch 1 changes to OFF
THEN
-WITH
–RGB Bulb 1, RGB Bulb 2
-Turn OFF
-End With
End IF

(see above example with the lightning bolt circled)