Automation help - sensor becomes unavailable sometimes

Hi
I’m having trouble defining an automation which checks if a door sensor is open or not.
The issue is that the sensor becomes unavailable, so when the door opens, it becomes unavailable after a while until close or visa versa.
Is there a way I can make the automation smart enough to ignore the unavailable and continue check if the door is opens longer than 30 minutes?

So this automation doesn’t work because of the unavailable states sometimes, like you can see in the logs:

alias: Doors
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.aqara_contact
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition: []
action:
  - service: notify.family
    data:
      message: "The door is open for a hour!"
      title: Door
mode: single

the log:

Add this line to the State Trigger:

    from: "off"

like this:

  - platform: state
    entity_id:
      - binary_sensor.aqara_contact
    from: "off"
    to: "on"
    for:
      minutes: 30

That ensures it will only trigger if the binary_sensor’s value changes from off to on and remains unchanged for at least 30 minutes.

If its value changes during the 30 minute period (becomes off again or unavailable), it serves to reset the State Trigger.

1 Like