Multiple Sensor(s) Open Reminder Until Closed With Incremental Counter Not Working


#1

1) Give a description of the problem
I want my piston to repeat a sensor open reminder until closed for multiple sensors and also have an incremental counter for an SMS notification in the form of minutes or hours. Currently I’m having problems with 1) the piston running simultaneously for multiple sensors and 2) the counter not incrementing properly.

2) What is the expected behaviour?
I would like each of the sensors in my list to be able to keep track of

3) What is happening/not happening?
If a sensor is opened then another newer sensor is opened the previous one in the piston no longer runs. I have tried a for each statement with no improvement. The counter is not incrementing like it should by adding a number (e.g.; 1 minute) in the do while loop.

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

5) Attach logs after turning logging level to Full
3/27/2020, 9:29:11 AM +179ms
+1ms ╔Received event [Home].time = 1585315752489 with a delay of -1310ms
+115ms ║RunTime Analysis CS > 36ms > PS > 46ms > PE > 33ms > CE
+118ms ║Runtime (42916 bytes) successfully initialized in 46ms (v0.3.110.20191009) (115ms)
+119ms ║╔Execution stage started
+138ms ║║Cancelling statement #15’s schedules…
+145ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+149ms ║║Executed virtual command [Kitchen Window].setVariable (1ms)
+156ms ║║Calculating (string) Kitchen Window + (string) stayed open for >> (string) Kitchen Window stayed open for
+159ms ║║Calculating (string) Kitchen Window stayed open for + (string) 1 >> (string) Kitchen Window stayed open for 1
+161ms ║║Calculating (string) Kitchen Window stayed open for 1 + (string) minute(s) >> (string) Kitchen Window stayed open for 1 minute(s)
+241ms ║║Executed virtual command [Kitchen Window].sendSMSNotification (74ms)
+249ms ║║Comparison (enum) open is (string) open = true (2ms)
+251ms ║║Condition #14 evaluated true (7ms)
+252ms ║║Condition group #13 evaluated true (state did not change) (9ms)
+254ms ║║Cancelling statement #16’s schedules…
+258ms ║║Executed virtual command [Kitchen Window].wait (1ms)
+259ms ║║Requesting a wake up for Fri, Mar 27 2020 @ 9:30:11 AM EDT (in 60.0s)
+264ms ║╚Execution stage complete. (146ms)
+266ms ║Setting up scheduled job for Fri, Mar 27 2020 @ 9:30:11 AM EDT (in 59.995s)
+300ms ╚Event processed successfully (300ms)
3/27/2020, 9:28:12 AM +148ms
+1ms ╔Received event [Home].time = 1585315693490 with a delay of -1342ms
+101ms ║RunTime Analysis CS > 25ms > PS > 43ms > PE > 33ms > CE
+105ms ║Runtime (42916 bytes) successfully initialized in 43ms (v0.3.110.20191009) (103ms)
+107ms ║╔Execution stage started
+131ms ║║Cancelling statement #15’s schedules…
+143ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+148ms ║║Executed virtual command [Kitchen Window].setVariable (1ms)
+158ms ║║Calculating (string) Kitchen Window + (string) stayed open for >> (string) Kitchen Window stayed open for
+162ms ║║Calculating (string) Kitchen Window stayed open for + (string) 1 >> (string) Kitchen Window stayed open for 1
+165ms ║║Calculating (string) Kitchen Window stayed open for 1 + (string) minute(s) >> (string) Kitchen Window stayed open for 1 minute(s)
+305ms ║║Executed virtual command [Kitchen Window].sendSMSNotification (134ms)
+321ms ║║Comparison (enum) open is (string) open = true (3ms)
+324ms ║║Condition #14 evaluated true (15ms)
+325ms ║║Condition group #13 evaluated true (state did not change) (18ms)
+330ms ║║Cancelling statement #16’s schedules…
+337ms ║║Executed virtual command [Kitchen Window].wait (1ms)
+340ms ║║Requesting a wake up for Fri, Mar 27 2020 @ 9:29:12 AM EDT (in 60.0s)
+348ms ║╚Execution stage complete. (242ms)
+350ms ║Setting up scheduled job for Fri, Mar 27 2020 @ 9:29:12 AM EDT (in 59.992s)
+368ms ╚Event processed successfully (368ms)
3/27/2020, 9:27:13 AM +289ms
+0ms ╔Received event [Home].time = 1585315634171 with a delay of -883ms
+120ms ║RunTime Analysis CS > 32ms > PS > 57ms > PE > 32ms > CE
+122ms ║Runtime (42915 bytes) successfully initialized in 57ms (v0.3.110.20191009) (121ms)
+123ms ║╔Execution stage started
+144ms ║║Cancelling statement #15’s schedules…
+152ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+157ms ║║Executed virtual command [Kitchen Window].setVariable (1ms)
+164ms ║║Calculating (string) Kitchen Window + (string) stayed open for >> (string) Kitchen Window stayed open for
+167ms ║║Calculating (string) Kitchen Window stayed open for + (string) 1 >> (string) Kitchen Window stayed open for 1
+170ms ║║Calculating (string) Kitchen Window stayed open for 1 + (string) minute(s) >> (string) Kitchen Window stayed open for 1 minute(s)
+183ms ║║Executed virtual command [Kitchen Window].sendSMSNotification (8ms)
+191ms ║║Comparison (enum) open is (string) open = true (1ms)
+192ms ║║Condition #14 evaluated true (7ms)
+193ms ║║Condition group #13 evaluated true (state did not change) (9ms)
+195ms ║║Cancelling statement #16’s schedules…
+199ms ║║Executed virtual command [Kitchen Window].wait (1ms)
+201ms ║║Requesting a wake up for Fri, Mar 27 2020 @ 9:28:13 AM EDT (in 60.0s)
+207ms ║╚Execution stage complete. (84ms)
+208ms ║Setting up scheduled job for Fri, Mar 27 2020 @ 9:28:13 AM EDT (in 59.993s)
+217ms ╚Event processed successfully (218ms)
3/27/2020, 9:26:13 AM +990ms
+2ms ╔Received event [Kitchen Window].contact = open with a delay of 131ms
+91ms ║RunTime Analysis CS > 21ms > PS > 38ms > PE > 32ms > CE
+93ms ║Runtime (42919 bytes) successfully initialized in 38ms (v0.3.110.20191009) (91ms)
+94ms ║╔Execution stage started
+143ms ║║Comparison (enum) closed is (string) open = false (2ms)
+145ms ║║Comparison (enum) closed is (string) open = false (1ms)
+147ms ║║Comparison (enum) closed is (string) open = false (1ms)
+149ms ║║Comparison (enum) closed is (string) open = false (1ms)
+150ms ║║Comparison (enum) closed is (string) open = false (1ms)
+152ms ║║Comparison (enum) open is (string) open = true (1ms)
+155ms ║║Condition #11 evaluated true (57ms)
+156ms ║║Condition group #10 evaluated true (state did not change) (58ms)
+170ms ║║Comparison (enum) open is (string) open = true (1ms)
+171ms ║║Condition #14 evaluated true (5ms)
+172ms ║║Condition group #13 evaluated true (state did not change) (7ms)
+174ms ║║Cancelling statement #16’s schedules…
+179ms ║║Executed virtual command [Kitchen Window].wait (1ms)
+180ms ║║Requesting a wake up for Fri, Mar 27 2020 @ 9:27:14 AM EDT (in 60.0s)
+185ms ║╚Execution stage complete. (91ms)
+186ms ║Setting up scheduled job for Fri, Mar 27 2020 @ 9:27:14 AM EDT (in 59.995s)
+196ms ╚Event processed successfully (196ms)
3/27/2020, 9:25:52 AM +568ms
+1ms ╔Received event [Office Window].contact = open with a delay of 159ms
+95ms ║RunTime Analysis CS > 21ms > PS > 38ms > PE > 37ms > CE
+98ms ║Runtime (42927 bytes) successfully initialized in 38ms (v0.3.110.20191009) (97ms)
+99ms ║╔Execution stage started
+148ms ║║Comparison (enum) closed is (string) open = false (1ms)
+150ms ║║Comparison (enum) closed is (string) open = false (1ms)
+153ms ║║Comparison (enum) closed is (string) open = false (1ms)
+155ms ║║Comparison (enum) closed is (string) open = false (1ms)
+157ms ║║Comparison (enum) closed is (string) open = false (2ms)
+159ms ║║Comparison (enum) closed is (string) open = false (1ms)
+161ms ║║Comparison (enum) closed is (string) open = false (1ms)
+163ms ║║Comparison (enum) closed is (string) open = false (1ms)
+165ms ║║Comparison (enum) open is (string) open = true (1ms)
+168ms ║║Cancelling condition #11’s schedules…
+169ms ║║Condition #11 evaluated true (66ms)
+170ms ║║Cancelling condition #10’s schedules…
+171ms ║║Condition group #10 evaluated true (state changed) (68ms)
+186ms ║║Comparison (enum) open is (string) open = true (1ms)
+187ms ║║Cancelling condition #14’s schedules…
+188ms ║║Condition #14 evaluated true (7ms)
+189ms ║║Cancelling condition #13’s schedules…
+190ms ║║Condition group #13 evaluated true (state changed) (9ms)
+192ms ║║Cancelling statement #16’s schedules…
+197ms ║║Executed virtual command [Office Window].wait (0ms)
+199ms ║║Requesting a wake up for Fri, Mar 27 2020 @ 9:26:52 AM EDT (in 60.0s)
+204ms ║╚Execution stage complete. (105ms)
+205ms ║Setting up scheduled job for Fri, Mar 27 2020 @ 9:26:52 AM EDT (in 59.994s)
+213ms ╚Event processed successfully (214ms)
3/27/2020, 9:25:48 AM +939ms
+1ms ╔Received event [Office Window].contact = closed with a delay of 121ms
+111ms ║RunTime Analysis CS > 21ms > PS > 38ms > PE > 52ms > CE
+113ms ║Runtime (42923 bytes) successfully initialized in 38ms (v0.3.110.20191009) (111ms)
+114ms ║╔Execution stage started
+172ms ║║Comparison (enum) closed is (string) open = false (1ms)
+174ms ║║Comparison (enum) closed is (string) open = false (1ms)
+177ms ║║Comparison (enum) closed is (string) open = false (1ms)
+179ms ║║Comparison (enum) closed is (string) open = false (1ms)
+181ms ║║Comparison (enum) closed is (string) open = false (1ms)
+183ms ║║Comparison (enum) closed is (string) open = false (1ms)
+186ms ║║Comparison (enum) closed is (string) open = false (1ms)
+188ms ║║Comparison (enum) closed is (string) open = false (1ms)
+190ms ║║Comparison (enum) closed is (string) open = false (1ms)
+192ms ║║Comparison (enum) closed is (string) open = false (1ms)
+195ms ║║Comparison (enum) closed is (string) open = false (1ms)
+198ms ║║Cancelling condition #11’s schedules…
+199ms ║║Condition #11 evaluated false (81ms)
+200ms ║║Cancelling condition #10’s schedules…
+201ms ║║Condition group #10 evaluated false (state changed) (82ms)
+203ms ║╚Execution stage complete. (88ms)
+204ms ╚Event processed successfully (204ms)
3/27/2020, 9:25:44 AM +409ms
+1ms ╔Starting piston… (v0.3.110.20191009)
+228ms ║╔Subscribing to devices…
+256ms ║║Subscribing to Basement Window Northeast.contact…
+273ms ║║Subscribing to Basement Window Northwest.contact…
+290ms ║║Subscribing to Basement Window Southeast.contact…
+306ms ║║Subscribing to Garage Window Northeast.contact…
+322ms ║║Subscribing to Garage Window Northwest.contact…
+338ms ║║Subscribing to Kitchen Window.contact…
+354ms ║║Subscribing to Living Room Window Northeast.contact…
+370ms ║║Subscribing to Living Room Window Northwest.contact…
+387ms ║║Subscribing to Office Window.contact…
+404ms ║║Subscribing to Playroom Window Northeast.contact…
+421ms ║║Subscribing to Playroom Window Northwest.contact…
+601ms ║╚Finished subscribing (382ms)
+678ms ║Comparison (enum) closed is (string) open = false (1ms)
+680ms ║Comparison (enum) closed is (string) open = false (1ms)
+683ms ║Comparison (enum) closed is (string) open = false (2ms)
+685ms ║Comparison (enum) closed is (string) open = false (1ms)
+688ms ║Comparison (enum) closed is (string) open = false (2ms)
+690ms ║Comparison (enum) closed is (string) open = false (1ms)
+693ms ║Comparison (enum) closed is (string) open = false (2ms)
+695ms ║Comparison (enum) closed is (string) open = false (1ms)
+698ms ║Comparison (enum) open is (string) open = true (1ms)
+717ms ║Comparison (string) Home is (string) open = false (2ms)
+719ms ║Cancelling condition #14’s schedules…
+720ms ║Cancelling condition #13’s schedules…
+735ms ╚Piston successfully started (735ms)


