Problem with wait element in a while loop


#1

Hello

I am having trouble with the wait element in a while loop:

1) Give a description of the problem
I want to create a piston that monitors the state of a window and, if open,
executes an action every 5 minutes (in this case sends a message as a sample).

After querying that the window is open, I would like to use a while loop to check every 5
minutes whether the window is still open.To do this, I wrote a wait statement in the loop.

2) What is the expected behaviour?
When opening the window for the first time, the message “Window open” appears
Every x-minutes the message “Window still open” appears
After closing, the message “Window closed” appears

3) What is happening/not happening?
The Piston runs error-free until the loop (outputs the message Window was opened at the beginning.
Everything in the loop is ignored - no message appears.
The message after the loop (window was closed) is displayed.

5) Attach logs after turning logging level to Full
29.3.2021, 19:57:28 +959ms
+1ms ╔Received event [Fe Bad].threeAxis = [-995,-14,-13] with a delay of 53ms
+58ms ║RunTime Analysis CS > 16ms > PS > 4ms > PE > 37ms > CE
+60ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (58ms)
+61ms ║╔Execution stage started
+68ms ║║Comparison (decimal) -995.0 rises_to_or_above (integer) 400 = false (1ms)
+69ms ║║Condition #2 evaluated false (4ms)
+70ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+75ms ║║Comparison (decimal) -995.0 drops_below (integer) 400 = false (1ms)
+77ms ║║Condition #15 evaluated false (4ms)
+77ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+79ms ║╚Execution stage complete. (18ms)
+80ms ╚Event processed successfully (80ms)
29.3.2021, 19:57:27 +936ms
+1ms ╔Received event [Fe Bad].threeAxis = [-990,-16,-8] with a delay of 47ms
+54ms ║RunTime Analysis CS > 15ms > PS > 4ms > PE > 35ms > CE
+56ms ║Runtime (38327 bytes) successfully initialized in 4ms (v0.3.113.20210203) (54ms)
+57ms ║╔Execution stage started
+64ms ║║Comparison (decimal) -990.0 rises_to_or_above (integer) 400 = false (1ms)
+65ms ║║Condition #2 evaluated false (4ms)
+66ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+71ms ║║Comparison (decimal) -990.0 drops_below (integer) 400 = false (1ms)
+73ms ║║Condition #15 evaluated false (4ms)
+73ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+75ms ║╚Execution stage complete. (18ms)
+76ms ╚Event processed successfully (76ms)
29.3.2021, 19:57:26 +983ms
+1ms ╔Received event [Fe Bad].threeAxis = [-986,-12,-12] with a delay of 56ms
+61ms ║RunTime Analysis CS > 19ms > PS > 4ms > PE > 38ms > CE
+64ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (61ms)
+64ms ║╔Execution stage started
+71ms ║║Comparison (decimal) -986.0 rises_to_or_above (integer) 400 = false (1ms)
+72ms ║║Condition #2 evaluated false (4ms)
+73ms ║║Condition group #1 evaluated false (state did not change) (5ms)
+78ms ║║Comparison (decimal) -986.0 drops_below (integer) 400 = false (0ms)
+80ms ║║Condition #15 evaluated false (5ms)
+81ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+82ms ║╚Execution stage complete. (18ms)
+83ms ╚Event processed successfully (83ms)
29.3.2021, 19:57:25 +907ms
+1ms ╔Received event [Fe Bad].threeAxis = [-995,-11,-13] with a delay of 52ms
+60ms ║RunTime Analysis CS > 18ms > PS > 4ms > PE > 39ms > CE
+62ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (61ms)
+63ms ║╔Execution stage started
+70ms ║║Comparison (decimal) -995.0 rises_to_or_above (integer) 400 = false (1ms)
+72ms ║║Condition #2 evaluated false (4ms)
+73ms ║║Condition group #1 evaluated false (state did not change) (5ms)
+78ms ║║Comparison (decimal) -995.0 drops_below (integer) 400 = false (1ms)
+79ms ║║Condition #15 evaluated false (4ms)
+80ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+82ms ║╚Execution stage complete. (19ms)
+83ms ╚Event processed successfully (83ms)
29.3.2021, 19:57:24 +885ms
+1ms ╔Received event [Fe Bad].threeAxis = [-969,-46,-73] with a delay of 46ms
+54ms ║RunTime Analysis CS > 16ms > PS > 4ms > PE > 33ms > CE
+56ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (54ms)
+57ms ║╔Execution stage started
+65ms ║║Comparison (decimal) -969.0 rises_to_or_above (integer) 400 = false (1ms)
+67ms ║║Condition #2 evaluated false (5ms)
+68ms ║║Condition group #1 evaluated false (state did not change) (7ms)
+74ms ║║Comparison (decimal) -969.0 drops_below (integer) 400 = false (1ms)
+75ms ║║Condition #15 evaluated false (5ms)
+76ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+78ms ║╚Execution stage complete. (21ms)
+79ms ╚Event processed successfully (79ms)
29.3.2021, 19:57:24 +397ms
+1ms ╔Received event [Fe Bad].threeAxis = [-988,-16,-13] with a delay of 52ms
+60ms ║RunTime Analysis CS > 17ms > PS > 4ms > PE > 39ms > CE
+62ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (60ms)
+63ms ║╔Execution stage started
+70ms ║║Comparison (decimal) -988.0 rises_to_or_above (integer) 400 = false (0ms)
+71ms ║║Condition #2 evaluated false (4ms)
+72ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+77ms ║║Comparison (decimal) -988.0 drops_below (integer) 400 = false (1ms)
+78ms ║║Condition #15 evaluated false (4ms)
+79ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+80ms ║╚Execution stage complete. (17ms)
+81ms ╚Event processed successfully (81ms)
29.3.2021, 19:57:23 +383ms
+1ms ╔Received event [Fe Bad].threeAxis = [-992,-17,-14] with a delay of 52ms
+50ms ║RunTime Analysis CS > 14ms > PS > 4ms > PE > 32ms > CE
+53ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (50ms)
+53ms ║╔Execution stage started
+60ms ║║Comparison (decimal) -992.0 rises_to_or_above (integer) 400 = false (1ms)
+62ms ║║Condition #2 evaluated false (5ms)
+63ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+68ms ║║Comparison (decimal) -992.0 drops_below (integer) 400 = false (1ms)
+69ms ║║Condition #15 evaluated false (4ms)
+70ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+72ms ║╚Execution stage complete. (18ms)
+73ms ╚Event processed successfully (73ms)
29.3.2021, 19:57:22 +465ms
+1ms ╔Received event [Fe Bad].threeAxis = [-993,-12,-13] with a delay of 44ms
+56ms ║RunTime Analysis CS > 15ms > PS > 3ms > PE > 37ms > CE
+58ms ║Runtime (38323 bytes) successfully initialized in 3ms (v0.3.113.20210203) (56ms)
+59ms ║╔Execution stage started
+67ms ║║Comparison (decimal) -993.0 rises_to_or_above (integer) 400 = false (1ms)
+68ms ║║Condition #2 evaluated false (5ms)
+69ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+75ms ║║Comparison (decimal) -993.0 drops_below (integer) 400 = false (1ms)
+76ms ║║Cancelling condition #15’s schedules…
+77ms ║║Condition #15 evaluated false (5ms)
+78ms ║║Cancelling condition #14’s schedules…
+79ms ║║Condition group #14 evaluated false (state changed) (7ms)
+81ms ║╚Execution stage complete. (22ms)
+82ms ╚Event processed successfully (82ms)
29.3.2021, 19:57:21 +376ms
+1ms ╔Received event [Fe Bad].threeAxis = [-994,-13,-14] with a delay of 44ms
+52ms ║RunTime Analysis CS > 15ms > PS > 4ms > PE > 32ms > CE
+54ms ║Runtime (38328 bytes) successfully initialized in 4ms (v0.3.113.20210203) (52ms)
+55ms ║╔Execution stage started
+62ms ║║Comparison (decimal) -994.0 rises_to_or_above (integer) 400 = false (0ms)
+64ms ║║Condition #2 evaluated false (5ms)
+65ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+71ms ║║Comparison (decimal) -994.0 drops_below (integer) 400 = true (0ms)
+72ms ║║Cancelling condition #15’s schedules…
+73ms ║║Condition #15 evaluated true (6ms)
+74ms ║║Cancelling condition #14’s schedules…
+75ms ║║Condition group #14 evaluated true (state changed) (8ms)
+77ms ║║Cancelling statement #16’s schedules…
+104ms ║║Executed virtual command sendPushNotification (24ms)
+107ms ║╚Execution stage complete. (52ms)
+108ms ╚Event processed successfully (108ms)
29.3.2021, 19:57:20 +371ms
+1ms ╔Received event [Fe Bad].threeAxis = [1056,84,199] with a delay of 75ms
+46ms ║RunTime Analysis CS > 11ms > PS > 3ms > PE > 32ms > CE
+48ms ║Runtime (38327 bytes) successfully initialized in 3ms (v0.3.113.20210203) (46ms)
+49ms ║╔Execution stage started
+56ms ║║Comparison (decimal) 1056.0 rises_to_or_above (integer) 400 = false (0ms)
+57ms ║║Condition #2 evaluated false (4ms)
+58ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+63ms ║║Comparison (decimal) 1056.0 drops_below (integer) 400 = false (1ms)
+64ms ║║Condition #15 evaluated false (4ms)
+65ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+67ms ║╚Execution stage complete. (18ms)
+68ms ╚Event processed successfully (68ms)
29.3.2021, 19:57:02 +786ms
+1ms ╔Received event [Fe Bad].threeAxis = [1036,76,53] with a delay of 48ms
+51ms ║RunTime Analysis CS > 17ms > PS > 4ms > PE > 31ms > CE
+53ms ║Runtime (38326 bytes) successfully initialized in 4ms (v0.3.113.20210203) (52ms)
+54ms ║╔Execution stage started
+62ms ║║Comparison (decimal) 1036.0 rises_to_or_above (integer) 400 = false (0ms)
+63ms ║║Condition #2 evaluated false (5ms)
+64ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+70ms ║║Comparison (decimal) 1036.0 drops_below (integer) 400 = false (0ms)
+71ms ║║Condition #15 evaluated false (4ms)
+72ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+74ms ║╚Execution stage complete. (20ms)
+75ms ╚Event processed successfully (75ms)
29.3.2021, 19:57:01 +880ms
+1ms ╔Received event [Fe Bad].threeAxis = [1042,74,57] with a delay of 73ms
+51ms ║RunTime Analysis CS > 16ms > PS > 5ms > PE > 31ms > CE
+54ms ║Runtime (38326 bytes) successfully initialized in 5ms (v0.3.113.20210203) (51ms)
+55ms ║╔Execution stage started
+62ms ║║Comparison (decimal) 1042.0 rises_to_or_above (integer) 400 = false (1ms)
+63ms ║║Condition #2 evaluated false (4ms)
+64ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+70ms ║║Comparison (decimal) 1042.0 drops_below (integer) 400 = false (1ms)
+71ms ║║Condition #15 evaluated false (4ms)
+72ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+74ms ║╚Execution stage complete. (20ms)
+75ms ╚Event processed successfully (75ms)
29.3.2021, 19:57:00 +736ms
+1ms ╔Received event [Fe Bad].threeAxis = [1055,65,67] with a delay of 44ms
+153ms ║RunTime Analysis CS > 21ms > PS > 4ms > PE > 127ms > CE
+156ms ║Runtime (38323 bytes) successfully initialized in 4ms (v0.3.113.20210203) (153ms)
+157ms ║╔Execution stage started
+164ms ║║Comparison (decimal) 1055.0 rises_to_or_above (integer) 400 = false (1ms)
+166ms ║║Cancelling condition #2’s schedules…
+167ms ║║Condition #2 evaluated false (6ms)
+168ms ║║Cancelling condition #1’s schedules…
+169ms ║║Condition group #1 evaluated false (state changed) (8ms)
+174ms ║║Comparison (decimal) 1055.0 drops_below (integer) 400 = false (1ms)
+176ms ║║Condition #15 evaluated false (5ms)
+177ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+179ms ║╚Execution stage complete. (22ms)
+185ms ╚Event processed successfully (185ms)
29.3.2021, 19:56:59 +714ms
+1ms ╔Received event [Fe Bad].threeAxis = [1080,74,105] with a delay of 40ms
+48ms ║RunTime Analysis CS > 15ms > PS > 4ms > PE > 29ms > CE
+50ms ║Runtime (38324 bytes) successfully initialized in 4ms (v0.3.113.20210203) (48ms)
+51ms ║╔Execution stage started
+58ms ║║Comparison (decimal) 1080.0 rises_to_or_above (integer) 400 = true (1ms)
+60ms ║║Cancelling condition #2’s schedules…
+61ms ║║Condition #2 evaluated true (6ms)
+62ms ║║Cancelling condition #1’s schedules…
+63ms ║║Condition group #1 evaluated true (state changed) (7ms)
+65ms ║║Cancelling statement #3’s schedules…
+75ms ║║Executed virtual command sendPushNotification (7ms)
+82ms ║║Comparison (decimal) 1080.0 is_greater_than (integer) 400 = true (1ms)
+83ms ║║Condition #6 evaluated true (5ms)
+84ms ║║Condition group #5 evaluated true (state did not change) (6ms)
+86ms ║║Cancelling statement #7’s schedules…
+89ms ║║Executed virtual command wait (0ms)
+91ms ║║Requesting a wake up for Mon, Mar 29 2021 @ 7:57:09 PM CEST (in 10.0s)
+95ms ║╚Execution stage complete. (44ms)
+96ms ║Setting up scheduled job for Mon, Mar 29 2021 @ 7:57:09 PM CEST (in 9s)
+104ms ╚Event processed successfully (104ms)
29.3.2021, 19:56:58 +711ms
+1ms ╔Received event [Fe Bad].threeAxis = [3,-6,1067] with a delay of 48ms
+50ms ║RunTime Analysis CS > 16ms > PS > 4ms > PE > 29ms > CE
+52ms ║Runtime (38326 bytes) successfully initialized in 4ms (v0.3.113.20210203) (50ms)
+53ms ║╔Execution stage started
+60ms ║║Comparison (decimal) 3.0 rises_to_or_above (integer) 400 = false (1ms)
+62ms ║║Condition #2 evaluated false (4ms)
+63ms ║║Condition group #1 evaluated false (state did not change) (5ms)
+68ms ║║Comparison (decimal) 3.0 drops_below (integer) 400 = false (1ms)
+69ms ║║Condition #15 evaluated false (4ms)
+70ms ║║Condition group #14 evaluated false (state did not change) (5ms)
+72ms ║╚Execution stage complete. (20ms)
+73ms ╚Event processed successfully (73ms)
29.3.2021, 19:56:57 +723ms
+1ms ╔Received event [Fe Bad].threeAxis = [-1235,-237,179] with a delay of 47ms
+48ms ║RunTime Analysis CS > 14ms > PS > 4ms > PE > 30ms > CE
+50ms ║Runtime (38330 bytes) successfully initialized in 4ms (v0.3.113.20210203) (48ms)
+51ms ║╔Execution stage started
+58ms ║║Comparison (decimal) -1235.0 rises_to_or_above (integer) 400 = false (0ms)
+59ms ║║Condition #2 evaluated false (4ms)
+60ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+65ms ║║Comparison (decimal) -1235.0 drops_below (integer) 400 = false (0ms)
+67ms ║║Condition #15 evaluated false (5ms)
+68ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+69ms ║╚Execution stage complete. (18ms)
+70ms ╚Event processed successfully (70ms)

Thank you for any support!


#2

Skip the IF and go directly to While loop, so the piston will subscribe to the sensor1 event, or force the subscription of line #22, go to its options and change automatic to always subscribe.

while sensor1 axisX is above 400
  wait 10 seconds
  send push notification
end while

#3

In addition to @eibyer’s great advice, be sure your ‘with’ statement inside the loop is set to ‘never cancel tasks’. This is almost always necessary with waits to be sure it comes back even if interrupted by another event.