Trigger Automation when one sensor tripped but other hasn't

I have 2 yolink sensors. I need to send a notification to my phone when the one by my house has been triggered but the one at the end of my driveway has not been triggered in the past 5 seconds. At the moment I am testing before installing them. I will bump the time up once I get this working. I am fairly new to YAML but I am not sure how to do this. Here is my code.

alias: Kids Going Down The Driveway
description: ""
trigger:
  - type: motion
    platform: device
    device_id: e79633a1f4e69288fd3bb28b1cdeefbf
    entity_id: 7cede9d3586fb3861f5073f4575a8195
    domain: binary_sensor
condition:
  - type: is_no_motion
    condition: device
    device_id: 2e087b2e0f889772406174c4dbbedcbb
    entity_id: e4d58b091762b6cc85333fffa62fcf94
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 5
action:
  - device_id: 665f8ab52457dc4d19bcbfce8f18cca4
    domain: mobile_app
    type: notify
    message: Test
    title: test
mode: single

Hello and welcome to the forum. For a start be kind to future you and do have a read of this: Why and how to avoid device_ids in automations and scripts

Funny you say that. I ended up learning that in about the past hour. Unfortunately I am still having issues. My code is now this

alias: Back Drive Motion with Front Drive Check
description: >
  If the back drive motion sensor is triggered but the front drive motion sensor
  hasn't been triggered in the past 5 seconds, send a notification.
trigger:
  - platform: state
    entity_id: binary_sensor.back_drive_motion_sensor_motion
    to: "on"
condition:
  - condition: template
    value_template: >
      {{ (now() -
      states.binary_sensor.front_drive_motion_sensor_motion.last_changed).total_seconds()
      > 5 }}
action:
  - data:
      name: Back Drive Motion Automation
      message: >-
        Condition met. Front Drive Last Changed: {{
        states.binary_sensor.front_drive_motion_sensor_motion.last_changed }}
    action: logbook.log
  - data:
      message: Back drive motion detected while front drive not triggered.
      title: Motion Detected
    action: notify.mobile_app_alexs_iphone
mode: single

What does the trace tell you?

You probably want a second condition in the conditions block to confirm the state of the front drive motion sensor is off.

Otherwise the automation can trigger if there has been motion detected on the front drive continuously for at least 5 seconds.

1 Like

What Rick says. I have automations similar to that.

So, basically, your logic must be: When the back driveway’s sensor gets triggered, check that the front driveway’s sensor is off and hasn’t changed in the last 5 seconds.