Piston triggered by virtual switch sometimes works and sometimes it doesn't


#1

I have another confusing issue.
I say goodnight to Alexa, which opens a virtual switch. That switch should then initiate a piston that turns off some stuff and then turns off the virtual switch.
Should be straight forward. Still, sometimes it works and sometimes it doesn’t. See the logs for the last 2 days. The situation should be exactly the same - yet yesterday it ran and today it didn’t.
What gives?

1/8/2022, 11:06:01 PM +672ms
+2ms ╔Received event [Routine_Night].switch = on with a delay of 85ms
+73ms ║RunTime Analysis CS > 22ms > PS > 10ms > PE > 40ms > CE
+75ms ║Runtime (40383 bytes) successfully initialized in 10ms (v0.3.113.20210203) (73ms)
+76ms ║╔Execution stage started
+84ms ║║Comparison (enum) on changes_to (string) on = false (1ms)
+86ms ║║Cancelling condition #2’s schedules…
+87ms ║║Condition #2 evaluated false (5ms)
+88ms ║║Cancelling condition #1’s schedules…
+89ms ║║Condition group #1 evaluated false (state changed) (8ms)
+90ms ║╚Execution stage complete. (14ms)
+92ms ╚Event processed successfully (91ms)

1/7/2022, 10:46:57 PM +686ms
+1ms ╔Received event [Routine_Night].switch = off with a delay of 162ms
+77ms ║RunTime Analysis CS > 20ms > PS > 10ms > PE > 47ms > CE
+80ms ║Runtime (40385 bytes) successfully initialized in 10ms (v0.3.113.20210203) (77ms)
+81ms ║╔Execution stage started
+88ms ║║Comparison (enum) off changes_to (string) on = false (1ms)
+90ms ║║Condition #2 evaluated false (5ms)
+91ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+93ms ║╚Execution stage complete. (13ms)
+94ms ╚Event processed successfully (94ms)


#2

On the 7th, the switch turned off
On the 8th, the switch turned on

Does any other programming touch Switch 4?


#3

You’re right, i didnt even pay attention to that.
No, this piston is the only function of the virtual switch. Alexa turns it on, the piston turns it back off. That’s it.

In the Alexa routine I have a turn off, then a turn on, exactly for these situations where the routine doesnt run and the switch remains on


#4

I have a very similar set up. I have a separate event that runs as dusk to change the virtual switch “night”. off again.

On occasion I have found that the alexa routine has not turned the switch on, not sure why, I just say “goodnight” again


#5

Additionally, on the 7th the changes to on evaluated to false which would be expected as it was an off event. However there is a ‘state did not change’ which implies that the condition was already false. If the virtual switch is stateless that could be suggestive of the piston having turned the switch off, and this instance being the Alexa routine turning it off again, if not then I am puzzled.

On the 8th changes to on still evaluated to false in receipt of an on event, suggesting that the switch was already on. However this time the ‘state changed’ for the condition suggesting it had been true last time around.

Odd.


#6

I will sometimes throw in two “turn off switch” commands. Occasionally, the first command doesn’t go through for some reason.


#7

Me too… With a 1 sec WAIT in between.
(typically needed for periods of major activity)


#8

The only thing i can think of is related to the location state. (I still have to test this theory).
I have another morning piston that changes the state from Night to Home.
In the morning of the 7th i ran this piston; so the “set to Night” in the piston referenced above made a change (set it from Home to Night).
If i remember correctly, on the 8th maybe I didn’t run this piston so the state might have been in Night mode all day.

Could this cause it to not work correctly?
Since then i wrote another piston that automatically changes to Home at 9am if i am present.
Also moved the location state to the bottom of the piston.

So hopefully the points of failure have been eliminated, but could this cause the piston to stop executing?


#9

Seems strange that that would be all the logs you get. When you turn on the virtual switch, this piston should run and then it should run again when it turns the virtual switch off (i.e., the piston should run on any change of your switch, 1 on=true and 1 on=false). You should see both logs you show on both days. Very strange.


#10

THIS piston turns the switch off. Or you mean from Alexa?
So the Alexa routine was

  1. Turn switch off
  2. wait 5 seconds
  3. turn switch on
  4. say goodnight.
    She always says goodnight. But the lights sometimes turn off and sometimes not.

#11

Actually, it doesn’t matter. Anything that changes the switch will cause the piston to run top to bottom. So if Alexa changes the switch (on or off), the piston will run AND if the piston changes the switch (on or off) the piston will run. So, if Alexa turns the switch off, the piston will run. Then, when Alexa turns the switch on, the piston will run again. Finally, when the piston turns off the switch, it would run a third time. The only thing uncertain is if the switch is already off when Alexa first attempts to turn it off, it may do nothing. Not sure about Alexa command optimization.

So, whether works or not may be dependent on Alexa sending two commands successfully 5 seconds apart. Most of the time that should work but sometimes I see a significant delay from an Alexa command to something happening which could cause an issue.


#12

Could be an Alexa issue. I initially didn’t have the Off and wait in the routine; The reason I added it was because even then, sometimes the piston didn’t run, and thus the switch stayed on. So then I could not call Alexa again, i had to open the app and turn the virtual switch off. Not something I was happy with.

Any way to make this coding better? either on the Alexa or Webcore side?


#13

I have had similar problems even when the piston seems to run, somehow the virtual switch is left on and then it won’t work. Really need a momentary virtual Alexa switch so it would turn off automatically. Sorry, don’t have any suggestions atm.


#14

I have noticed that Alexa Routines do not like conflicting commands…

I have seen many errors when attempting:

  • Turn on DeviceA
  • Wait a few seconds
  • Turn off DeviceA

Instead, what I try to do is keep the Routine only one direction, and let webCoRE do the WAIT and Turn off afterwards. (instead of Alexa cleaning up)


Alternatively, sometimes I use a “Momentary Button Tile” instead of a virtual switch. 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 webCoRE logic to:

IF MomentaryButtonTile changes to on


#15

Side note:

  • Normally, a switch is either on or off…
  • a contact sensor is either open or close

Somehow, your piston shows a Contact Sensor going on/off (like a switch)?!?
(I would change it to one of the above, or use a MomentaryButtonTile)


#16

I haven’t heard of the Momentary Button Tile - i will look into that.

What i am using is a Simulated Alexa Switch. It acts as both a switch and a sensor, so that both ST and Alexa can recognize and activate it.


#17

Try one of these modifications:

  • IF Switch is on…
  • IF Contact Sensor is open