Help with automation trigger, binary sensor for a time period

How can I have an automation trigger 5 minutes after a binary sensor changes to a given state?

I have a laser emitter / sensor that I’m planning to install just inside my garage door at bumper height. My plan is to use esphome so HA knows if the door is clear. I also have an LED light that comes on when the bumper is clear of the door so I know when to stop pulling into the garage. Here is my yaml for the binary sensor and for controlling the “stop” light:


binary_sensor:
  - platform: gpio
    pin: 16
    name: "Garage Door Clear"
    id: garage_door_clear
    device_class: safety 
    filters:
      - invert:
      - delayed_on: 200ms
    on_state:
      then:
        if:
          condition:
            binary_sensor.is_on: garage_door_clear
          then:
            - output.turn_off:  gpio_light
          else: 
            - output.turn_on:  gpio_light

output:
  - platform: gpio
    pin: 12
    id: gpio_light

I’d like to turn the “stop” light off after 5 minutes or so. There’s really no reason for it to burn all the time. It seems that within esphome you can only have triggers that work on a state change. I know that I could expose the light to HA and use a HA automation to turn it off, but I’d prefer to keep it within the esphome ecosystem.

It’s easy using the automation editor

Or if you want to do it on the esp this should work:

    on_state:
      then:
        if:
          condition:
            binary_sensor.is_on: garage_door_clear
          then:
            - output.turn_off:  gpio_light
          else: 
            - output.turn_on:  gpio_light
            - delay 300s
            - output.turn_off:  gpio_light

Thanks. I considered this, but the documentation mentions the asynchronous nature of the delay, and I was concerned that if the state changed back to on, that it would turn the light off anyway.

and it probably would

Use the for condition then: