Long-time lurker, first-time poster. This community has been a great resource for me for years. Finally, I have an issue that I couldn’t find an existing answer for so I humbly request assistance from the community. I’m sure this is my failure to understand some basic aspect of For Loops but I can’t figure it out.
Also, I’m sure there are simpler, more elegant ways to accomplish what this piston does: I’m certainly open to suggestions.
1) Give a description of the problem
The piston in question operates a particular irrigation valve. Lest anyone wonder how this piston is triggered, this piston is triggered by a separate piston, which handles WHEN to run. The piston in question focuses on actually operating the valve.
When triggered, the piston controlling the valve uses various local and global variables to calculate the desired run time of the irrigation system. The run time automatically adjust seasonally based on evapotranspiration data (how fast the lawn loses moisture). The piston then resets various local variables used in a For Loop that opens and closes the valve.
The For Loop is intended to “cycle and soak” the ground. In other words, the For Loop accounts for how long it takes for the ground to become oversaturated with water. If the desired run time is longer than the time it takes to oversaturate the ground, the For Loop stops at the estimated duration the ground becomes oversaturated, waits for the water to soak in, and then loops until the total time the valve has been open surpasses the desired run time.
Example: If the irrigation system oversaturates the ground at 15 minutes and the calculated run time is 40 minutes, the piston is supposed to run for 15 minutes, wait, run another 15 minutes, wait again, and then run 10 minutes to complete the final 40-minute total run time.
I’m hoping for assistance with the For Loop. I’ve noticed the For Loop is cycling more times than it’s supposed to. Upon further review, I believe that at the end of the For Loop, the piston is then returning to the top of the piston rather than staying within the For Loop. I believe this is the case because the “set variable” tasks that precede the For Loop appear to be executing with every loop rather than being executed once when the piston is first triggered. That appears to be then messing up when the For Loop stops.
A simple example is the lastRunDTG variable. I intended that to update once when the piston is first triggered. However, it appears to update with every loop.
2) What is the expected behaviour?
Once the piston enters the For Loop, I want it to stay strictly within that loop until the cycleTimeElapsed (cumulative time the valve has been open) surpasses the RT (desired run time).
3) What is happening/not happening?
It appears to me that at the end of the loop, the piston is returning to the very top of the piston rather than the top of the loop.
**4) Post a Green Snapshot of the piston![image|45x37]
5) Attach logs after turning logging level to Full
5/16/2021, 11:35:10 AM +945ms
+1ms ╔Received event [Home].time = 1621190111242 with a delay of -297ms
+93ms ║Runtime (48002 bytes) successfully initialized in 10ms (v0.3.110.20191009) (92ms)
+95ms ║╔Execution stage started
+121ms ║║Executed [Zooz MultiRelay-Relay 1].off (6ms)
+132ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (2ms)
+142ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+156ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+167ms ║║Executed virtual command setVariable (1ms)
+187ms ║╚Execution stage complete. (93ms)
+189ms ╚Event processed successfully (189ms)
5/16/2021, 11:18:03 AM +64ms
+1ms ╔Received event [Home].time = 1621189084767 with a delay of -1703ms
+64ms ║Runtime (47988 bytes) successfully initialized in 10ms (v0.3.110.20191009) (62ms)
+65ms ║╔Execution stage started
+1157ms ║║Executed [Zooz MultiRelay-Relay 1].on (1069ms)
+1170ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+1176ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (1ms)
+1177ms ║║Requesting a wake up for Sun, May 16 2021 @ 11:35:11 AM PDT (in 1027.0s)
+1181ms ║╚Execution stage complete. (1116ms)
+1182ms ║Setting up scheduled job for Sun, May 16 2021 @ 11:35:11 AM PDT (in 1026.996s)
+1190ms ╚Event processed successfully (1189ms)
5/16/2021, 10:40:33 AM +216ms
+0ms ╔Received event [Home].time = 1621186834924 with a delay of -1709ms
+100ms ║Runtime (47987 bytes) successfully initialized in 10ms (v0.3.110.20191009) (99ms)
+101ms ║╔Execution stage started
+1516ms ║║Executed [Zooz MultiRelay-Relay 1].off (1397ms)
+1526ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+1534ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+1549ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+1550ms ║║Requesting a wake up for Sun, May 16 2021 @ 11:18:04 AM PDT (in 2250.0s)
+1554ms ║╚Execution stage complete. (1453ms)
+1555ms ║Setting up scheduled job for Sun, May 16 2021 @ 11:18:04 AM PDT (in 2249.996s)
+1562ms ╚Event processed successfully (1562ms)
5/16/2021, 10:18:03 AM +938ms
+2ms ╔Received event [Lawn Sprinklers Manual Switch].switch = off with a delay of 154ms
+84ms ║Runtime (48033 bytes) successfully initialized in 11ms (v0.3.110.20191009) (82ms)
+85ms ║╔Execution stage started
+98ms ║║Executed virtual command setVariable (3ms)
+124ms ║║Executed virtual command setVariable (3ms)
+132ms ║║Executed virtual command setVariable (2ms)
+137ms ║║Executed virtual command setVariable (3ms)
+143ms ║║Executed virtual command setVariable (3ms)
+149ms ║║Executed virtual command setVariable (3ms)
+965ms ║║Executed [Zooz MultiRelay-Relay 1].on (805ms)
+978ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (4ms)
+984ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+986ms ║║Requesting a wake up for Sun, May 16 2021 @ 10:40:34 AM PDT (in 1350.0s)
+990ms ║╚Execution stage complete. (905ms)
+991ms ║Setting up scheduled job for Sun, May 16 2021 @ 10:40:34 AM PDT (in 1349.995s)
+998ms ╚Event processed successfully (998ms)
5/16/2021, 10:18:01 AM +232ms
+0ms ╔Received event [Home].time = 1621185482248 with a delay of -1016ms
+108ms ║Runtime (48009 bytes) successfully initialized in 9ms (v0.3.110.20191009) (106ms)
+109ms ║╔Execution stage started
+2123ms ║║Executed [Zooz MultiRelay-Relay 1].off (2000ms)
+2132ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+2140ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (2ms)
+2150ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+2159ms ║║Executed virtual command setVariable (1ms)
+2562ms ║║Executed [Lawn Sprinklers Manual Switch].off (389ms)
+2566ms ║╚Execution stage complete. (2457ms)
+2567ms ╚Event processed successfully (2567ms)
5/16/2021, 10:00:51 AM +775ms
+1ms ╔Received event [Home].time = 1621184429031 with a delay of 22744ms
+121ms ║Runtime (47995 bytes) successfully initialized in 13ms (v0.3.110.20191009) (119ms)
+122ms ║╔Execution stage started
+2950ms ║║Executed [Zooz MultiRelay-Relay 1].on (2803ms)
+3463ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+3470ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+3472ms ║║Requesting a wake up for Sun, May 16 2021 @ 10:18:02 AM PDT (in 1027.0s)
+3477ms ║╚Execution stage complete. (3355ms)
+3478ms ║Setting up scheduled job for Sun, May 16 2021 @ 10:18:02 AM PDT (in 1026.995s)
+3485ms ╚Event processed successfully (3485ms)
5/16/2021, 9:22:58 AM +78ms
+1ms ╔Received event [Home].time = 1621182179659 with a delay of -1581ms
+76ms ║Runtime (47993 bytes) successfully initialized in 8ms (v0.3.110.20191009) (74ms)
+77ms ║╔Execution stage started
+918ms ║║Executed [Zooz MultiRelay-Relay 1].off (826ms)
+927ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+936ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+951ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+953ms ║║Requesting a wake up for Sun, May 16 2021 @ 10:00:29 AM PDT (in 2250.0s)
+957ms ║╚Execution stage complete. (880ms)
+958ms ║Setting up scheduled job for Sun, May 16 2021 @ 10:00:29 AM PDT (in 2249.995s)
+964ms ╚Event processed successfully (964ms)
5/16/2021, 9:00:19 AM +426ms
+0ms ╔Received event [Home].execute = :c08e06cbc6f9cd4c38cae71eb7ca5dd5: with a delay of 152ms
+10121ms ║Piston waited at a semaphore for 10018ms
+10125ms ║Runtime (48091 bytes) successfully initialized in 10025ms (v0.3.110.20191009) (10123ms)
+10126ms ║╔Execution stage started
+10141ms ║║Executed virtual command setVariable (4ms)
+10170ms ║║Executed virtual command setVariable (3ms)
+10179ms ║║Executed virtual command setVariable (4ms)
+10185ms ║║Executed virtual command setVariable (3ms)
+10190ms ║║Executed virtual command setVariable (3ms)
+10195ms ║║Executed virtual command setVariable (3ms)
+10212ms ║║Executed [Zooz MultiRelay-Relay 1].on (7ms)
+10225ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+10231ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+10232ms ║║Requesting a wake up for Sun, May 16 2021 @ 9:22:59 AM PDT (in 1350.0s)
+10236ms ║╚Execution stage complete. (111ms)
+10237ms ║Setting up scheduled job for Sun, May 16 2021 @ 9:22:59 AM PDT (in 1349.996s)
+10248ms ╚Event processed successfully (10248ms)
5/16/2021, 9:00:19 AM +222ms
+1ms ╔Received event [Lawn Sprinklers Manual Switch].switch = on with a delay of 70ms
+70ms ║Runtime (48036 bytes) successfully initialized in 8ms (v0.3.110.20191009) (69ms)
+71ms ║╔Execution stage started
+83ms ║║Executed virtual command setVariable (3ms)
+108ms ║║Executed virtual command setVariable (2ms)
+114ms ║║Executed virtual command setVariable (2ms)
+119ms ║║Executed virtual command setVariable (3ms)
+124ms ║║Executed virtual command setVariable (2ms)
+128ms ║║Executed virtual command setVariable (2ms)
+1046ms ║║Executed [Zooz MultiRelay-Relay 1].on (909ms)
+1058ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].setVariable (3ms)
+1064ms ║║Executed virtual command [Zooz MultiRelay-Relay 1].wait (0ms)
+1066ms ║║Requesting a wake up for Sun, May 16 2021 @ 9:22:50 AM PDT (in 1350.0s)
+1070ms ║╚Execution stage complete. (998ms)
+1071ms ║Setting up scheduled job for Sun, May 16 2021 @ 9:22:50 AM PDT (in 1349.996s)
+1078ms ╚Event processed successfully (1077ms)
Your assistance is greatly appreciated!