#2

First of all, you don’t want to use $currentEventDevice in this piston at all. That variable will be different every time this piston is run. For the loop you have written you would want to use $device but the loop is a big problem in itself. If multiple windows are open, you will never get past the first one as it will loop on the first open window it finds until the window is closed.

I haven’t tested it but I think you need something like this:

if any of allwindows changes to open. <--trigger
   save matching device to window
   cancel all pending tasks
   with window
      set variable counter[$window]=0
   end with
end if

while any of allwindown is open
  save matching devices to window
  with location
      wait 1 minute
  end with
  for each $device in window
    with $device
       set variable counter[$device] = counter[$device]+1
       send SMS notification $device " window stayed open for " counter[$device] " minutes."
    end with
  end for
end while

You need to change the counter variable type to an array.

Note that this may be OK for testing but there is a limit to the number of SMS messages you can send.


#3

Update: The incrementing counter seems to be mostly working now. The only thing I notice is if I have multiple instances of the piston running for each sensor the minutes (for testing only, I plan for it to be hours) are offset. e.g.; the first device is 1 minute, the second is 2 minutes, the first device is 3 minutes, the second device is 4 minutes, etc. I would have thought the variable would be self-contained per instance.

This is what I have now and it does work for multiple devices in the testing I’ve done, so thank you for that! But the counter still isn’t incrementing right. I followed your example as closely as I could but I think I probably got a couple things wrong. I also wasn’t quite sure which variable type is an array in WebCoRE.

Thanks.


#5

The reason I laid out the piston as I did above was to be sure only one instance was running since one will track all the sensors. That is why I inserted the ‘cancel all pending tasks’ command and then put the while loop outside the trigger. I knew this would create an offset in the counters but if you were really doing minutes wouldn’t matter much. Not an easy way to avoid that. I would suggest deleting the counter and instead using this message:

log to console $device "window has been open for " formatDuration(age([$device : switch]))

This will give you how long each sensor has been in their current state (on) in hh:mm:ss


#6

@mada2885, Sorry, I should have said list type. Those are below the regular variable types. I took a cut at it with the counter and had to add one more variable for the counter index.

This provides the following log:

3/27/2020, 11:41:05 PM +454ms
+1ms	╔Received event [LV Side Door].contact = closed with a delay of 1019ms
+172ms	╚Event processed successfully (172ms)
3/27/2020, 11:40:53 PM +225ms
+1ms	╔Received event [Las Vegas].time = 1585377654762 with a delay of -1538ms
+278ms	║LV Side Door stayed open for 3 minute(s)
+345ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:41:53 PM PDT (in 59.994s)
+353ms	╚Event processed successfully (353ms)
3/27/2020, 11:39:54 PM +635ms
+1ms	╔Received event [LV Back Door].contact = closed with a delay of 114ms
+131ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:40:54 PM PDT (in 59.997s)
+144ms	╚Event processed successfully (144ms)
3/27/2020, 11:39:22 PM +234ms
+0ms	╔Received event [Las Vegas].time = 1585377563729 with a delay of -1496ms
+258ms	║LV Back Door stayed open for 1 minute(s)
+258ms	║LV Side Door stayed open for 2 minute(s)
+319ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:40:22 PM PDT (in 59.997s)
+338ms	╚Event processed successfully (339ms)
3/27/2020, 11:38:23 PM +591ms
+1ms	╔Received event [LV Back Door].contact = open with a delay of 292ms
+142ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:39:23 PM PDT (in 59.997s)
+152ms	╚Event processed successfully (152ms)
3/27/2020, 11:37:36 PM +217ms
+1ms	╔Received event [Las Vegas].time = 1585377457911 with a delay of -1694ms
+186ms	║LV Side Door stayed open for 1 minute(s)
+232ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:38:36 PM PDT (in 59.997s)
+241ms	╚Event processed successfully (240ms)
3/27/2020, 11:36:37 PM +713ms
+1ms	╔Received event [LV Side Door].contact = open with a delay of 550ms
+202ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:37:37 PM PDT (in 59.997s)
+209ms	╚Event processed successfully (209ms)

Problem with this is it resets the timer every time a contact is opened or closed so the time open can get way off.


#7

@mada2885 Here is what I think you really want:

Which provides this log:

3/27/2020, 11:57:05 PM +310ms
+0ms	╔Received event [Las Vegas].time = 1585378626164 with a delay of -855ms
+106ms	╚Event processed successfully (106ms)
3/27/2020, 11:56:20 PM +370ms
+0ms	╔Received event [LV Side Door].contact = closed with a delay of 446ms
+126ms	╚Event processed successfully (126ms)
3/27/2020, 11:56:05 PM +979ms
+2ms	╔Received event [LV Back Door].contact = closed with a delay of 922ms
+189ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:57:06 PM PDT (in 59.996s)
+200ms	╚Event processed successfully (199ms)
3/27/2020, 11:55:29 PM +295ms
+0ms	╔Received event [Las Vegas].time = 1585378530627 with a delay of -1333ms
+353ms	║LV Back Door stayed open for 00:01:00 minute(s)
+353ms	║LV Side Door stayed open for 00:02:37 minute(s)
+399ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:56:29 PM PDT (in 59.997s)
+406ms	╚Event processed successfully (406ms)
3/27/2020, 11:54:30 PM +471ms
+1ms	╔Received event [LV Back Door].contact = open with a delay of 1364ms
+160ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:55:30 PM PDT (in 59.997s)
+171ms	╚Event processed successfully (171ms)
3/27/2020, 11:53:51 PM +478ms
+0ms	╔Received event [Las Vegas].time = 1585378432624 with a delay of -1147ms
+161ms	║LV Side Door stayed open for 00:00:59 minute(s)
+207ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:54:51 PM PDT (in 59.996s)
+215ms	╚Event processed successfully (215ms)
3/27/2020, 11:52:52 PM +430ms
+1ms	╔Received event [LV Side Door].contact = open with a delay of 529ms
+200ms	║Setting up scheduled job for Fri, Mar 27 2020 @ 11:53:52 PM PDT (in 59.995s)
+208ms	╚Event processed successfully (208ms)

EDIT: Message really should say “hours” but I didn’t edit it.


#8

@guxdude Great, thank you for all your help! I think everything is working now. The only thing I might want to tweak is the “age” output to be only an hour and not included minutes or seconds. What I’m trying is $device " has been open for " formatDuration(age([$device : contact]), ‘h’)"". I believe I have to wait for the sensor to actually be open an hour to get a test of what the output is, as I’ve tried with minutes during testing and I get back 00 hours and XX minutes.


#9

Glad it is working. Two tweak the ‘age’ output, I think you need to include the true or false for the friendly format. See the documentation here.


#10

@guxdude I’ve run into a snag with this piston. It seems that when multiple sensors are open if any one of them changes it forces the schedules for others to cancel e.g.; (sensor 1 opens, then 2 minutes later sensor 2 opens, then sensor 2 closes shortly after, and sensor 2 as well as sensor 1 are both stopped in the piston.) I thought this was all working correctly but I haven’t really started opening windows until recently so my testing wasn’t very thorough. Thanks for any help you can offer.


#11

@mada2885 Are you using the pistons as I posted it? set logging to full and post the logs after you see this problem. As long as any window is open it should continue to send messages so not sure what it is doing.


#12

I think I figured that issue out. I had the While statement within the first If block. This is what I have now.

Although now it seems that if sensors are opened only the latest schedule is kept. Similar to what I posted previously, if sensor 1 opens, then 30 minutes later sensor 2 opens then both sensors notify an hour later, making the first one 1.5 hours. I guess it’s not a huge deal, just not exactly what I had in mind.


#13

Yes, this keeps one notification time based on the last one opened or closed but gives an accurate time open message for each window. If you really wanted separate notifications for each window you would have separate pistons for each window which I don’t think you want to do.