Can't reliably reset device state after piston runs


#1

1) Give a description of the problem
Piston is not reliably setting devices back to initial state

2) What is the expected behavior?
See above

3) What is happening/not happening?
Sometimes lights are returned to previous state, many times they are not

4) Post a Green Snapshot of the pistonimage

So I understand that the toggle doesn’t always turn things on and off reliably. So I’m grabbing the state before the piston runs and then setting it back afterwards. Only sometimes, if the device was off, it leaves it on. Any ideas what I’m missing?


#2

It’s possibly going too fast, add a second or two wait after the capture then proceed with your tasks.


#3

I’m no expert but if the motion sensor’s condition changes not active while in the middle of executing all your actions inside the “then” statement, it aborts where ever it happens to be at that moment. Perhaps changing the if statement’s “Task cancellation policy” to never cancel tasks may correct the problem.


#4

I tried 1, and then 2, seconds. Neither made it any more reliable.


#5

I’m using ‘changes to’ not ‘is’ so I don’t think that matters.


#6

you still need to set execution policy to never cancel on the first if statement. if the motion changes to inactive, it will stop the piston where ever it currently is in the execution, which is probably in one of the wait segments.

i havnt used the capture/restore attributes before, but if there are still issues with this after you set to never cancel, i would probably use another variable inside the piston to hold the ‘initial’ state of the {@outdoorRearLights} switch when the piston first executes (or where you currently capture attribute), then use the variable to set it back in the last statement.


#7

Tried setting Never Cancel, but it didn’t help.


#8

Are you looking at the “trace” with full logging? it will probably tell you where the piston is getting hung up/stopping/or if the restore is for some reason triggering before the 4 toggles finish. post the full logs for several executions of the piston, that will help us narrow down the issue.

you also might want to use a trigger (if statement) for restoring the attributes… maybe something like:
if {iCount} changes to 4 then with {@outdoorRearLights} do wait 10 seconds… restore attributes…


#9

It’s not getting hung up at all, its just occasionally restoring the wrong state.


#10

Anyone got any other ideas? =/


#11

Okay, how about now?

crosses fingers


#12

A fresh green snapshot here would help, plus a log of a bad event…


#13

Sure. I’ve expanded it a bit, but the problem remains. Some of the time it fails to (re)set the state at exit. IIRC, there’s no error in the logs, it just decides to (re)set the wrong state. I’ll get some logs though…


#14

A log will help us, plus we’d need a green snapshot showing the numbers at the end of each line.
(seen when Trace is on)

Like this:

temp


#15

Of course I can’t get it to do it now. The fact that it’s inconsistent is really annoying.


#16

Got it. Initial state was lanai lights on, keezer light on. Final state was lanai lights on, keezer light off.

