Virtual switch set to off instead of "changes to off"?


#1

I’d like to make it so my piston executes an action whenever an off command is sent to my virtual switch. In other words, this should trigger whether or not the switch was already on or off before the “off” was set on the switch. With some of my physical smart switches, this is easy because I can set the trigger to be whenever the “off” button is pressed. But with the virtual switch, my only trigger seems to be “changes to off”.

When the off button is pressed, even if the virtual switch was already off, I see in my logs that the piston runs (good), but then it reaches the evaluation of “changes to” and does not execute because it did not “change to” off since it was already off. Any suggestions?


#2

Triggers happen when there is action. Unfortunately, if the device is already in that state, there is no action taking place.

Depending on your current piston, you have a few options:

(1) Use a “Momentary Button Tile” instead. It’s also virtual, but acts like a traditional button, meaning right after you press it on, it turns itself off. If you go this route, just change your logic to IF MomentaryButtonTile changes to on (instead of off)

(2) Alternatively, you can program webCoRE to turn on the Simulated Switch prior to sending the the turn off command

For pistons that need multiple triggers back to back with no changes taking place, what I often do is use a “Momentary Button Tile” to trigger the action. Depending on the complexity, I may also have that piston call another piston for even more flexibility.

temp


This also works:

IF Momentary Button Tile changes to on   <-- Trigger
Then
    IF Simulated switch is off           <-- Condition
    Then Do stuff
    END IF
END IF

#3

But the event itself does fire, I just can’t figure out how to take advantage of it. This shows in the piston’s log when I turn from “off” to “off”:

|+1ms|╔Received event [Virtual DownOff].switch = off with a delay of 328ms|
|---|---|
|+138ms|║RunTime Analysis CS > 27ms > PS > 59ms > PE > 52ms > CE|
|+140ms|║Runtime (45466 bytes) successfully initialized in 59ms (v0.3.108.20180906) (138ms)|
|+141ms|║╔Execution stage started|
|+157ms|║║Condition #4 evaluated false (9ms)|
|+158ms|║║Condition group #3 evaluated false (state did not change) (11ms)|
|+170ms|║║Condition #9 evaluated false (8ms)|
|+171ms|║║Condition group #8 evaluated false (state did not change) (10ms)|
|+179ms|║║Comparison (enum) off changes_to (string) off = false (1ms)|
|+181ms|║║Condition #16 evaluated false (6ms)|
|+182ms|║║Condition group #15 evaluated false (state did not change) (8ms)|
|+193ms|║║Condition #23 evaluated false (6ms)|
|+194ms|║║Condition group #22 evaluated false (state did not change) (9ms)|
|+201ms|║╚Execution stage complete. (59ms)|

As you seen an event does fire but then it compares “off changes_to off” = false, so it doesn’t execute. If I had an “set_to off” as an option it would work.

I actually currently had it where “if turned off” -> Do things, wait 5 seconds, turn on. But sometimes there’s weird states where the virtual switch was already off. Therefore my actions would not fire because I’d be changing off to off. I just tried disabling TCP and will see if maybe that solves my issue with sometimes already being off.


#4

Untested, but you can try this:

IF Switch changes     <-- Trigger
Then
    IF Switch is off  <-- Conditions
    Then
    Do Stuff
    END IF
END IF

Personally, I usually use one of the 3 previous mentioned methods.