While Block execution?


#1

1) Give a description of the problem
I have provided the event log with my mark ups in yellow and text in red. The event log was cleared before a garage door contact event occurred. It seems to execute property until it reached the While block.

2) What is the expected behavior?
The code is intended to detect the garage door open, and, if so, display that event with a light attached to an outlet.
If the outlet was found to be off before the garage door was opened, it will be turned on.
If the outlet was on then it will do a 1 second flash off every 30 sec while the garage door is opened.
When the garage door closes the outlet will be returned to its original state.
At least that’s the plan .

3) What is happening/not happening?
It seems like the While block does not execute correctly

**4) Post a Green Snapshot of the piston![image|45x37]


5) Attach any logs (From ST IDE and by turning logging level to Full)
9/23/2017, 3:08:22 PM +434ms
+1ms ╔Received event [Home].time = 1506193702640 with a delay of -207ms
+185ms ║RunTime Analysis CS > 42ms > PS > 43ms > PE > 100ms > CE
+197ms ║Runtime (42097 bytes) successfully initialized in 43ms (v0.2.0e7.20170906) (194ms)
+198ms ║╔Execution stage started
+280ms ║║Skipped execution of physical command [Link To Garage Door].on([]) because it would make no change to the device. (4ms)
+281ms ║║Executed [Link To Garage Door].on (6ms)
+293ms ║║Executed virtual command [Link To Garage Door].wait (7ms)
+295ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 3:08:52 PM EDT (in 30.0s)
+309ms ║╚Execution stage complete. (112ms)
+312ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 3:08:52 PM EDT (in 29.988s)
+328ms ╚Event processed successfully (328ms)
9/23/2017, 3:08:10 PM +520ms
+2ms ╔Received event [Link To Garage Door].switch = on with a delay of 716ms
+10906ms ║RunTime Analysis CS > 24ms > PS > 10748ms > PE > 134ms > CE
+10917ms ║Piston waited at a semaphore for 10691ms
+10920ms ║Runtime (42182 bytes) successfully initialized in 10748ms (v0.2.0e7.20170906) (10917ms)
+10922ms ║╔Execution stage started
+10948ms ║║Comparison (enum) open is (string) open = true (3ms)
+10951ms ║║Condition #14 evaluated true (16ms) (Contact opened)
+10964ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+10966ms ║║Condition #15 evaluated true (14ms) Event Not in progress)
+10967ms ║║Condition group #5 evaluated true (state did not change) (34ms)
+10982ms ║║Comparison (enum) on is (string) on = true (4ms) Start a garage door even
+10984ms ║║Condition #13 evaluated true (12ms) The outlet was found to be ON
+10986ms ║║Condition group #6 evaluated true (state did not change) (15ms)
+10990ms ║║Cancelling statement #10’s schedules…
+11000ms ║║Executed virtual command setVariable (4ms)
+11008ms ║║Executed virtual command setVariable (1ms)
+11028ms ║║Comparison (enum) open is (string) closed = false (3ms)
+11031ms ║║Condition #19 evaluated false (15ms)
+11032ms ║║Condition group #16 evaluated false (state did not change) (17ms)
+11046ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+11048ms ║║Condition #33 evaluated true (10ms)
+11050ms ║║Condition group #32 evaluated true (state did not change) (12ms)
+11062ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+11064ms ║║Condition #31 evaluated true (10ms)
+11066ms ║║Condition group #21 evaluated true (state did not change) (12ms)
+11078ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+11080ms ║║Condition #30 evaluated true (10ms)
+11082ms ║║Condition group #22 evaluated true (state did not change) (13ms)
+11086ms ║║Cancelling statement #25’s schedules… ??? What happened here?
+11109ms ║║Executed physical command [Link To Garage Door].off() (18ms)
+11111ms ║║Executed [Link To Garage Door].off (20ms)
+11117ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+11119ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 3:08:22 PM EDT (in 1.0s)
+11131ms ║╚Execution stage complete. (209ms)
+11133ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 3:08:22 PM EDT (in 1s)
+11154ms ╚Event processed successfully (11153ms)
9/23/2017, 3:08:10 PM +488ms
+2ms ╔Received event [Link To Garage Door].switch = on with a delay of 725ms
+10349ms ║RunTime Analysis CS > 28ms > PS > 10224ms > PE > 97ms > CE
+10361ms ║Piston waited at a semaphore for 10169ms
+10364ms ║Runtime (42182 bytes) successfully initialized in 10224ms (v0.2.0e7.20170906) (10361ms)
+10366ms ║╔Execution stage started
+10392ms ║║Comparison (enum) open is (string) open = true (3ms)
+10394ms ║║Condition #14 evaluated true (16ms)
+10407ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+10410ms ║║Condition #15 evaluated true (14ms)
+10411ms ║║Condition group #5 evaluated true (state did not change) (34ms)
+10426ms ║║Comparison (enum) on is (string) on = true (4ms)
+10429ms ║║Condition #13 evaluated true (12ms)
+10430ms ║║Condition group #6 evaluated true (state did not change) (15ms)
+10435ms ║║Cancelling statement #10’s schedules…
+10445ms ║║Executed virtual command setVariable (5ms)
+10452ms ║║Executed virtual command setVariable (2ms)
+10471ms ║║Comparison (enum) open is (string) closed = false (3ms)
+10473ms ║║Condition #19 evaluated false (13ms)
+10475ms ║║Condition group #16 evaluated false (state did not change) (16ms)
+10488ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10491ms ║║Condition #33 evaluated true (10ms)
+10492ms ║║Condition group #32 evaluated true (state did not change) (12ms)
+10505ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10507ms ║║Condition #31 evaluated true (10ms)
+10509ms ║║Condition group #21 evaluated true (state did not change) (12ms)
+10521ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10523ms ║║Condition #30 evaluated true (10ms)
+10525ms ║║Condition group #22 evaluated true (state did not change) (12ms)
+10529ms ║║Cancelling statement #25’s schedules…
+10552ms ║║Executed physical command [Link To Garage Door].off() (18ms)
+10553ms ║║Executed [Link To Garage Door].off (20ms)
+10559ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+10561ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 3:08:22 PM EDT (in 1.0s)
+10572ms ║╚Execution stage complete. (207ms)
+10575ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 3:08:22 PM EDT (in 1s)
+10638ms ╚Event processed successfully (10637ms)
9/23/2017, 3:07:59 PM +920ms
+1ms ╔Received event [Link To Garage Door].switch = on with a delay of 887ms
+9979ms ║RunTime Analysis CS > 27ms > PS > 9879ms > PE > 74ms > CE
+9992ms ║Piston waited at a semaphore for 9825ms
+9995ms ║Runtime (42176 bytes) successfully initialized in 9879ms (v0.2.0e7.20170906) (9992ms)
+9996ms ║╔Execution stage started
+10021ms ║║Comparison (enum) open is (string) open = true (3ms)
+10023ms ║║Condition #14 evaluated true (15ms)
+10036ms ║║Comparison (boolean) false is (boolean) false = true (2ms)
+10038ms ║║Condition #15 evaluated true (14ms)
+10040ms ║║Condition group #5 evaluated true (state did not change) (32ms)
+10054ms ║║Comparison (enum) on is (string) on = true (3ms)
+10057ms ║║Condition #13 evaluated true (12ms)
+10058ms ║║Condition group #6 evaluated true (state did not change) (15ms)
+10062ms ║║Cancelling statement #10’s schedules…
+10072ms ║║Executed virtual command setVariable (4ms)
+10079ms ║║Executed virtual command setVariable (2ms)
+10098ms ║║Comparison (enum) open is (string) closed = false (3ms)
+10100ms ║║Condition #19 evaluated false (13ms)
+10102ms ║║Condition group #16 evaluated false (state did not change) (15ms)
+10114ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10117ms ║║Condition #33 evaluated true (9ms)
+10118ms ║║Condition group #32 evaluated true (state did not change) (12ms)
+10130ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10133ms ║║Condition #31 evaluated true (10ms)
+10134ms ║║Condition group #21 evaluated true (state did not change) (12ms)
+10146ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10148ms ║║Condition #30 evaluated true (10ms)
+10149ms ║║Condition group #22 evaluated true (state did not change) (12ms)
+10154ms ║║Cancelling statement #25’s schedules…
+10216ms ║║Executed physical command [Link To Garage Door].off() (56ms)
+10217ms ║║Executed [Link To Garage Door].off (58ms)
+10223ms ║║Executed virtual command [Link To Garage Door].wait (0ms)
+10224ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 3:08:11 PM EDT (in 1.0s)
+10235ms ║╚Execution stage complete. (240ms)
+10238ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 3:08:11 PM EDT (in 1s)
+10397ms ╚Event processed successfully (10398ms)
9/23/2017, 3:07:49 PM +834ms
+2ms ╔Received event [Link To Garage Door].switch = on with a delay of 764ms
+9341ms ║RunTime Analysis CS > 41ms > PS > 9238ms > PE > 62ms > CE
+9360ms ║Piston waited at a semaphore for 9196ms
+9363ms ║Runtime (42182 bytes) successfully initialized in 9238ms (v0.2.0e7.20170906) (9361ms)
+9365ms ║╔Execution stage started
+9390ms ║║Comparison (enum) open is (string) open = true (3ms)
+9392ms ║║Cancelling condition #14’s schedules…
+9393ms ║║Condition #14 evaluated true (17ms)
+9406ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+9409ms ║║Condition #15 evaluated true (14ms)
+9410ms ║║Cancelling condition #5’s schedules…
+9411ms ║║Condition group #5 evaluated true (state changed) (36ms)
+9425ms ║║Comparison (enum) on is (string) on = true (3ms)
+9428ms ║║Condition #13 evaluated true (11ms)
+9429ms ║║Condition group #6 evaluated true (state did not change) (14ms)
+9434ms ║║Cancelling statement #10’s schedules…
+9443ms ║║Executed virtual command setVariable (4ms)
+9451ms ║║Executed virtual command setVariable (1ms)
+9470ms ║║Comparison (enum) open is (string) closed = false (3ms)
+9472ms ║║Cancelling condition #19’s schedules…
+9474ms ║║Condition #19 evaluated false (15ms)
+9475ms ║║Condition group #16 evaluated false (state did not change) (18ms)
+9489ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+9491ms ║║Cancelling condition #33’s schedules…
+9492ms ║║Condition #33 evaluated true (11ms)
+9494ms ║║Cancelling condition #32’s schedules…
+9495ms ║║Condition group #32 evaluated true (state changed) (15ms)
+9507ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+9510ms ║║Condition #31 evaluated true (9ms)
+9511ms ║║Condition group #21 evaluated true (state did not change) (12ms)
+9524ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+9526ms ║║Condition #30 evaluated true (10ms)
+9528ms ║║Condition group #22 evaluated true (state did not change) (13ms)
+9532ms ║║Cancelling statement #25’s schedules…
+9558ms ║║Executed physical command [Link To Garage Door].off() (20ms)
+9559ms ║║Executed [Link To Garage Door].off (22ms)
+9565ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+9567ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 3:08:00 PM EDT (in 1.0s)
+9578ms ║╚Execution stage complete. (214ms)
+9581ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 3:08:00 PM EDT (in 1s)
+9601ms ╚Event processed successfully (9601ms)
Clear
Full
I have this log in a marked up PDF but could not see a place to attach it.

Your assistance would be welcomed.


#2

Your last statement starts with an IF and then carries on with a WHILE.
The IF and the WHILE are exactly the same statement.
I would try it without the IF and go straight to the WHILE.


#3

I will try that. Thanks


#4

I would do it like this I think.
WHILE
image
AND
image
image

I’m not 100% certain the else will run though as the WHILE will not be true and therefore no statements will run.
You might have to take the ELSE into a separate statement.


#5

I removed the If before the While and the result was the same. If I recall correctly I put the If in to see if that would fix the While issue during my many attempts earlier today.

I’ll try your last suggestion

Thanks for the help.


#6

Looking at this statement again
image
Then as soon as the outlet turns off, the while statement will become false and I don’t think the outlet will turn back on again.
Click on your DO and in the settings change the TCP (Task Cancellation Policy) to NEVER.


#7

I split the While into two parts. It is not yet happy.

Is there a better way to send the event log other than copy and paste. I looked in the SmartThing IDE and the log did not have anything in it.

9/23/2017, 5:53:00 PM +498ms
+0ms ╔Received event [Home].time = 1506203570567 with a delay of 9930ms
+188ms ║RunTime Analysis CS > 29ms > PS > 61ms > PE > 98ms > CE
+204ms ║Runtime (42397 bytes) successfully initialized in 61ms (v0.2.0e7.20170906) (202ms)
+206ms ║╔Execution stage started
+284ms ║║Skipped execution of physical command [Link To Garage Door].on([]) because it would make no change to the device. (4ms)
+286ms ║║Executed [Link To Garage Door].on (6ms)
+292ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+294ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 5:53:30 PM EDT (in 30.0s)
+304ms ║╚Execution stage complete. (98ms)
+306ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 5:53:30 PM EDT (in 29.99s)
+382ms ╚Event processed successfully (382ms)
9/23/2017, 5:52:50 PM +328ms
+1ms ╔Received event [Home].time = 1506203570567 with a delay of -240ms
+9279ms ║RunTime Analysis CS > 21ms > PS > 9169ms > PE > 89ms > CE
+9298ms ║Piston waited at a semaphore for 9112ms
+9301ms ║Runtime (42471 bytes) successfully initialized in 9169ms (v0.2.0e7.20170906) (9299ms)
+9302ms ║╔Execution stage started
+9304ms ║╚Execution stage complete. (1ms)
+9306ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 5:52:50 PM EDT (in 1s)
+9326ms ╚Event processed successfully (9326ms)
9/23/2017, 5:52:39 PM +453ms
+1ms ╔Received event [Link To Garage Door].switch = on with a delay of 1196ms
+9878ms ║RunTime Analysis CS > 18ms > PS > 9783ms > PE > 77ms > CE
+9939ms ║Piston waited at a semaphore for 9741ms
+9942ms ║Runtime (42478 bytes) successfully initialized in 9783ms (v0.2.0e7.20170906) (9939ms)
+9943ms ║╔Execution stage started
+9974ms ║║Comparison (enum) open is (string) open = true (3ms)
+9976ms ║║Condition #14 evaluated true (17ms)
+9989ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+9991ms ║║Condition #15 evaluated true (14ms)
+9993ms ║║Condition group #5 evaluated true (state did not change) (34ms)
+10007ms ║║Comparison (enum) on is (string) on = true (3ms)
+10009ms ║║Condition #13 evaluated true (12ms)
+10010ms ║║Condition group #6 evaluated true (state did not change) (14ms)
+10015ms ║║Cancelling statement #10’s schedules…
+10024ms ║║Executed virtual command setVariable (4ms)
+10032ms ║║Executed virtual command setVariable (1ms)
+10052ms ║║Comparison (enum) open is (string) closed = false (3ms)
+10054ms ║║Condition #19 evaluated false (15ms)
+10056ms ║║Condition group #16 evaluated false (state did not change) (16ms)
+10069ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10071ms ║║Condition #31 evaluated true (10ms)
+10080ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10083ms ║║Condition #48 evaluated true (10ms)
+10084ms ║║Condition group #21 evaluated true (state did not change) (24ms)
+10088ms ║║Cancelling statement #43’s schedules…
+10105ms ║║Executed physical command [Link To Garage Door].off() (11ms)
+10106ms ║║Executed [Link To Garage Door].off (13ms)
+10112ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+10114ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 5:52:50 PM EDT (in 1.0s)
+10123ms ║╚Execution stage complete. (180ms)
+10125ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 5:52:50 PM EDT (in 1s)
+10145ms ╚Event processed successfully (10145ms)
9/23/2017, 5:52:28 PM +455ms
+1ms ╔Received event [Link To Garage Door].switch = on with a delay of 1026ms
+10263ms ║RunTime Analysis CS > 23ms > PS > 10167ms > PE > 73ms > CE
+10275ms ║Piston waited at a semaphore for 10127ms
+10278ms ║Runtime (42484 bytes) successfully initialized in 10167ms (v0.2.0e7.20170906) (10275ms)
+10279ms ║╔Execution stage started
+10302ms ║║Comparison (enum) open is (string) open = true (3ms)
+10305ms ║║Condition #14 evaluated true (14ms)
+10317ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+10319ms ║║Condition #15 evaluated true (13ms)
+10320ms ║║Condition group #5 evaluated true (state did not change) (31ms)
+10334ms ║║Comparison (enum) on is (string) on = true (3ms)
+10336ms ║║Condition #13 evaluated true (11ms)
+10338ms ║║Condition group #6 evaluated true (state did not change) (13ms)
+10342ms ║║Cancelling statement #10’s schedules…
+10351ms ║║Executed virtual command setVariable (4ms)
+10358ms ║║Executed virtual command setVariable (2ms)
+10376ms ║║Comparison (enum) open is (string) closed = false (3ms)
+10378ms ║║Condition #19 evaluated false (13ms)
+10380ms ║║Condition group #16 evaluated false (state did not change) (15ms)
+10393ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10395ms ║║Condition #31 evaluated true (10ms)
+10403ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+10406ms ║║Condition #48 evaluated true (9ms)
+10407ms ║║Condition group #21 evaluated true (state did not change) (22ms)
+10411ms ║║Cancelling statement #43’s schedules…
+10433ms ║║Executed physical command [Link To Garage Door].off() (17ms)
+10434ms ║║Executed [Link To Garage Door].off (18ms)
+10440ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+10442ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 5:52:39 PM EDT (in 1.0s)
+10450ms ║╚Execution stage complete. (172ms)
+10452ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 5:52:39 PM EDT (in 1s)
+10471ms ╚Event processed successfully (10471ms)
9/23/2017, 5:52:26 PM +604ms
+2ms ╔Received event [Desk Chair].contact = open with a delay of 1002ms
+146ms ║RunTime Analysis CS > 21ms > PS > 59ms > PE > 65ms > CE
+159ms ║Runtime (42404 bytes) successfully initialized in 59ms (v0.2.0e7.20170906) (155ms)
+160ms ║╔Execution stage started
+183ms ║║Comparison (enum) open is (string) open = true (3ms)
+186ms ║║Cancelling condition #14’s schedules…
+187ms ║║Condition #14 evaluated true (13ms)
+199ms ║║Comparison (boolean) false is (boolean) false = true (3ms)
+202ms ║║Condition #15 evaluated true (13ms)
+203ms ║║Cancelling condition #5’s schedules…
+204ms ║║Condition group #5 evaluated true (state changed) (32ms)
+435ms ║║Comparison (enum) on is (string) on = true (216ms)
+438ms ║║Condition #13 evaluated true (229ms)
+439ms ║║Condition group #6 evaluated true (state did not change) (231ms)
+443ms ║║Cancelling statement #10’s schedules…
+453ms ║║Executed virtual command setVariable (5ms)
+462ms ║║Executed virtual command setVariable (2ms)
+480ms ║║Comparison (enum) open is (string) closed = false (3ms)
+483ms ║║Cancelling condition #19’s schedules…
+484ms ║║Condition #19 evaluated false (13ms)
+485ms ║║Condition group #16 evaluated false (state did not change) (16ms)
+498ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+501ms ║║Cancelling condition #31’s schedules…
+502ms ║║Condition #31 evaluated true (11ms)
+510ms ║║Comparison (boolean) true is (boolean) true = true (3ms)
+513ms ║║Condition #48 evaluated true (9ms)
+514ms ║║Cancelling condition #21’s schedules…
+515ms ║║Condition group #21 evaluated true (state changed) (25ms)
+520ms ║║Cancelling statement #43’s schedules…
+552ms ║║Executed physical command [Link To Garage Door].off() (29ms)
+553ms ║║Executed [Link To Garage Door].off (31ms)
+559ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+560ms ║║Waiting for 1000ms
+1590ms ║║Executed physical command [Link To Garage Door].on() (25ms)
+1591ms ║║Executed [Link To Garage Door].on (28ms)
+1600ms ║║Executed virtual command [Link To Garage Door].wait (1ms)
+1602ms ║║Requesting a wake up for Sat, Sep 23 2017 @ 5:52:58 PM EDT (in 30.0s)
+1616ms ║╚Execution stage complete. (1456ms)
+1620ms ║Setting up scheduled job for Sat, Sep 23 2017 @ 5:52:58 PM EDT (in 29.985s)
+1666ms ╚Event processed successfully (1666ms)


#8

Bob:

Are variables defined in a piston reset every time the piston is re-triggered? As such they can’t pass a flag parameter from piston to piston re-triggering events (as I have in my code)?

If this is the case is there a way to make them global so they will persist?

Thanks for your help.

“Circling ever closer” :slight_smile:

Cheers,
Ray


#9

Yes you can define global variables.
When you are editing a piston scroll down and you will see a section for global variables.
Define them there.
When you define your variable you can define an initial value. If it is left blank then whatever value it becomes will remain until it is recalculated and changes.


#10

Thanks RE: defining global variables.

For my better understanding, do local variables in a piston get lost every time the piston exits and therefore they are not usable for passing flags to later piston events, as I was using them?

Thanks again.

Cheers,
Ray


#11

Local variables will persist. They only differ from global variables in that local variables are only accessible in that specific piston.


#12

Thanks for that clarification.


#13

Hi Ray!

How did you make out with this piston? Can you share the working piston, i have need for this.

Thanks


#14

Sorry for the late response. I replied to the email version of your question but that failed to be transmitted.

Regarding the wile loop issue: I tried many things that were suggested, however, in the end, I just used a simpler method and avoided the WHILE.


#15

Thank you for the response.