Alert me if someone is outside only if the front door motion sensor does not show open in the last 20 seconds

I have a motion sensor outside above the front door whitch shows if someone is outside the house, this works well.

alias: Frontdoor Someone outside
description: ""
trigger:
  - type: motion
    platform: device
    device_id: ffda8f8b6dbdc576e1418c170394edc2
    entity_id: 2a694648c767946595286485a6d13f15
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition: []
action:
  - service: notify.pushover
    data:
      title: Front Door
      message: Someone Outside
mode: single

However this also fires if someone leaves the house. There is a Door Sensor on the front door so I can see if the front door is left open…

alias: Frontdoor Left Open
description: Repeat alert to mobile if the front door is open every 2 minutes
trigger:
  - platform: state
    entity_id:
      - binary_sensor.frontdoor_isopened
    to: "on"
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - repeat:
      while:
        - condition: state
          entity_id: binary_sensor.frontdoor_isopened
          state: "on"
      sequence:
        - service: notify.mobile_app_m2007j20cg
          data:
            message: Front Door has been open for more than 2 minutes
            title: Front Door
          enabled: false
        - service: notify.pushover
          data:
            title: Front Door
            message: Open > 2 minutes
        - delay:
            hours: 0
            minutes: 2
            seconds: 0
            milliseconds: 0
mode: single

What I would like to do is combine these sensors so I only get alerted if someone comes to the door, not if someone leaves. So what I am thinking is have a condition of the first YAML (which fires if there is someone outside the Front Door) to only fire if the front Door Door/Window Sensor has not been triggered in the last 20 seconds. This will stop the alert if someone has just left the house but will still fire if someone comes to the house.

Something like

If front door motion sensor fires and front door open/closed sensor has not been fired in last 20 seconds send alert ‘someoner at front door’

Feel like I need to save the time the front door open/closed sensor to some type of varable/widget and check this time when the front door motion sensor fires. However not sure how to do this?

Create a sensor “outside motion armed” that gets set when the door is closed for more than 20 seconds and reset when the door is opened. Use this “armed” sensor as a condition on the motion detection automation.

Add a State Condition to the automation that requires the door to have been closed for at least 20 seconds.

condition:
 - condition: state
   entity_id: binary_sensor.frontdoor
   state: 'off'
   for:
     seconds: 20

Anyone leaving home will have 20 seconds to vacate after closing the door. 20 seconds after the door is closed, any detected movement will permit the automation to execute its action .

2 Likes

Just to clarify. This condition will stop.an automation firing if the door/window sensor has b en triggered in the last 20 seconds?

The State Condition posted above will allow the automation to execute its action only if the door was closed at least 20 seconds before the automation was triggered.

At the moment when motion is detected, the door must be in a closed state for at least the past 20 seconds in order for the notification to occur.

1 Like

Thanks, yhat did the trick. I also added another condition so I only get the alert during the day. Hope this is usefull to others.

alias: Front Door Someone outside
description: Send an alert if someone arrives at the Front Door during the day
trigger:
  - type: motion
    platform: device
    device_id: ffda8f8b6dbdc576e1418c170394edc2
    entity_id: 2a694648c767946595286485a6d13f15
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.frontdoor_isopened
        state: "off"
        for:
          seconds: 20
      - condition: time
        after: "08:30:00"
        before: "23:00:00"
action:
  - service: notify.pushover
    data:
      title: Front Door
      message: Someone Outside
mode: single

You’re welcome! Glad to hear it fulfilled your request.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like

You appear to have marked your own post with the Solution tag. It’s the custom of this community forum to assign the Solution tag to the post that resolves the original problem or answers the original question. If you recall, that this post which explained how to use a State Condition to meet your requirements. Only one post in the entire topic can have the tag.

FWIW, if everyone marked their own post, it would give the impression that everyone ultimately solves their own problem (regardless of the help they received).