Linking 2 motion detectors but only in one sequence

I want to receive an alert when a car comes down the drive but not when a car leaves. I have a camera by the gate, and a PIR ~10 yards / metres nearer to the house - the coverages do not overlap.

I think the easiest way to achieve this would be the following flow of activities…

WHEN binary_sensor.gate_motion changes from off to on

AND within 10 seconds BEFORE switch.gate_pir changes from off to on

Activate Call Service

How might I encode the AND within 10 seconds BEFORE part in the follow automation code?

Many thanks!

description: ""
mode: single
trigger:  
  - platform: state    
    entity_id:      
# This is the motion sensor within the camera
      - binary_sensor.gate_motion    
        from: "off"
        to: "on"
condition: []

trigger:
  - platform: state
    entity_id:
# This is the motion sensor within the PIR sensor
      - switch.gate_pir
    from: "off"
    to: "on"
condition: []

action:
  - service: notify.mobile_app_iphone    
    data:      
      message: Car coming down the drive
      title: Drive Activity

Trigger on your gate. First action is a wait for trigger waiting for the PIR to trigger, with a timeout of 10 seconds and continue on timeout set to false.

Second action is your notify service. This won’t happen if the wait template expires, i.e. if the PIR does not trigger within 10 seconds of the gate triggering.

trigger:  
  - platform: state    
    entity_id: binary_sensor.gate_motion    
    from: 'off'
    to: 'on'
action:
  - wait_for_trigger:
      - platform: state
        entity_id: switch.gate_pir
        from: 'off'
        to: 'on'
    timeout: 10
    continue_on_timeout: false
  - service: notify.mobile_app_iphone    
    data:      
      message: Car coming down the drive
      title: Drive Activity
1 Like

Brilliant - works perfectly. Thank you so much!