12/6/2018, 10:32:11 AM +623ms
+1ms ╔Received event [Walkway Motion].motion = inactive with a delay of 662ms
+7884ms ║RunTime Analysis CS > 24ms > PS > 7798ms > PE > 62ms > CE
+7885ms ║Piston waited at a semaphore for 7765ms
+7888ms ║Runtime (44162 bytes) successfully initialized in 7798ms (v0.3.108.20180906) (7886ms)
+7889ms ║╔Execution stage started
+7898ms ║║Comparison (enum) inactive changes_to (string) active = false (1ms)
+7900ms ║║Cancelling condition #8’s schedules…
+7901ms ║║Condition #8 evaluated false (7ms)
+7902ms ║║Cancelling condition #1’s schedules…
+7904ms ║║Condition group #1 evaluated false (state changed) (9ms)
+7906ms ║╚Execution stage complete. (18ms)
+7907ms ╚Event processed successfully (7908ms)
12/6/2018, 10:32:09 AM +128ms
+1ms ╔Received event [Home].time = 1544110329741 with a delay of -614ms
+270ms ║RunTime Analysis CS > 74ms > PS > 134ms > PE > 63ms > CE
+273ms ║Runtime (44083 bytes) successfully initialized in 134ms (v0.3.108.20180906) (272ms)
+274ms ║╔Execution stage started
+350ms ║║Restoring attribute ‘switch’ to value ‘off’ using command off()
+367ms ║║Executed physical command [Keezer Light].off() (15ms)
+368ms ║║Executed virtual command [Keezer Light].loadStateLocally (25ms)
+376ms ║║Restoring attribute ‘switch’ to value ‘on’ using command on()
+2894ms ║║Executed physical command [Lanai Lights].on() (2516ms)
+2896ms ║║Executed virtual command [Lanai Lights].loadStateLocally (2525ms)
+2899ms ║╚Execution stage complete. (2625ms)
+2901ms ╚Event processed successfully (2901ms)
12/6/2018, 10:32:02 AM +119ms
+1ms ╔Received event [Home].time = 1544110318214 with a delay of 3905ms
+127ms ║RunTime Analysis CS > 27ms > PS > 41ms > PE > 59ms > CE
+130ms ║Runtime (44081 bytes) successfully initialized in 41ms (v0.3.108.20180906) (128ms)
+131ms ║╔Execution stage started
+190ms ║║Executed physical command [Hallway Light].off() (34ms)
+191ms ║║Executed [Hallway Light].off (37ms)
+196ms ║╚Execution stage complete. (65ms)
+198ms ║Setting up scheduled job for Thu, Dec 6 2018 @ 10:32:09 AM EST (in 7.425s)
+207ms ╚Event processed successfully (207ms)
12/6/2018, 10:31:53 AM +11ms
+0ms ╔Received event [Walkway Motion].motion = active with a delay of 662ms
+106ms ║RunTime Analysis CS > 21ms > PS > 29ms > PE > 57ms > CE
+109ms ║Runtime (44089 bytes) successfully initialized in 29ms (v0.3.108.20180906) (108ms)
+111ms ║╔Execution stage started
+121ms ║║Comparison (enum) active changes_to (string) active = true (0ms)
+123ms ║║Cancelling condition #8’s schedules…
+124ms ║║Condition #8 evaluated true (8ms)
+125ms ║║Cancelling condition #1’s schedules…
+126ms ║║Condition group #1 evaluated true (state changed) (10ms)
+146ms ║║Comparison (time) 37913140 is_between (datetime) 1544098080000 … (datetime) 1544135700000 = true (9ms)
+148ms ║║Time restriction check passed
+150ms ║║Condition #19 evaluated true (21ms)
+151ms ║║Condition group #18 evaluated true (state did not change) (22ms)
+164ms ║║Comparison (enum) off is (string) off = true (2ms)
+166ms ║║Condition #31 evaluated true (11ms)
+167ms ║║Condition group #30 evaluated true (state did not change) (13ms)
+170ms ║║Cancelling statement #24’s schedules…
+194ms ║║Executed physical command [Hallway Light].on() (21ms)
+196ms ║║Executed [Hallway Light].on (23ms)
+200ms ║║Executed virtual command [Hallway Light].wait (1ms)
+202ms ║║Requesting a wake up for Thu, Dec 6 2018 @ 10:31:58 AM EST (in 5.0s)
+209ms ║║Cancelling statement #10’s schedules…
+227ms ║║Executed virtual command [Keezer Light].saveStateLocally (1ms)
+229ms ║║Executed virtual command [Lanai Lights].saveStateLocally (1ms)
+238ms ║║Calculating (string) Last trigger on + (string) Thu, Dec 6 2018 @ 10:31:53 AM EST >> (string) Last trigger on Thu, Dec 6 2018 @ 10:31:53 AM EST
+242ms ║║Calculating (string) Last trigger on Thu, Dec 6 2018 @ 10:31:53 AM EST + (string) . >> (string) Last trigger on Thu, Dec 6 2018 @ 10:31:53 AM EST.
+245ms ║║Executed virtual command [Keezer Light, Lanai Lights].setState (1ms)
+250ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (0ms)
+251ms ║║Waiting for 2000ms
+2256ms ║║Cancelling statement #3’s schedules…
+2275ms ║║Executed physical command [Keezer Light].off() (12ms)
+2276ms ║║Executed virtual command [Keezer Light].toggle (16ms)
+2382ms ║║Executed physical command [Lanai Lights].off() (101ms)
+2383ms ║║Executed virtual command [Lanai Lights].toggle (105ms)
+2388ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (1ms)
+2389ms ║║Waiting for 1000ms
+3399ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+3403ms ║║Executed virtual command [Keezer Light, Lanai Lights].setVariable (2ms)
+3410ms ║║Comparison (integer) 1 is_equal_to (integer) 4 = false (2ms)
+3412ms ║║Cancelling condition #7’s schedules…
+3413ms ║║Condition #7 evaluated false (8ms)
+3415ms ║║Cancelling condition #2’s schedules…
+3416ms ║║Condition group #2 evaluated false (state changed) (11ms)
+3419ms ║║Cancelling statement #3’s schedules…
+3436ms ║║Executed physical command [Keezer Light].off() (11ms)
+3437ms ║║Executed virtual command [Keezer Light].toggle (15ms)
+3556ms ║║Executed physical command [Lanai Lights].on() (115ms)
+3557ms ║║Executed virtual command [Lanai Lights].toggle (119ms)
+3562ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (1ms)
+3563ms ║║Waiting for 1000ms
+4571ms ║║Calculating (integer) 1 + (integer) 1 >> (integer) 2
+4575ms ║║Executed virtual command [Keezer Light, Lanai Lights].setVariable (2ms)
+4582ms ║║Comparison (integer) 2 is_equal_to (integer) 4 = false (2ms)
+4584ms ║║Condition #7 evaluated false (7ms)
+4585ms ║║Condition group #2 evaluated false (state did not change) (8ms)
+4588ms ║║Cancelling statement #3’s schedules…
+4606ms ║║Executed physical command [Keezer Light].off() (10ms)
+4607ms ║║Executed virtual command [Keezer Light].toggle (15ms)
+4623ms ║║Executed physical command [Lanai Lights].off() (11ms)
+4625ms ║║Executed virtual command [Lanai Lights].toggle (16ms)
+4629ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (1ms)
+4630ms ║║Waiting for 1000ms
+5638ms ║║Calculating (integer) 2 + (integer) 1 >> (integer) 3
+5642ms ║║Executed virtual command [Keezer Light, Lanai Lights].setVariable (2ms)
+5649ms ║║Comparison (integer) 3 is_equal_to (integer) 4 = false (1ms)
+5651ms ║║Condition #7 evaluated false (6ms)
+5652ms ║║Condition group #2 evaluated false (state did not change) (8ms)
+5655ms ║║Cancelling statement #3’s schedules…
+5671ms ║║Executed physical command [Keezer Light].off() (10ms)
+5673ms ║║Executed virtual command [Keezer Light].toggle (14ms)
+5688ms ║║Executed physical command [Lanai Lights].on() (11ms)
+5689ms ║║Executed virtual command [Lanai Lights].toggle (15ms)
+5694ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (1ms)
+5695ms ║║Waiting for 1000ms
+6703ms ║║Calculating (integer) 3 + (integer) 1 >> (integer) 4
+6707ms ║║Executed virtual command [Keezer Light, Lanai Lights].setVariable (1ms)
+6714ms ║║Comparison (integer) 4 is_equal_to (integer) 4 = true (2ms)
+6715ms ║║Cancelling condition #7’s schedules…
+6717ms ║║Condition #7 evaluated true (7ms)
+6718ms ║║Cancelling condition #2’s schedules…
+6719ms ║║Condition group #2 evaluated true (state changed) (11ms)
+6722ms ║║Cancelling statement #12’s schedules…
+6728ms ║║Executed virtual command [Keezer Light, Lanai Lights].wait (1ms)
+6730ms ║║Requesting a wake up for Thu, Dec 6 2018 @ 10:32:09 AM EST (in 10.0s)
+6735ms ║╚Execution stage complete. (6625ms)
+6737ms ║Setting up scheduled job for Thu, Dec 6 2018 @ 10:31:58 AM EST (in 1s), with 1 more job pending
+6746ms ╚Event processed successfully (6746ms)


#17

Still looking for possible suggestions. Thanks! :wink:


#18

Sorry, I am tied up for the next few days.
Hopefully someone else can chime in…


For what it’s worth, I never capture multiple devices in one line. I always capture each device individually, one per line, and restore them the same way. Your mileage may vary.


#19

Okay, so I switched to using a single device and still have the same issue.

I’m wondering if this could be the problem:

The initial IF is a trigger. Once that goes off, it starts toggling the light. What if the trigger goes off again and capture attributes grabs the state of the device while it’s toggled on, then resets to on when it’s done.

Does that makes sense and/or could that be the issue? If so, I’m not sure how to get around it as the motion sensor only stays active for like 15 seconds.