Trigger Switch if 2nd Motion is triggered within 30 seconds

piston

#1

1) Give a description of the problem
Unsure how to build. New to webCoRE.

2) What is the expected behaviour?
Ideally, I would like a switch to operate if motion is detected by Motion2 only if within 30 seconds of motion triggered by Motion1.

3) What is happening/not happening?
Nothing yet. Not sure how to add the “within 30 seconds of first motion” part.

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

5) Attach logs after turning logging level to Full
7/13/2020, 11:12:44 PM +158ms
+0ms ╔Received event [SmartThings Hub].test = 1594696364157 with a delay of 0ms
+74ms ║RunTime Analysis CS > 14ms > PS > 32ms > PE > 29ms > CE
+76ms ║Runtime (37245 bytes) successfully initialized in 32ms (v0.3.110.20191009) (75ms)
+77ms ║╔Execution stage started
+113ms ║║Comparison (enum) inactive changed = false (25ms)
+114ms ║║Condition #2 evaluated false (32ms)
+115ms ║║Condition group #1 evaluated false (state did not change) (33ms)
+120ms ║╚Execution stage complete. (42ms)
+121ms ╚Event processed successfully (121ms)

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


#2

Something like this maybe

On Event from motion sensors

  If $now is after addseconds(Start,31) and 
  TriggerEvent is true

         TriggerEvent = false

  If first motion is active
      Start = $now
      TriggerEvent = true

  If second motion is active and Trigger Event is true
      If $now is after addseconds(Start,30) then
            Turn on Switch

Start is a Time Variable, TriggerEvent is a Boolean.

There are probably better ways but that is what I came up with and I of coarse haven’t tested it but I think it would work. This would give you a 1 second window, which may be too tight. Every time a motion event occurs it will trigger the piston. So you may have to give it a few seconds or it might miss a trigger.


#3

IF
age([motionSensor1 : motion]) is less than 30000
AND
age([motionSensor2 : motion]) is less than 30000
THEN
turn on switch

Note - 30000 = 30 seconds, as the age() function outputs in milliseconds.