Automation - trigger action if garage door left open

Need a bit of help - how would I trigger an automation that does something after a trigger and time period has elapsed?

I want to send a message if my garage door has been left open for longer than 5 minutes, I tried this

- alias: Send Message - Garage
  trigger:
     - platform: state
       entity_id: binary_sensor.garage door
       to: 'on'
  condition:
    condition: state
    entity_id: binary_sensor.garage door
    state: 'on'    
    for:
      minutes: 5 
  action:
    - service: telegram_bot.send_message
      data_template:
        target: -xxxxx
        message:
          The garage door has been left open for longer than 5 minutes

Your code will never work because the condition is tested when the trigger happens. And in this case, the condition requires the door to have been opened for 5 minutes at the exact time it opens, which is impossible. Luckily, though, the solution is even simpler: Just use the for: parameter with the trigger and delete the condition:

- alias: Send Message - Garage
  trigger:
    - platform: state
      entity_id: binary_sensor.garage door
      to: 'on'
      for:
        minutes: 5 
  action:
    - service: telegram_bot.send_message
      data_template:
        target: -xxxxx
        message: The garage door has been left open for longer than 5 minutes
1 Like

Perfect, working

I didn’t think the above would work - I initially only had the For in the condition - none of the rest… but got errors

1 Like

I know I’m a little late to the party here, but I wanted to offer an alternative solution because of the additional benefit of providing multiple notifications with just one setup, i.e. not even an automation:

#######################################################################
# Alert for Garage Door having been open for more than 5 minutes
alert:
  garage_door_open_long:
    name: Garage Door is still open!
    entity_id: binary_sensor.garage_door_sensor
    state: 'off'   # Optional, 'on' is the default value
    repeat: 5
    can_acknowledge: true  # Optional, default is true
    skip_first: true  # Optional, false is the default
    notifiers:
      - mypushbullet

This setup (in the configuration.yaml not as an automation) sends me a message not just once, but every 5 minutes, details for the configuration are here:

I know that others have had difficulties to get it to work but for me it works flawlessly.

Thanks - I’ll look into it - haven’t used Alerts at all - and I do quite a few automation that do alerting.