Notify if garage door is open for longer than 5 minutes after 8pm

I’m trying to get an alert on my phone if I have left my garage door open. I have my garage door connected to a Shelley1 with a reed switch connected to it’s Input terminal. My automation works fine except that the input sensor regularly reports as unavailable for several seconds for some reason. So my automation gets triggered when the door isn’t actually open.

I tried adding a For 5 minutes into my automation but it hasn’t helped. I’ve read a few other threads similar to this which got very technical about how the For operates but unfortunately I couldn’t figure out what the solution was.

Any help greatly appreciated!

alias: Garage Door open notification
description: ""
trigger:
  - type: not_powered
    platform: device
    device_id: e1baadb166e5ba354c9c2ff76e779ecd
    entity_id: binary_sensor.double_garage_door_input
    domain: binary_sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    before: "06:00:00"
    after: "20:00:00"
    weekday:
      - sun
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
action:
  - service: notify.adult_mobiles
    data:
      data:
        actions:
          - action: URI
            title: Open App
            uri: /lovelace-mushroom/garage
      message: Yo! The garage door is open
      title: Garage Door Open

It might help to switch to a State trigger instead of using the Device trigger so you can filter out state changes from “unavailable” or “unknown”. Additionally, you may want to add a Time trigger and corresponding State condition so the door closes if it has been opened 5 minutes just prior to 8pm:

alias: Garage Door open notification
description: ""
trigger:
  - platform: time
    at: "20:00:00" 
  - platform: state
    entity_id: binary_sensor.double_garage_door_input
    to: 'off'
    not_from:
      - "unknown"
      - "unavailable"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    before: "06:00:00"
    after: "20:00:00"
  - condition: state
    entity_id: binary_sensor.double_garage_door_input
    state: 'off'
    for:
      hours: 0
      minutes: 5
      seconds: 0
action:
  - service: notify.adult_mobiles
    data:
      data:
        actions:
          - action: URI
            title: Open App
            uri: /lovelace-mushroom/garage
      message: Yo! The garage door is open
      title: Garage Door Open

Aha - that makes sense. I’ll give that a shot. Thanks!