Send a notification when motion detected at front door, but cancel if one or multiple conditions are met

I am pulling my hair out with the following automation idea…:
Whenever our doorbell detects motion, send a notification. This is the part that works, ofcourse. However, I want to cancel this automation whenever someone rings our doorbell OR the door opens in a timespan of 30 seconds.

trigger:
   - platform: state
     entity_id: binary_sensor.g4_doorbell_motion
     from: "off"
     to: "on"

condition: # WAIT FOR 30 SECONDS TO CHECK IF CONDITIONS IS MET, IF A CONDITIONS IS MET, CANCEL THE AUTOMATION/DON'T SEND A NOTIFICATION
             - platform: state
               entity_id: binary_sensor.g4_doorbell_doorbell
               from: 'off'
               to: 'on'
             - platform: state
               entity_id: lock.loqed_voordeur
               from: 'ontgrendeld'
               to: 'open'

action:
        - service: notify.mobile_app_iphone_max
          data:
            title: Voordeur motion
            message: Er is beweging bij de voordeur gedetecteerd, maar er is niet aangebeld...

I know that the condition part is wrong at this moment, but I’m looking for the right way to do it. I’ve looked into wait_for_template, wait_for_trigger, if, then, else````, choose```.

I’m hoping for someone who can help me with finding the right way to get this automation to work.

Thanks in advance.

1 Like

You may need to specify this a bit better…what I read is
When motion detected, wait 30s and if in that period either the door opens or the doorbell is used…no notification.

Meaning that if niehter door/ring it takes 30s to send a notification, which for me sounds a long time…but that is me :slight_smile:

This may need some templating though…

That is correct. Check within 30 seconds after motion is detected if someone rang the doorbell or the door is opened and if so, don’t send a notification.
It doesn’t matter that the notification will be 30 seconds after the motion is detected. I will just look back the camera in another app if it was someone at the door who did not had to be there. (most of the times it will be the postman or a cat…)

I have it working with just one condition:

  trigger:
    - platform: state
      entity_id: binary_sensor.g4_doorbell_motion
      from: "off"
      to: "on"

  action:
    - wait_template: "{{ is_state('binary_sensor.g4_doorbell_doorbell', 'on') }}"
      timeout: 30
    - if:
        - "{{ not wait.completed }}"
      then:

        - service: notify.mobile_app_iphone_max
          data:
            title: Voordeur motion
            message: Er is beweging bij de voordeur gedetecteerd, maar er is niet aangebeld...
            data:
              url: unifi-protect://
              entity_id: camera.g4_doorbell_high
              push:
                badge: 1
      else:
        - stop: "Automation stopped: condition was not met"

But I have some difficulties with adding another condition…

My approach would be
Trigger
wait (action) 30s
IF (doorbell last changed - trigger last changed) > 30 AND (door last changed - trigger last changed) > 30
THEN send message

Thanks for the idea! I think this will work. Will test later when I get home.

  trigger:
    - platform: state
      entity_id: binary_sensor.g4_doorbell_motion
      from: "off"
      to: "on"

  action:
    - delay: "00:00:30"

    - if:
        - condition: or
          conditions:
            - condition: template
              value_template: "{{ (as_timestamp(now()) - as_timestamp((states.lock.loqed_voordeur.last_updated)) < 30  )}}"
            - condition: template
              value_template: "{{ (as_timestamp(now()) - as_timestamp((states.binary_sensor.g4_doorbell_doorbell.last_updated)) < 30  )}}"

      then:
        - stop: "Automation stopped: door opened or someone rang the doorbell"

      else:
        - service: camera.snapshot
          data:
            filename: /config/www/deurbel_snapshots/deurbel_camera_motion_snapshot.jpg
          target:
            entity_id: camera.g4_doorbell_high

        - service: notify.mobile_app_iphone_max
          data:
            title: Voordeur motion
            message: Er is beweging bij de voordeur gedetecteerd, maar er is niet aangebeld...
            data:
              image: /local/deurbel_snapshots/deurbel_camera_motion_snapshot.jpg
              url: /local/deurbel_snapshots/deurbel_camera_motion_snapshot.jpg
              push:
                badge: 1

Similar but different :wink: