Help, I can't stay in a while loop


#1

1) Give a description of the problem
I’m trying to create a piston that will flash a RGB smart bulb red if any of my doors are open more than 5 seconds(just for testing purposes, will make longer once I get this sorted out). I try and store the state of the bulb prior to this starting, so the bulb can be returned to that same state after all the doors are closed. What seems to happen to me is that it just runs all the statements in the piston over and over again until all the doors are shut.

2) What is the expected behaviour?
Once any door has been open for more than 5 seconds, the bulb will start flashing red. After all the doors have been closed, the bulb should return to its previous state.

3) What is happening/not happening?
Bulb is alternating between red and green(its previous state)

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
|+1ms|╔Received event [My Home].time = 1559403225720 with a delay of -1427ms|
| — | — |
|+226ms|║RunTime Analysis CS > 49ms > PS > 120ms > PE > 58ms > CE|
|+229ms|║Runtime (41580 bytes) successfully initialized in 120ms (v0.3.108.20180906) (227ms)|
|+230ms|║╔Execution stage started|
|+231ms|║╚Execution stage complete. (1ms)|
|+233ms|╚Event processed successfully (233ms)|
|6/1/2019, 11:33:41 AM +857ms|
|+2ms|╔Received event [Office Mutipurpose Sensor].contact = closed with a delay of 115ms|
|+171ms|║RunTime Analysis CS > 26ms > PS > 91ms > PE > 54ms > CE|
|+174ms|║Runtime (41589 bytes) successfully initialized in 91ms (v0.3.108.20180906) (170ms)|
|+175ms|║╔Execution stage started|
|+181ms|║║Cancelling statement #11’s schedules…|
|+208ms|║║Executed virtual command [Orb].saveStateLocally (21ms)|
|+235ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+238ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+241ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+244ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+248ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+251ms|║║Cancelling any timed trigger schedules for device :4a90bbf43c48a56a965ac34bbdf67104: for condition 2|
|+252ms|║║Cancelling statement #2’s schedules…|
|+253ms|║║Cancelling any timed trigger schedules for device :6661934f4bf52b406f78048e2cf458e2: for condition 2|
|+254ms|║║Cancelling statement #2’s schedules…|
|+256ms|║║Cancelling any timed trigger schedules for device :355671a2069fa288e7af23bbe3f94ca7: for condition 2|
|+257ms|║║Cancelling statement #2’s schedules…|
|+258ms|║║Cancelling any timed trigger schedules for device :505e3fb005360f91021ab5c326f4f65a: for condition 2|
|+259ms|║║Cancelling statement #2’s schedules…|
|+260ms|║║Cancelling any timed trigger schedules for device :7b9cd5316dbe622bc2b444fbd951ae88: for condition 2|
|+261ms|║║Cancelling statement #2’s schedules…|
|+262ms|║║Condition #2 evaluated false (51ms)|
|+263ms|║║Condition group #1 evaluated false (state did not change) (52ms)|
|+267ms|║║Cancelling statement #13’s schedules…|
|+284ms|║║Restoring attribute ‘color’ to value ‘’ using command setColor()|
|+298ms|║║Executed physical command [Orb].setColor([]) (13ms)|
|+312ms|║║Restoring attribute ‘colorTemperature’ to value ‘2703’ using command setColorTemperature(2703)|
|+321ms|║║Executed physical command [Orb].setColorTemperature([2703]) (8ms)|
|+336ms|║║Restoring attribute ‘hue’ to value ‘0.0’ using command setHue(0.0)|
|+344ms|║║Executed physical command [Orb].setHue([0.0]) (7ms)|
|+357ms|║║Restoring attribute ‘level’ to value ‘5’ using command setLevel(5)|
|+367ms|║║Skipped execution of physical command [Orb].setLevel([5]) because it would make no change to the device. (8ms)|
|+380ms|║║Restoring attribute ‘saturation’ to value ‘100’ using command setSaturation(100)|
|+389ms|║║Executed physical command [Orb].setSaturation([100]) (8ms)|
|+393ms|║║Restoring attribute ‘switch’ to value ‘on’ using command on()|
|+398ms|║║Skipped execution of physical command [Orb].on([]) because it would make no change to the device. (3ms)|
|+399ms|║║Executed virtual command [Orb].loadStateLocally (128ms)|
|+402ms|║╚Execution stage complete. (228ms)|
|+403ms|╚Event processed successfully (403ms)|
|6/1/2019, 11:33:38 AM +205ms|
|+1ms|╔Received event [My Home].time = 1559403219735 with a delay of -1531ms|
|+192ms|║RunTime Analysis CS > 29ms > PS > 93ms > PE > 70ms > CE|
|+195ms|║Runtime (41577 bytes) successfully initialized in 93ms (v0.3.108.20180906) (193ms)|
|+197ms|║╔Execution stage started|
|+210ms|║║Cancelling condition #2’s schedules…|
|+212ms|║║Condition #2 evaluated true (2ms)|
|+225ms|║║Comparison (enum) off is_not (string) on = true (4ms)|
|+229ms|║║Condition #3 evaluated true (15ms)|
|+231ms|║║Cancelling condition #1’s schedules…|
|+232ms|║║Condition group #1 evaluated true (state changed) (23ms)|
|+236ms|║║Cancelling statement #4’s schedules…|
|+254ms|║║Executed physical command [Orb].setColor([[hex: #FF0000, hue:0, saturation:100, level:50]]) (9ms)|
|+256ms|║║Executed [Orb].setColor (12ms)|
|+273ms|║║Executed physical command [Orb].setLevel([100]) (10ms)|
|+275ms|║║Executed [Orb].setLevel (13ms)|
|+287ms|║║Executed physical command [Orb].setSaturation([100]) (6ms)|
|+289ms|║║Executed [Orb].setSaturation (9ms)|
|+314ms|║║Executed physical command [Orb].off() (7ms)|
|+325ms|║║Executed physical command [Orb].on([delay: 1000]) (9ms)|
|+333ms|║║Executed physical command [Orb].on([delay: 2099]) (7ms)|
|+335ms|║║Executed virtual command [Orb].flash (34ms)|
|+336ms|║║Waiting for 2100ms|
|+2472ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2478ms|║║Comparison (enum) closed stays (string) open = false (4ms)|
|+2482ms|║║Comparison (enum) closed stays (string) open = false (3ms)|
|+2487ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2491ms|║║Comparison (enum) open stays (string) open = true (3ms)|
|+2495ms|║║Cancelling any timed trigger schedules for device :4a90bbf43c48a56a965ac34bbdf67104: for condition 2|
|+2496ms|║║Cancelling statement #2’s schedules…|
|+2498ms|║║Cancelling any timed trigger schedules for device :6661934f4bf52b406f78048e2cf458e2: for condition 2|
|+2499ms|║║Cancelling statement #2’s schedules…|
|+2500ms|║║Cancelling any timed trigger schedules for device :355671a2069fa288e7af23bbe3f94ca7: for condition 2|
|+2502ms|║║Cancelling statement #2’s schedules…|
|+2503ms|║║Cancelling any timed trigger schedules for device :505e3fb005360f91021ab5c326f4f65a: for condition 2|
|+2505ms|║║Cancelling statement #2’s schedules…|
|+2514ms|║║Adding a timed trigger schedule for device :7b9cd5316dbe622bc2b444fbd951ae88: for condition 2|
|+2518ms|║║Cancelling condition #2’s schedules…|
|+2519ms|║║Condition #2 evaluated false (80ms)|
|+2520ms|║║Cancelling condition #1’s schedules…|
|+2522ms|║║Condition group #1 evaluated false (state changed) (82ms)|
|+2526ms|║║Cancelling statement #13’s schedules…|
|+2548ms|║║Restoring attribute ‘color’ to value ‘’ using command setColor()|
|+2556ms|║║Executed physical command [Orb].setColor([]) (6ms)|
|+2574ms|║║Restoring attribute ‘colorTemperature’ to value ‘2703’ using command setColorTemperature(2703)|
|+2582ms|║║Executed physical command [Orb].setColorTemperature([2703]) (6ms)|
|+2600ms|║║Restoring attribute ‘hue’ to value ‘0.0’ using command setHue(0.0)|
|+2608ms|║║Executed physical command [Orb].setHue([0.0]) (7ms)|
|+2625ms|║║Restoring attribute ‘level’ to value ‘34’ using command setLevel(34)|
|+2636ms|║║Executed physical command [Orb].setLevel([34]) (10ms)|
|+2654ms|║║Restoring attribute ‘saturation’ to value ‘100’ using command setSaturation(100)|
|+2661ms|║║Executed physical command [Orb].setSaturation([100]) (5ms)|
|+2666ms|║║Restoring attribute ‘switch’ to value ‘on’ using command on()|
|+2680ms|║║Executed physical command [Orb].on() (11ms)|
|+2681ms|║║Executed virtual command [Orb].loadStateLocally (150ms)|
|+2684ms|║╚Execution stage complete. (2488ms)|
|+2687ms|║Setting up scheduled job for Sat, Jun 1 2019 @ 11:33:45 AM EDT (in 4.829s)|
|+2696ms|╚Event processed successfully (2695ms)|
|6/1/2019, 11:33:32 AM +272ms|
|+1ms|╔Received event [My Home].time = 1559403213558 with a delay of -1286ms|
|+154ms|║RunTime Analysis CS > 19ms > PS > 80ms > PE > 55ms > CE|
|+157ms|║Runtime (41577 bytes) successfully initialized in 80ms (v0.3.108.20180906) (155ms)|
|+158ms|║╔Execution stage started|
|+169ms|║║Cancelling condition #2’s schedules…|
|+171ms|║║Condition #2 evaluated true (1ms)|
|+180ms|║║Comparison (enum) off is_not (string) on = true (2ms)|
|+182ms|║║Condition #3 evaluated true (10ms)|
|+184ms|║║Cancelling condition #1’s schedules…|
|+185ms|║║Condition group #1 evaluated true (state changed) (17ms)|
|+188ms|║║Cancelling statement #4’s schedules…|
|+201ms|║║Executed physical command [Orb].setColor([[hex: #FF0000, hue:0, saturation:100, level:50]]) (8ms)|
|+202ms|║║Executed [Orb].setColor (10ms)|
|+216ms|║║Executed physical command [Orb].setLevel([100]) (8ms)|
|+217ms|║║Executed [Orb].setLevel (10ms)|
|+227ms|║║Executed physical command [Orb].setSaturation([100]) (6ms)|
|+228ms|║║Executed [Orb].setSaturation (7ms)|
|+246ms|║║Executed physical command [Orb].off() (5ms)|
|+287ms|║║Executed physical command [Orb].on([delay: 1000]) (40ms)|
|+296ms|║║Executed physical command [Orb].on([delay: 2099]) (8ms)|
|+298ms|║║Executed virtual command [Orb].flash (61ms)|
|+299ms|║║Waiting for 2100ms|
|+2431ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2435ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2438ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2442ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+2445ms|║║Comparison (enum) open stays (string) open = true (2ms)|
|+2449ms|║║Cancelling any timed trigger schedules for device :4a90bbf43c48a56a965ac34bbdf67104: for condition 2|
|+2450ms|║║Cancelling statement #2’s schedules…|
|+2451ms|║║Cancelling any timed trigger schedules for device :6661934f4bf52b406f78048e2cf458e2: for condition 2|
|+2452ms|║║Cancelling statement #2’s schedules…|
|+2454ms|║║Cancelling any timed trigger schedules for device :355671a2069fa288e7af23bbe3f94ca7: for condition 2|
|+2455ms|║║Cancelling statement #2’s schedules…|
|+2456ms|║║Cancelling any timed trigger schedules for device :505e3fb005360f91021ab5c326f4f65a: for condition 2|
|+2458ms|║║Cancelling statement #2’s schedules…|
|+2462ms|║║Adding a timed trigger schedule for device :7b9cd5316dbe622bc2b444fbd951ae88: for condition 2|
|+2465ms|║║Cancelling condition #2’s schedules…|
|+2466ms|║║Condition #2 evaluated false (64ms)|
|+2468ms|║║Cancelling condition #1’s schedules…|
|+2469ms|║║Condition group #1 evaluated false (state changed) (68ms)|
|+2472ms|║║Cancelling statement #13’s schedules…|
|+2492ms|║║Restoring attribute ‘color’ to value ‘’ using command setColor()|
|+2499ms|║║Executed physical command [Orb].setColor([]) (6ms)|
|+2514ms|║║Restoring attribute ‘colorTemperature’ to value ‘2703’ using command setColorTemperature(2703)|
|+2521ms|║║Executed physical command [Orb].setColorTemperature([2703]) (6ms)|
|+2536ms|║║Restoring attribute ‘hue’ to value ‘0.0’ using command setHue(0.0)|
|+2543ms|║║Executed physical command [Orb].setHue([0.0]) (6ms)|
|+2558ms|║║Restoring attribute ‘level’ to value ‘34’ using command setLevel(34)|
|+2571ms|║║Executed physical command [Orb].setLevel([34]) (12ms)|
|+2586ms|║║Restoring attribute ‘saturation’ to value ‘100’ using command setSaturation(100)|
|+2592ms|║║Executed physical command [Orb].setSaturation([100]) (4ms)|
|+2596ms|║║Restoring attribute ‘switch’ to value ‘on’ using command on()|
|+2609ms|║║Executed physical command [Orb].on() (11ms)|
|+2610ms|║║Executed virtual command [Orb].loadStateLocally (132ms)|
|+2613ms|║╚Execution stage complete. (2455ms)|
|+2615ms|║Setting up scheduled job for Sat, Jun 1 2019 @ 11:33:39 AM EDT (in 4.849s)|
|+2624ms|╚Event processed successfully (2624ms)|
|6/1/2019, 11:33:28 AM +265ms|
|+2ms|╔Received event [Office Mutipurpose Sensor].contact = open with a delay of 168ms|
|+200ms|║RunTime Analysis CS > 23ms > PS > 111ms > PE > 65ms > CE|
|+203ms|║Runtime (41590 bytes) successfully initialized in 111ms (v0.3.108.20180906) (199ms)|
|+204ms|║╔Execution stage started|
|+210ms|║║Cancelling statement #11’s schedules…|
|+236ms|║║Executed virtual command [Orb].saveStateLocally (20ms)|
|+267ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+271ms|║║Comparison (enum) closed stays (string) open = false (1ms)|
|+274ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+277ms|║║Comparison (enum) closed stays (string) open = false (2ms)|
|+280ms|║║Comparison (enum) open stays (string) open = true (2ms)|
|+284ms|║║Cancelling any timed trigger schedules for device :4a90bbf43c48a56a965ac34bbdf67104: for condition 2|
|+285ms|║║Cancelling statement #2’s schedules…|
|+286ms|║║Cancelling any timed trigger schedules for device :6661934f4bf52b406f78048e2cf458e2: for condition 2|
|+287ms|║║Cancelling statement #2’s schedules…|
|+288ms|║║Cancelling any timed trigger schedules for device :355671a2069fa288e7af23bbe3f94ca7: for condition 2|
|+290ms|║║Cancelling statement #2’s schedules…|
|+291ms|║║Cancelling any timed trigger schedules for device :505e3fb005360f91021ab5c326f4f65a: for condition 2|
|+292ms|║║Cancelling statement #2’s schedules…|
|+293ms|║║Adding a timed trigger schedule for device :7b9cd5316dbe622bc2b444fbd951ae88: for condition 2|
|+296ms|║║Condition #2 evaluated false (55ms)|
|+297ms|║║Condition group #1 evaluated false (state did not change) (57ms)|
|+300ms|║║Cancelling statement #13’s schedules…|
|+318ms|║║Restoring attribute ‘color’ to value ‘’ using command setColor()|
|+331ms|║║Executed physical command [Orb].setColor([]) (11ms)|
|+344ms|║║Restoring attribute ‘colorTemperature’ to value ‘2703’ using command setColorTemperature(2703)|
|+355ms|║║Executed physical command [Orb].setColorTemperature([2703]) (10ms)|
|+370ms|║║Restoring attribute ‘hue’ to value ‘0.0’ using command setHue(0.0)|
|+380ms|║║Executed physical command [Orb].setHue([0.0]) (8ms)|
|+393ms|║║Restoring attribute ‘level’ to value ‘34’ using command setLevel(34)|
|+401ms|║║Skipped execution of physical command [Orb].setLevel([34]) because it would make no change to the device. (7ms)|
|+415ms|║║Restoring attribute ‘saturation’ to value ‘100’ using command setSaturation(100)|
|+425ms|║║Executed physical command [Orb].setSaturation([100]) (9ms)|
|+429ms|║║Restoring attribute ‘switch’ to value ‘on’ using command on()|
|+434ms|║║Skipped execution of physical command [Orb].on([]) because it would make no change to the device. (4ms)|
|+435ms|║║Executed virtual command [Orb].loadStateLocally (131ms)|
|+438ms|║╚Execution stage complete. (235ms)|
|+440ms|║Setting up scheduled job for Sat, Jun 1 2019 @ 11:33:33 AM EDT (in 4.854s)|
|+450ms|╚Event processed successfully (450ms)|

After getting this working as, I do intended to modify it abit more and make the bulb blink a certain color based on which door is open.

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Two observations:

(1) I would be tempted to enclose your restore command inside an IF.
(IE: IF All of Sensor 1, 2 & 3’s contact are closed, Then Restore)

(2) When restoring color, I usually code it by hand instead of using the “Restore” command… But the important thing is to only restore Hue, Saturation and Level. For some reason, ColorTemp does not match with HSL… HSL does not match with Color… and Color does not match with ColorTemp.

In other words, when restoring, only use one of the three groups I have listed. My preference is using HSL.


#3

I’ve only had luck with the Capture/Restore of the ‘level’ and ‘switch’. If I add anything else, it doesn’t always work right.

I just add code for any other attribute.