Randomized Lighting - two questions re Cancel Jobs and Randomization code


#1

See attached green Piston for randomizing lights when we are on Vacation or Away from the house:

  1. When I arrive home and change Mode from Vacation to Home, the lights keep going on and off. Should this Piston cancel pending jobs when we come home and I set Mode = Home? If yes, what code do I use to determine the Mode has changed to Home and how do I cancel pending jobs?

  2. You will see multiple IF/THENs to randomize seven lights. The first of the seven lights (IF #21) seems to get executed more than the others. With the logic shown, will all seven IFs be executed about the same number of times (depends on how “random” evaluates, of course). Do ALL the IFs (21, 24, 29, 36, 41, 59, 67) get evaluated on every pass through async IF / THEN and each get a unique value of Random? If more than one of the IFs evaluate to true, do multiple jobs get scheduled? Or, if IF #21 evaluates to TRUE, do the succeeding IFs not get evaluated?

2/29/2020, 10:32:30 PM +114ms
+1ms ╔Received event [Hayden Lake].time = 1583044350496 with a delay of -382ms
+161ms ║RunTime Analysis CS > 53ms > PS > 57ms > PE > 51ms > CE
+164ms ║Runtime (53148 bytes) successfully initialized in 57ms (v0.3.110.20191009) (162ms)
+165ms ║╔Execution stage started
+184ms ║║Comparison (time) 81150291 is_before (time) 80400000 = false (6ms)
+186ms ║║Cancelling condition #4's schedules...
+187ms ║║Condition #4 evaluated false (11ms)
+188ms ║║Cancelling condition #2's schedules...
+189ms ║║Condition group #2 evaluated false (state changed) (13ms)
+202ms ║║Comparison (time) 81150305 is_between (time) 85500000 .. (time) 3600000 = false (8ms)
+203ms ║║Condition #74 evaluated false (12ms)
+204ms ║║Condition group #72 evaluated false (state did not change) (13ms)
+207ms ║║Cancelling statement #97's schedules...
+211ms ║╚Execution stage complete. (46ms)
+212ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 11:02:30 PM PST (in 1800.17s)
+219ms ╚Event processed successfully (218ms)
2/29/2020, 10:26:42 PM +105ms
+1ms ╔Received event [Hayden Lake].time = 1583044002800 with a delay of -695ms
+133ms ║RunTime Analysis CS > 25ms > PS > 46ms > PE > 61ms > CE
+136ms ║Runtime (53150 bytes) successfully initialized in 46ms (v0.3.110.20191009) (134ms)
+137ms ║╔Execution stage started
+189ms ║║Executed physical command [LR table lamp - recliner].off() (13ms)
+191ms ║║Executed virtual command [LR table lamp - recliner].toggle (17ms)
+206ms ║║Calculating (decimal) 0.21207601199029613 > (decimal) 0.6 >> (boolean) false
+212ms ║║Comparison (boolean) false is (boolean) true = false (2ms)
+215ms ║║Condition #42 evaluated false (19ms)
+217ms ║║Condition group #41 evaluated false (state did not change) (21ms)
+230ms ║║Calculating (decimal) 0.16253374156811573 > (decimal) 0.6 >> (boolean) false
+237ms ║║Comparison (boolean) false is (boolean) true = false (3ms)
+239ms ║║Condition #60 evaluated false (18ms)
+241ms ║║Condition group #59 evaluated false (state did not change) (20ms)
+254ms ║║Calculating (decimal) 0.9434372551526559 > (decimal) 0.6 >> (boolean) true
+261ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+263ms ║║Cancelling condition #68's schedules...
+265ms ║║Condition #68 evaluated true (19ms)
+266ms ║║Cancelling condition #67's schedules...
+267ms ║║Condition group #67 evaluated true (state changed) (23ms)
+270ms ║║Cancelling statement #69's schedules...
+281ms ║║Executed virtual command [BR 4 bed lamp Teri].waitRandom (1ms)
+282ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 10:48:59 PM PST (in 1336.868s)
+309ms ║╚Execution stage complete. (171ms)
+312ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 10:32:30 PM PST (in 348.08s), with 2 more jobs pending
+320ms ╚Event processed successfully (320ms)
2/29/2020, 10:20:39 PM +143ms
+0ms ╔Received event [Hayden Lake].time = 1583043640799 with a delay of -1657ms
+182ms ║RunTime Analysis CS > 65ms > PS > 63ms > PE > 54ms > CE
+185ms ║Runtime (53154 bytes) successfully initialized in 63ms (v0.3.110.20191009) (184ms)
+186ms ║╔Execution stage started
+223ms ║║Executed physical command [LR table lamp - chairs].off() (15ms)
+224ms ║║Executed virtual command [LR table lamp - chairs].toggle (20ms)
+234ms ║║Calculating (decimal) 0.8112793423744061 > (decimal) 0.6 >> (boolean) true
+240ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+242ms ║║Cancelling condition #28's schedules...
+243ms ║║Condition #28 evaluated true (16ms)
+245ms ║║Cancelling condition #24's schedules...
+246ms ║║Condition group #24 evaluated true (state changed) (18ms)
+249ms ║║Cancelling statement #25's schedules...
+259ms ║║Executed virtual command [LR table lamp - front door].waitRandom (1ms)
+260ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 10:47:34 PM PST (in 1614.666s)
+288ms ║╚Execution stage complete. (102ms)
+290ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 10:26:42 PM PST (in 363.367s), with 2 more jobs pending
+300ms ╚Event processed successfully (300ms)
2/29/2020, 10:02:30 PM +189ms
+0ms ╔Received event [Hayden Lake].time = 1583042550496 with a delay of -308ms
+458ms ║RunTime Analysis CS > 209ms > PS > 203ms > PE > 46ms > CE
+460ms ║Runtime (53156 bytes) successfully initialized in 203ms (v0.3.110.20191009) (459ms)
+461ms ║╔Execution stage started
+477ms ║║Comparison (time) 79350659 is_before (time) 80400000 = true (5ms)
+478ms ║║Time restriction check passed
+479ms ║║Condition #4 evaluated true (9ms)
+673ms ║║Comparison (time) 79350669 is_after (time) 1583026320000 = true (6ms)
+674ms ║║Time restriction check passed
+676ms ║║Condition #93 evaluated true (195ms)
+676ms ║║Condition group #91 evaluated true (state did not change) (196ms)
+677ms ║║Condition group #2 evaluated true (state did not change) (207ms)
+685ms ║║Calculating (decimal) 0.8075488683549018 > (decimal) 0.6 >> (boolean) true
+688ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+689ms ║║Condition #23 evaluated true (10ms)
+690ms ║║Condition group #21 evaluated true (state did not change) (11ms)
+692ms ║║Cancelling statement #3's schedules...
+700ms ║║Executed virtual command [LR table lamp - chairs].waitRandom (1ms)
+701ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 10:20:40 PM PST (in 1089.908s)
+706ms ║║Cancelling statement #97's schedules...
+709ms ║╚Execution stage complete. (248ms)
+710ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 10:20:40 PM PST (in 1089.9s), with 2 more jobs pending
+720ms ╚Event processed successfully (719ms)
2/29/2020, 9:59:20 PM +73ms
+1ms ╔Received event [Hayden Lake].time = 1583042360704 with a delay of -632ms
+101ms ║RunTime Analysis CS > 32ms > PS > 24ms > PE > 45ms > CE
+104ms ║Runtime (53147 bytes) successfully initialized in 24ms (v0.3.110.20191009) (102ms)
+105ms ║╔Execution stage started
+133ms ║║Executed physical command [LR table lamp - chairs].off() (9ms)
+134ms ║║Executed virtual command [LR table lamp - chairs].toggle (13ms)
+142ms ║║Calculating (decimal) 0.3301408435373101 > (decimal) 0.6 >> (boolean) false
+146ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+148ms ║║Cancelling condition #28's schedules...
+149ms ║║Condition #28 evaluated false (12ms)
+150ms ║║Cancelling condition #24's schedules...
+150ms ║║Condition group #24 evaluated false (state changed) (14ms)
+158ms ║║Calculating (decimal) 0.3168594015369691 > (decimal) 0.6 >> (boolean) false
+162ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+164ms ║║Cancelling condition #32's schedules...
+165ms ║║Condition #32 evaluated false (11ms)
+166ms ║║Cancelling condition #29's schedules...
+167ms ║║Condition group #29 evaluated false (state changed) (13ms)
+175ms ║║Calculating (decimal) 0.8082029132705655 > (decimal) 0.6 >> (boolean) true
+179ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+180ms ║║Condition #37 evaluated true (11ms)
+181ms ║║Condition group #36 evaluated true (state did not change) (12ms)
+183ms ║║Cancelling statement #38's schedules...
+191ms ║║Executed virtual command [LR table lamp - recliner].waitRandom (1ms)
+192ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 10:26:42 PM PST (in 1642.534s)
+213ms ║╚Execution stage complete. (108ms)
+215ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 10:02:30 PM PST (in 190.209s), with 1 more job pending
+225ms ╚Event processed successfully (225ms)
2/29/2020, 9:38:43 PM +56ms
+1ms ╔Received event [Hayden Lake].time = 1583041123565 with a delay of -509ms
+89ms ║RunTime Analysis CS > 16ms > PS > 24ms > PE > 49ms > CE
+92ms ║Runtime (53149 bytes) successfully initialized in 24ms (v0.3.110.20191009) (90ms)
+93ms ║╔Execution stage started
+126ms ║║Executed physical command [LR table lamp - front door].off() (7ms)
+127ms ║║Executed virtual command [LR table lamp - front door].toggle (11ms)
+137ms ║║Calculating (decimal) 0.6015662111694186 > (decimal) 0.6 >> (boolean) true
+141ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+143ms ║║Cancelling condition #32's schedules...
+143ms ║║Condition #32 evaluated true (12ms)
+145ms ║║Cancelling condition #29's schedules...
+145ms ║║Condition group #29 evaluated true (state changed) (15ms)
+148ms ║║Cancelling statement #30's schedules...
+156ms ║║Executed virtual command [LR table lamps - stairs].waitRandom (1ms)
+157ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 10:05:30 PM PST (in 1606.907s)
+164ms ║╚Execution stage complete. (71ms)
+166ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 9:59:20 PM PST (in 1237.483s), with 2 more jobs pending
+173ms ╚Event processed successfully (173ms)
2/29/2020, 9:32:30 PM +235ms
+1ms ╔Received event [Hayden Lake].time = 1583040750496 with a delay of -261ms
+139ms ║RunTime Analysis CS > 35ms > PS > 47ms > PE > 57ms > CE
+143ms ║Runtime (53150 bytes) successfully initialized in 47ms (v0.3.110.20191009) (138ms)
+144ms ║╔Execution stage started
+166ms ║║Comparison (time) 77550392 is_before (time) 80400000 = true (7ms)
+167ms ║║Time restriction check passed
+169ms ║║Condition #4 evaluated true (13ms)
+236ms ║║Comparison (time) 77550407 is_after (time) 1583026320000 = true (11ms)
+238ms ║║Time restriction check passed
+241ms ║║Condition #93 evaluated true (70ms)
+243ms ║║Condition group #91 evaluated true (state did not change) (72ms)
+245ms ║║Condition group #2 evaluated true (state did not change) (88ms)
+258ms ║║Calculating (decimal) 0.7098979535644087 > (decimal) 0.6 >> (boolean) true
+264ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+267ms ║║Condition #23 evaluated true (19ms)
+269ms ║║Condition group #21 evaluated true (state did not change) (22ms)
+273ms ║║Cancelling statement #3's schedules...
+287ms ║║Executed virtual command [LR table lamp - chairs].waitRandom (1ms)
+289ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 9:59:20 PM PST (in 1610.179s)
+298ms ║║Cancelling statement #97's schedules...
+304ms ║╚Execution stage complete. (160ms)
+307ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 9:38:43 PM PST (in 373.024s), with 2 more jobs pending
+316ms ╚Event processed successfully (316ms)
2/29/2020, 9:27:07 PM +207ms
+0ms ╔Received event [Hayden Lake].time = 1583040427690 with a delay of -484ms
+123ms ║RunTime Analysis CS > 35ms > PS > 35ms > PE > 54ms > CE
+126ms ║Runtime (53153 bytes) successfully initialized in 35ms (v0.3.110.20191009) (125ms)
+127ms ║╔Execution stage started
+179ms ║║Executed physical command [LR table lamp - chairs].off() (20ms)
+180ms ║║Executed virtual command [LR table lamp - chairs].toggle (25ms)
+189ms ║║Calculating (decimal) 0.6673984712390288 > (decimal) 0.6 >> (boolean) true
+193ms ║║Comparison (boolean) true is (boolean) true = true (2ms)
+195ms ║║Cancelling condition #28's schedules...
+196ms ║║Condition #28 evaluated true (12ms)
+197ms ║║Cancelling condition #24's schedules...
+198ms ║║Condition group #24 evaluated true (state changed) (14ms)
+200ms ║║Cancelling statement #25's schedules...
+208ms ║║Executed virtual command [LR table lamp - front door].waitRandom (0ms)
+209ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 9:38:43 PM PST (in 696.148s)
+234ms ║╚Execution stage complete. (107ms)
+236ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 9:32:30 PM PST (in 323.054s), with 1 more job pending
+243ms ╚Event processed successfully (243ms)
2/29/2020, 9:02:43 PM +461ms
+0ms ╔Received event [Hayden Lake].time = 1583038950496 with a delay of 12964ms
+650ms ║RunTime Analysis CS > 319ms > PS > 272ms > PE > 59ms > CE
+653ms ║Runtime (53160 bytes) successfully initialized in 272ms (v0.3.110.20191009) (652ms)
+654ms ║╔Execution stage started
+673ms ║║Comparison (time) 75764126 is_before (time) 80400000 = true (5ms)
+674ms ║║Time restriction check passed
+676ms ║║Condition #4 evaluated true (10ms)
+949ms ║║Comparison (time) 75764139 is_after (time) 1583026320000 = true (7ms)
+951ms ║║Time restriction check passed
+953ms ║║Condition #93 evaluated true (275ms)
+954ms ║║Condition group #91 evaluated true (state did not change) (277ms)
+955ms ║║Condition group #2 evaluated true (state did not change) (290ms)
+965ms ║║Calculating (decimal) 0.891487504203996 > (decimal) 0.6 >> (boolean) true
+969ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+970ms ║║Cancelling condition #23's schedules...
+971ms ║║Condition #23 evaluated true (13ms)
+972ms ║║Cancelling condition #21's schedules...
+973ms ║║Condition group #21 evaluated true (state changed) (16ms)
+976ms ║║Cancelling statement #3's schedules...
+984ms ║║Executed virtual command [LR table lamp - chairs].waitRandom (0ms)
+991ms ║║Requesting a wake up for Sat, Feb 29 2020 @ 9:27:07 PM PST (in 1463.237s)
+996ms ║║Cancelling statement #97's schedules...
+999ms ║╚Execution stage complete. (345ms)
+1001ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 9:27:07 PM PST (in 1463.229s), with 1 more job pending
+1007ms ╚Event processed successfully (1007ms)
2/29/2020, 8:48:08 PM +101ms
+0ms ╔Received event [Hayden Lake].time = 1583038089251 with a delay of -1151ms
+133ms ║RunTime Analysis CS > 41ms > PS > 45ms > PE > 47ms > CE
+137ms ║Runtime (53157 bytes) successfully initialized in 45ms (v0.3.110.20191009) (135ms)
+138ms ║╔Execution stage started
+183ms ║║Executed physical command [LR table lamp - recliner].on() (13ms)
+184ms ║║Executed virtual command [LR table lamp - recliner].toggle (17ms)
+193ms ║║Calculating (decimal) 0.40657306996344966 > (decimal) 0.6 >> (boolean) false
+196ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+198ms ║║Condition #42 evaluated false (11ms)
+199ms ║║Condition group #41 evaluated false (state did not change) (11ms)
+207ms ║║Calculating (decimal) 0.49749139272904463 > (decimal) 0.6 >> (boolean) false
+210ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+212ms ║║Condition #60 evaluated false (11ms)
+213ms ║║Condition group #59 evaluated false (state did not change) (11ms)
+221ms ║║Calculating (decimal) 0.3327220508592985 > (decimal) 0.6 >> (boolean) false
+225ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+226ms ║║Condition #68 evaluated false (11ms)
+227ms ║║Condition group #67 evaluated false (state did not change) (12ms)
+230ms ║╚Execution stage complete. (92ms)
+232ms ║Setting up scheduled job for Sat, Feb 29 2020 @ 9:02:30 PM PST (in 862.164s)
+240ms ╚Event processed successfully (240ms)

#2

Quick answer:

I would change your “Only When” into an IF…


#3

My understanding is that the ‘only when’ at the start of your piston restricts whether the ‘every 30 minutes’ cycle gets started when the piston is resumed. I don’t think it gets reassessed. It won’t apply to what it going on inside the ‘every’ block.

There is a command for cancelling scheduled tasks. I don’t know if it will stop the ‘every’ timer.

I’m not sure what the ‘async’ on the ‘if’ is acheiving but I’d imagine it is harmless. It looks like all those 'if’s should run in sequence every time. I guess a lot depends on how the random numbers work and how the sequence start point is randomised.


#4

WC – stupid question, but I cannot find a simple way to do that. I struggle with this all the time in webCoRE.


#5

There is no such thing as a stupid question…

Instead of the piston starting off like this:

ONLY WHEN
    Location mode is any of Vacation or Home
Every 30 minutes
    do Stuff
END EVERY

My recommendation would be something like this:

Every 30 minutes
do
    IF Location mode is any of Vacation or Home
        Then do Stuff
    END IF
END EVERY

With this second variation, the block will cancel out if Location is no longer Vacation or Home


#6

Thanks. My question was more about the mechanics of using the webCoRE environment for programming. We obviously cannot write code (for understandable reasons). I have a very hard time in the webCoRE environment modifying code to make the changes you suggested. I click on some lines and nothing happens. I find a statement farther down in the block can make changes. The drag and drop is very iffy and has a tendency to mess things up. You cannot copy/paste blocks of code.

How do you maintain code and make changes such as the one you suggest?


#7

Oh, we can definitely do this!!

Here is my tips for moving/copying/pasting code.
(It works like a champ if you drop in the right spot)

If you need to copy in the same piston, hold CTRL while dragging. If you want to copy a block of code to another piston, then the link above goes into more detail.


#8

My apologies.
The drag & drop method cannot delete “Only When”, nor can it create a new “IF” block from nothing.

(Creation & deletion must be done manually. Let us know if you need help with this)

but… the good news is, once your new IF block is created, you can drag and drop it to the right spot in the code. Then, you can (carefully) drag the old code into the new structure. (Working on a large monitor helps with this)

This saves you from retyping it all out again.


Edit:

This conversation inspired me to add new tips to the Wiki