Automation that triggers when a sensor becomes unavailable

This one has stumped me. I have a sensor (in my car) that is reporting an incrementing number every second via an ESPHome device. When I drive off, the sensor eventually becomes “unavailable”, however before that happens the sensor shows the same number for a few seconds.

I’d like to trigger an automation when the sensor reports the same number for 5 seconds or it times out to “unavailable”.

  trigger:
  - platform: state
    entity_id: sensor.yourentity
    to: 'unavailable'
    for:
      seconds: 5

This should work. Give it a try.
However I have no idea how to do this for when it reports the same number.

1 Like

in addition to the suggestion above you might be able to use this: