Setting a global flag when there has any been motion detected in the past two minutes


#1

1) Give a description of the problem

I am trying to write a piston that sets a global variable, @EntrywayMotion, to true whenever there has been any motion detected by the Entryway Motion motion sensor (anonymized in the snapshot as Motion Sensor 1) within the past two minutes, and to false otherwise.

I would like to accomplish this in the simplest and most efficient way possible.

2) What is the expected behavior?

The @EntrywayMotion variable should be set to true when there is motion, and then back to false exactly two minutes after the last motion has been detected.

3) What is happening/not happening?

The @EntrywayMotion variable is correctly set to true when there is motion, but it is set back to false two minutes after the motion sensor first becomes inactive, rather than two minutes after the last motion has been detected.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)

10/18/2017, 6:50:18 PM +359ms
+1ms	╔Received event [Home].time = 1508377819525 with a delay of -1166ms
+165ms	║RunTime Analysis CS > 12ms > PS > 78ms > PE > 74ms > CE
+181ms	║Runtime (41308 bytes) successfully initialized in 78ms (v0.2.0fa.20171011) (178ms)
+182ms	║╔Execution stage started
+201ms	║║Cancelling condition #16's schedules...
+202ms	║║Condition #16 evaluated true (2ms)
+207ms	║║Comparison (boolean) true is (boolean) true = true (2ms)
+209ms	║║Condition #17 evaluated true (7ms)
+210ms	║║Cancelling condition #13's schedules...
+211ms	║║Condition group #13 evaluated true (state changed) (11ms)
+213ms	║║Cancelling statement #14's schedules...
+235ms	║║Executed virtual command sendPushNotification (17ms)
+238ms	║║Cancelling statement #31's schedules...
+241ms	║║Executed virtual command setVariable (1ms)
+246ms	║║Executed virtual command setVariable (3ms)
+249ms	║╚Execution stage complete. (68ms)
+332ms	╚Event processed successfully (332ms)
10/18/2017, 6:49:50 PM +625ms
+1ms	╔Received event [Entryway Motion].motion = inactive with a delay of 502ms
+151ms	║RunTime Analysis CS > 12ms > PS > 67ms > PE > 71ms > CE
+166ms	║Runtime (41310 bytes) successfully initialized in 67ms (v0.2.0fa.20171011) (164ms)
+167ms	║╔Execution stage started
+177ms	║║Comparison (enum) inactive changes_to (string) active = false (0ms)
+178ms	║║Cancelling condition #6's schedules...
+179ms	║║Condition #6 evaluated false (6ms)
+180ms	║║Cancelling condition #1's schedules...
+181ms	║║Condition group #1 evaluated false (state changed) (8ms)
+186ms	║║Comparison (datetime) 1508377771801 stays_unchanged = true (1ms)
+188ms	║║Condition #16 evaluated false (5ms)
+189ms	║║Condition group #13 evaluated false (state did not change) (5ms)
+191ms	║╚Execution stage complete. (24ms)
+193ms	║Setting up scheduled job for Wed, Oct 18 2017 @ 6:50:19 PM PDT (in 28.708s)
+217ms	╚Event processed successfully (216ms)
10/18/2017, 6:49:32 PM +110ms
+2ms	╔Received event [Entryway Motion].motion = active with a delay of 309ms
+190ms	║RunTime Analysis CS > 15ms > PS > 101ms > PE > 74ms > CE
+206ms	║Runtime (41314 bytes) successfully initialized in 101ms (v0.2.0fa.20171011) (203ms)
+207ms	║╔Execution stage started
+217ms	║║Comparison (enum) active changes_to (string) active = true (1ms)
+219ms	║║Cancelling condition #6's schedules...
+219ms	║║Condition #6 evaluated true (7ms)
+220ms	║║Cancelling condition #1's schedules...
+221ms	║║Condition group #1 evaluated true (state changed) (9ms)
+227ms	║║Comparison (boolean) true is (boolean) false = false (2ms)
+228ms	║║Condition #23 evaluated false (5ms)
+229ms	║║Condition group #18 evaluated false (state did not change) (6ms)
+231ms	║║Cancelling statement #26's schedules...
+242ms	║║Executed virtual command sendPushNotification (7ms)
+245ms	║║Cancelling statement #2's schedules...
+250ms	║║Executed virtual command setVariable (3ms)
+256ms	║║Comparison (datetime) 1508377771801 stays_unchanged = true (1ms)
+258ms	║║Condition #16 evaluated false (4ms)
+258ms	║║Condition group #13 evaluated false (state did not change) (5ms)
+261ms	║╚Execution stage complete. (55ms)
+263ms	║Setting up scheduled job for Wed, Oct 18 2017 @ 6:50:19 PM PDT (in 47.153s)
+287ms	╚Event processed successfully (287ms)
10/18/2017, 6:48:19 PM +297ms
+1ms	╔Received event [Entryway Motion].motion = inactive with a delay of 304ms
+188ms	║RunTime Analysis CS > 15ms > PS > 103ms > PE > 70ms > CE
+206ms	║Runtime (41311 bytes) successfully initialized in 103ms (v0.2.0fa.20171011) (203ms)
+207ms	║╔Execution stage started
+218ms	║║Comparison (enum) inactive changes_to (string) active = false (1ms)
+219ms	║║Condition #6 evaluated false (6ms)
+220ms	║║Condition group #1 evaluated false (state did not change) (7ms)
+225ms	║║Comparison (datetime) 1508377681972 stays_unchanged = true (0ms)
+227ms	║║Adding a timed trigger schedule for condition 16
+229ms	║║Cancelling condition #16's schedules...
+230ms	║║Condition #16 evaluated false (7ms)
+231ms	║║Cancelling condition #13's schedules...
+232ms	║║Condition group #13 evaluated false (state changed) (9ms)
+234ms	║╚Execution stage complete. (28ms)
+236ms	║Setting up scheduled job for Wed, Oct 18 2017 @ 6:50:19 PM PDT (in 119.993s)
+265ms	╚Event processed successfully (265ms)
10/18/2017, 6:48:02 PM +260ms
+1ms	╔Received event [Entryway Motion].motion = active with a delay of 288ms
+271ms	║RunTime Analysis CS > 13ms > PS > 195ms > PE > 63ms > CE
+353ms	║Runtime (41310 bytes) successfully initialized in 195ms (v0.2.0fa.20171011) (350ms)
+353ms	║╔Execution stage started
+363ms	║║Comparison (enum) active changes_to (string) active = true (1ms)
+365ms	║║Cancelling condition #6's schedules...
+365ms	║║Condition #6 evaluated true (6ms)
+366ms	║║Cancelling condition #1's schedules...
+367ms	║║Condition group #1 evaluated true (state changed) (8ms)
+372ms	║║Comparison (boolean) false is (boolean) false = true (1ms)
+373ms	║║Cancelling condition #23's schedules...
+374ms	║║Condition #23 evaluated true (5ms)
+375ms	║║Cancelling condition #18's schedules...
+376ms	║║Condition group #18 evaluated true (state changed) (7ms)
+378ms	║║Cancelling statement #19's schedules...
+381ms	║║Executed virtual command setVariable (1ms)
+383ms	║║Cancelling statement #28's schedules...
+394ms	║║Executed virtual command sendPushNotification (7ms)
+397ms	║║Cancelling statement #2's schedules...
+402ms	║║Executed virtual command setVariable (3ms)
+408ms	║║Comparison (datetime) 1508377681972 stays_unchanged = true (1ms)
+409ms	║║Adding a timed trigger schedule for condition 16
+411ms	║║Cancelling condition #16's schedules...
+412ms	║║Condition #16 evaluated false (7ms)
+413ms	║║Cancelling condition #13's schedules...
+414ms	║║Condition group #13 evaluated false (state changed) (9ms)
+416ms	║╚Execution stage complete. (63ms)
+418ms	║Setting up scheduled job for Wed, Oct 18 2017 @ 6:50:02 PM PDT (in 119.993s)
+439ms	╚Event processed successfully (439ms)

#2


#3

Thanks for your suggested solution. Unfortunately, it doesn’t look like it does what I want. I want the flag to be cleared two minutes after the last time the motion sensor has reported that it was active, not two minutes after it reports that it’s become inactive.

Also, what happens if there is motion detected during your two-minute wait? I’m guessing it will clear the flag immediately after the two-minute wait, even if there has been motion right before the end of that wait.


#4

Sorry I misunderstood your request, you can do this with two pistons. The first one executing the second one like so.


#5

If motion is detected during the two minute wait it restarts the countdown, it will not reset the flag till two minutes have elapsed with no motion


#6

Thanks. I have two questions:

  1. Why does your second solution require two separate pistons?

  2. Why doesn’t my piston work as I expect, and is there a simple change I can make to it to make it work?

I’m new to all this and still trying to understand how piston control flow works.