Just a quick question. I have a DO WHILE statement. I assumed that once the WHILE was no longer true, the DO items would be cancelled. That apparently is not the case. What would I need to do in the below piston to makes sure everything stops running once Contact Sensor 1 is closed.
How to stop processing a DO WHILE statement?
I’ve never used DO WHILE but for other stop (WAIT ie) you can use CANCEL ALL PENDING TASKS
I am only assuming this would also work for DO WHILE…
You can also look at a Repeat Loop.
I use the Repeat Loop below to ensure that my thermostat has changed it’s heating and cooling setpoints to match what I wanted them to be.
Note the ‘UNTIL’ section. There are two conditions in there - one to see if the setpoints requested match those in the thermostat and the second condition checks on my loop counter. If the setpoints match or the piston loops (5) times without matching, ithe piston exits and lets me know.
Cancel all pending tasks is the default, and I had assumed that it would cancel everything once Contact Sensor 1 closes. But that doesn’t seem to be the case. What am I missing?
Doesn’t a While statement only check at the beginning of each time through? So in your case, it sees that the sensor is open. It may be that it’s gonna do everything once before it checks again. Make it wait a shorter time, even into the seconds range. Use an If statement at the beginning of the loop to execute the rest if the variable reaches a high enough level. That way it always checks the status of the sensor immediately before it tries to say anything.
While Sensor Open { Do { If Counter > 360 { Speak; Counter=0}; Wait 5 seconds; Counter ++}}
That kind of thing. If that makes any sense…
It seems that you’re right that it only checks at the start, but doesn’t an IF reevaluate immediately upon a state change? My assumption was that everything did. Is that my error? If so, why would webcore evaluate them differently?
Not sure how things are setup in WebCore… My experience with While statements in general has just been that way, and what I suggested was more of a hunch.
If statements do re-evaluate on a condition change, so you are right about that. Someone smarter than me will have to answer about why a while is different.
Strange, I copied your piston and sped it up to 30 secs and it is cancelling the tasks… one difference is I’m logging only and not using speak, but still that shouldn’t make a difference?
I’m going to try 3 mins this time.
Maybe logs would help? I opened the garage door (contact sensor 1), left it open for 20-30 seconds, and closed it. The contact now shows closed, yet I can still see the timer counting down in the webcore UI.
Logs:
2/26/2019, 4:15:08 PM +554ms
+2ms ╔Received event [Garage Door].contact = open with a delay of 95ms
+10149ms ║RunTime Analysis CS > 27ms > PS > 10073ms > PE > 48ms > CE
+10150ms ║Piston waited at a semaphore for 10022ms
+10153ms ║Runtime (44046 bytes) successfully initialized in 10073ms (v0.3.10a.20190223) (10150ms)
+10154ms ║╔Execution stage started
+10166ms ║║Comparison (enum) open changes_to (string) open = true (1ms)
+10168ms ║║Cancelling condition #33’s schedules…
+10170ms ║║Condition #33 evaluated true (8ms)
+10171ms ║║Cancelling condition #30’s schedules…
+10173ms ║║Condition group #30 evaluated true (state changed) (11ms)
+10176ms ║║Cancelling statement #31’s schedules…
+10184ms ║║Executed virtual command setVariable (3ms)
+10194ms ║║Comparison (enum) open is (string) open = true (2ms)
+10197ms ║║Cancelling condition #2’s schedules…
+10198ms ║║Condition #2 evaluated true (10ms)
+10199ms ║║Cancelling condition #1’s schedules…
+10201ms ║║Condition group #1 evaluated true (state changed) (12ms)
+10204ms ║║Cancelling statement #15’s schedules…
+10211ms ║║Executed virtual command [Garage Door].setState (0ms)
+10216ms ║║Executed virtual command [Garage Door].wait (0ms)
+10218ms ║║Requesting a wake up for Tue, Feb 26 2019 @ 4:45:18 PM EST (in 1800.0s)
+10224ms ║╚Execution stage complete. (70ms)
+10226ms ║Setting up scheduled job for Tue, Feb 26 2019 @ 4:45:18 PM EST (in 1799.993s)
+10237ms ╚Event processed successfully (10237ms)
2/26/2019, 4:15:11 PM +70ms
+1ms ╔Received event [Garage Door].contact = closed with a delay of 99ms
+124ms ║RunTime Analysis CS > 26ms > PS > 53ms > PE > 46ms > CE
+127ms ║Runtime (43963 bytes) successfully initialized in 53ms (v0.3.10a.20190223) (125ms)
+128ms ║╔Execution stage started
+139ms ║║Comparison (enum) closed changes_to (string) open = false (1ms)
+141ms ║║Cancelling condition #33’s schedules…
+142ms ║║Condition #33 evaluated false (7ms)
+144ms ║║Cancelling condition #30’s schedules…
+145ms ║║Condition group #30 evaluated false (state changed) (11ms)
+154ms ║║Comparison (enum) closed is (string) open = false (2ms)
+156ms ║║Cancelling condition #2’s schedules…
+157ms ║║Condition #2 evaluated false (9ms)
+159ms ║║Cancelling condition #1’s schedules…
+160ms ║║Condition group #1 evaluated false (state changed) (12ms)
+168ms ║║Comparison (enum) closed changes_to (string) closed = true (1ms)
+170ms ║║Cancelling condition #19’s schedules…
+171ms ║║Condition #19 evaluated true (7ms)
+173ms ║║Cancelling condition #18’s schedules…
+174ms ║║Condition group #18 evaluated true (state changed) (10ms)
+182ms ║║Comparison (integer) 0 is_greater_than (integer) 0 = false (2ms)
+184ms ║║Cancelling condition #37’s schedules…
+186ms ║║Condition #37 evaluated false (8ms)
+187ms ║║Cancelling condition #34’s schedules…
+188ms ║║Condition group #34 evaluated false (state changed) (11ms)
+193ms ║╚Execution stage complete. (64ms)
+194ms ╚Event processed successfully (194ms)
2/26/2019, 4:15:10 PM +310ms
+2ms ╔Received event [Garage Door].contact = open with a delay of 104ms
+121ms ║RunTime Analysis CS > 28ms > PS > 53ms > PE > 40ms > CE
+124ms ║Runtime (44088 bytes) successfully initialized in 53ms (v0.3.10a.20190223) (120ms)
+126ms ║╔Execution stage started
+137ms ║║Comparison (enum) open changes_to (string) open = true (1ms)
+139ms ║║Cancelling condition #33’s schedules…
+140ms ║║Condition #33 evaluated true (8ms)
+142ms ║║Cancelling condition #30’s schedules…
+143ms ║║Condition group #30 evaluated true (state changed) (11ms)
+146ms ║║Cancelling statement #31’s schedules…
+155ms ║║Executed virtual command setVariable (4ms)
+165ms ║║Comparison (enum) open is (string) open = true (2ms)
+167ms ║║Cancelling condition #2’s schedules…
+168ms ║║Condition #2 evaluated true (9ms)
+170ms ║║Cancelling condition #1’s schedules…
+171ms ║║Condition group #1 evaluated true (state changed) (12ms)
+174ms ║║Cancelling statement #15’s schedules…
+181ms ║║Executed virtual command [Garage Door].setState (0ms)
+186ms ║║Executed virtual command [Garage Door].wait (0ms)
+187ms ║║Requesting a wake up for Tue, Feb 26 2019 @ 4:45:10 PM EST (in 1800.0s)
+194ms ║╚Execution stage complete. (68ms)
+196ms ║Setting up scheduled job for Tue, Feb 26 2019 @ 4:45:10 PM EST (in 1799.993s)
+207ms ╚Event processed successfully (207ms)
2/26/2019, 4:15:09 PM +564ms
+1ms ╔Received event [Garage Door].contact = closed with a delay of 102ms
+119ms ║RunTime Analysis CS > 19ms > PS > 58ms > PE > 41ms > CE
+121ms ║Runtime (44088 bytes) successfully initialized in 58ms (v0.3.10a.20190223) (119ms)
+123ms ║╔Execution stage started
+133ms ║║Comparison (enum) closed changes_to (string) open = false (1ms)
+135ms ║║Condition #33 evaluated false (6ms)
+136ms ║║Condition group #30 evaluated false (state did not change) (8ms)
+145ms ║║Comparison (enum) closed is (string) open = false (2ms)
+147ms ║║Condition #2 evaluated false (7ms)
+148ms ║║Condition group #1 evaluated false (state did not change) (9ms)
+156ms ║║Comparison (enum) closed changes_to (string) closed = false (0ms)
+158ms ║║Cancelling condition #19’s schedules…
+159ms ║║Condition #19 evaluated false (7ms)
+160ms ║║Cancelling condition #18’s schedules…
+161ms ║║Condition group #18 evaluated false (state changed) (10ms)
+164ms ║╚Execution stage complete. (42ms)
+165ms ╚Event processed successfully (165ms)
2/26/2019, 4:15:08 PM +413ms
+2ms ╔Received event [Garage Door].contact = closed with a delay of 98ms
+113ms ║RunTime Analysis CS > 19ms > PS > 53ms > PE > 40ms > CE
+116ms ║Runtime (43965 bytes) successfully initialized in 53ms (v0.3.10a.20190223) (112ms)
+117ms ║╔Execution stage started
+128ms ║║Comparison (enum) closed changes_to (string) open = false (1ms)
+131ms ║║Cancelling condition #33’s schedules…
+132ms ║║Condition #33 evaluated false (7ms)
+133ms ║║Cancelling condition #30’s schedules…
+134ms ║║Condition group #30 evaluated false (state changed) (11ms)
+144ms ║║Comparison (enum) closed is (string) open = false (2ms)
+146ms ║║Cancelling condition #2’s schedules…
+147ms ║║Condition #2 evaluated false (9ms)
+148ms ║║Cancelling condition #1’s schedules…
+149ms ║║Condition group #1 evaluated false (state changed) (11ms)
+157ms ║║Comparison (enum) closed changes_to (string) closed = true (1ms)
+159ms ║║Cancelling condition #19’s schedules…
+160ms ║║Condition #19 evaluated true (7ms)
+162ms ║║Cancelling condition #18’s schedules…
+163ms ║║Condition group #18 evaluated true (state changed) (11ms)
+171ms ║║Comparison (integer) 30 is_greater_than (integer) 0 = true (2ms)
+173ms ║║Cancelling condition #37’s schedules…
+174ms ║║Condition #37 evaluated true (8ms)
+176ms ║║Cancelling condition #34’s schedules…
+177ms ║║Condition group #34 evaluated true (state changed) (11ms)
+180ms ║║Cancelling statement #35’s schedules…
+191ms ║║Executed virtual command [Echo - Living Room].setVariable (3ms)
+505ms ║║Executed physical command [Echo - Living Room].speak([The garage door is now closed.]) (308ms)
+506ms ║║Executed [Echo - Living Room].speak (311ms)
+524ms ║║Executed virtual command [Echo - Living Room].sendPushNotification (13ms)
+533ms ║║Calculating (string) Garage door currently closed. Last opened at + (string) Tue, Feb 26 2019 @ 4:14:22 PM EST >> (string) Garage door currently closed. Last opened at Tue, Feb 26 2019 @ 4:14:22 PM EST
+536ms ║║Calculating (string) Garage door currently closed. Last opened at Tue, Feb 26 2019 @ 4:14:22 PM EST + (string) . >> (string) Garage door currently closed. Last opened at Tue, Feb 26 2019 @ 4:14:22 PM EST.
+540ms ║║Executed virtual command [Echo - Living Room].setState (1ms)
+545ms ║╚Execution stage complete. (428ms)
+546ms ╚Event processed successfully (546ms)
2/26/2019, 4:14:22 PM +40ms
+1ms ╔Received event [Garage Door].contact = open with a delay of 91ms
+191ms ║RunTime Analysis CS > 19ms > PS > 134ms > PE > 38ms > CE
+194ms ║Runtime (43968 bytes) successfully initialized in 134ms (v0.3.10a.20190223) (191ms)
+195ms ║╔Execution stage started
+206ms ║║Comparison (enum) open changes_to (string) open = true (0ms)
+208ms ║║Condition #33 evaluated true (6ms)
+209ms ║║Condition group #30 evaluated true (state did not change) (8ms)
+212ms ║║Cancelling statement #31’s schedules…
+220ms ║║Executed virtual command setVariable (4ms)
+230ms ║║Comparison (enum) open is (string) open = true (2ms)
+232ms ║║Cancelling condition #2’s schedules…
+233ms ║║Condition #2 evaluated true (9ms)
+234ms ║║Cancelling condition #1’s schedules…
+235ms ║║Condition group #1 evaluated true (state changed) (11ms)
+238ms ║║Cancelling statement #15’s schedules…
+244ms ║║Executed virtual command [Garage Door].setState (1ms)
+249ms ║║Executed virtual command [Garage Door].wait (0ms)
+250ms ║║Requesting a wake up for Tue, Feb 26 2019 @ 4:44:22 PM EST (in 1800.0s)
+256ms ║╚Execution stage complete. (62ms)
+258ms ║Setting up scheduled job for Tue, Feb 26 2019 @ 4:44:22 PM EST (in 1799.994s)
+266ms ╚Event processed successfully (266ms)
This is the log for the 3 mins… there’s a wakeup scheduled at 2:18:24 PM which is the last entry in the log after the door was closed. The timer woke up but didn’t perform the tasks.
Actually, as I looked at the device logs in the IDE, could this be an issue with the device handler? I opened it once, and closed it once. Yet this is what I see:
Hmm, that weird. I don’t know what to make of that lol. But in the end with the door/contact being closed the tasks should still cancel, right?
Try substituting a different contact device for the garage door and see if you get the same result?
I thought they should, but they do not cancel. Once the door is closed, it does one more loop before determining that the contact is closed.
Could it be that the events are happening too quickly for webcore to process? These quick open/close events happen over tenths of second.
Usually when that happens (quick succession of events) you’ll see the ‘waiting at semaphore’ message.
Okay, this is super weird. Is it somehow possible for a piston to just be broken? At your suggestion, I changed the contact sensor to my front/garage doors. However, the piston isn’t seeing the events for the door(s).
Logs (showing nothing)
2/26/2019, 4:55:27 PM +423ms
+1ms ╔Starting piston... (v0.3.10a.20190223)
+379ms ║╔Subscribing to devices...
+400ms ║║Subscribing to Garage Door.contact...
+597ms ║║Subscribing to Front/Garage Doors...
+598ms ║║Subscribing to Echo - Living Room...
+600ms ║╚Finished subscribing (231ms)
+648ms ║Comparison (enum) open is (string) open = true (2ms)
+651ms ║Cancelling condition #2's schedules...
+653ms ║Cancelling condition #1's schedules...
+679ms ║Comparison (integer) 60 is_greater_than (integer) 0 = true (2ms)
+690ms ╚Piston successfully started (690ms)
I noticed that on your first post you were at build 31 already… so it could be possible. I’d try a fresh one just in case.
I see the while
statement doesn’t have the lightning bolt so try and force it to subscribe to the event, change it from auto to always.