Strange variable behavior


#1

1) Give a description of the problem
In webCoRE I wrote some code to achive the following: When a door sensor is open for more then 20 seconds a push notification is sent to me every 20 seconds. If the door sensor get the state closed within 20 seconds nothing happens. But if the door is closed after a push message you get push notification with the text “Thanks for closing door”. When I het this script working I’ll let mij Google Nest Mini talk the notifications.

2) What is the expected behaviour?
I expect that the script should run ok, but the variable “dooropened” seems to lose the valie "true"after leaving the repeat loop en get the value “false”, which causes the if-statement after the repeat loop not to trigger the push notification.

3) What is happening/not happening?
The variable “dooropened” doens’t retain its value after leaving the repeat loop.

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HER

E)

5) Attach logs after turning logging level to Full
1/13/2021, 9:45:18 PM +112ms
+1ms ╔Received event [My home].time = 1610570719202 with a delay of -1090ms
+79ms ║RunTime Analysis CS > 39ms > PS > 4ms > PE > 36ms > CE
+82ms ║Runtime (39653 bytes) successfully initialized in 4ms (v0.3.110.20191009) (80ms)
+83ms ║╔Execution stage started
+84ms ║╚Execution stage complete. (2ms)
+85ms ╚Event processed successfully (85ms)
1/13/2021, 9:45:09 PM +710ms
+1ms ╔Received event [Door sesnsor test].contact = closed with a delay of 77ms
+45ms ║RunTime Analysis CS > 13ms > PS > 4ms > PE > 28ms > CE
+48ms ║Runtime (39648 bytes) successfully initialized in 4ms (v0.3.110.20191009) (46ms)
+49ms ║╔Execution stage started
+52ms ║║Cancelling statement #23’s schedules…
+58ms ║║Executed virtual command setVariable (2ms)
+64ms ║║Comparison (enum) closed is (string) open = false (1ms)
+65ms ║║Cancelling condition #2’s schedules…
+66ms ║║Condition #2 evaluated false (6ms)
+67ms ║║Cancelling condition #1’s schedules…
+68ms ║║Condition group #1 evaluated false (state changed) (7ms)
+70ms ║╚Execution stage complete. (21ms)
+71ms ╚Event processed successfully (70ms)
1/13/2021, 9:44:59 PM +41ms
+0ms ╔Received event [My home].time = 1610570699997 with a delay of -957ms
+55ms ║RunTime Analysis CS > 16ms > PS > 4ms > PE > 35ms > CE
+57ms ║Runtime (39645 bytes) successfully initialized in 4ms (v0.3.110.20191009) (56ms)
+58ms ║╔Execution stage started
+103ms ║║Comparison (enum) open is (string) open = true (1ms)
+105ms ║║Condition #10 evaluated true (34ms)
+106ms ║║Condition group #9 evaluated true (state did not change) (35ms)
+108ms ║║Cancelling statement #18’s schedules…
+114ms ║║Executed virtual command setVariable (3ms)
+131ms ║║Executed virtual command sendPushNotification (11ms)
+150ms ║║Comparison (enum) open is (string) closed = false (1ms)
+152ms ║║Condition #6 evaluated false (19ms)
+153ms ║║Condition group #5 evaluated false (state did not change) (21ms)
+155ms ║║Cancelling statement #7’s schedules…
+159ms ║║Executed virtual command wait (0ms)
+160ms ║║Requesting a wake up for Wed, Jan 13 2021 @ 9:45:19 PM CET (in 20.0s)
+165ms ║╚Execution stage complete. (106ms)
+166ms ║Setting up scheduled job for Wed, Jan 13 2021 @ 9:45:19 PM CET (in 19.996s)
+172ms ╚Event processed successfully (172ms)
1/13/2021, 9:44:39 PM +912ms
+2ms ╔Received event [Door sesnsor test].contact = open with a delay of 119ms
+52ms ║RunTime Analysis CS > 18ms > PS > 5ms > PE > 28ms > CE
+54ms ║Runtime (39655 bytes) successfully initialized in 5ms (v0.3.110.20191009) (51ms)
+55ms ║╔Execution stage started
+60ms ║║Cancelling statement #23’s schedules…
+65ms ║║Executed virtual command setVariable (3ms)
+71ms ║║Comparison (enum) open is (string) open = true (1ms)
+73ms ║║Cancelling condition #2’s schedules…
+74ms ║║Condition #2 evaluated true (7ms)
+75ms ║║Cancelling condition #1’s schedules…
+76ms ║║Condition group #1 evaluated true (state changed) (9ms)
+79ms ║║Cancelling statement #7’s schedules…
+83ms ║║Executed virtual command wait (0ms)
+84ms ║║Requesting a wake up for Wed, Jan 13 2021 @ 9:44:59 PM CET (in 20.0s)
+89ms ║╚Execution stage complete. (34ms)
+90ms ║Setting up scheduled job for Wed, Jan 13 2021 @ 9:44:59 PM CET (in 19.995s)
+111ms ╚Event processed successfully (111ms)


#2

Try moving line #18 right after line #39


#3

When the door closes the piston fires and because it is almost certainly in a 20 second wait it runs the new instance immediately, sets the variable false and kills the scheduled task and so the loop.

You need to set the Task Cancellation Policy to Never Cancel on the wait to keep the loop going, and move the variable inside the if so it is only initialised to false in response to the door opening.


#4

Tnx for your tip. I tried what you said and the variable kept the value true, but it never went through the condition if (dooropened is true and Door sensor test’s contact is closed).


#5

Tnx for your tip. I didn’t even now that you can set an Task Cancellation Policy. I tried what you said and it seems to be working fine now.

Piston code: