Creating automation to notify when a sensor hasn't updated for x time

I’m trying to automate a check so that if something hasn’t confirmed valid updated for x time, then actions/notify needs to occur.
Its for an oil level sensor which doesn’t change all the time, but i need to know if it stops reporting to prevent running out. the reporting ordinarily happens every 24 hours or so, even though the reported value may not change

The entity is sensor.last_reading_date

This doesnt show as an option in device for the automation, so i was thinking numeric state. But that gives options of above/below etc, and i specifically want to to trigger on sensor.last_reading_date has not updated for x days.

Sounds simple and I have tons of automations in toggledbits MSR, but i’m trying to move things more and more into native automations where possible.

Anyone spare time to give me a pointer?
Many thanks :slight_smile:

I use a template sensor that detects stale data on my plant sensors and then triggers an automation to notify me, maybe something you can re-use?


  - name: Plant 16 stale sensor
    icon: mdi:flower
    state: >-
      {% if as_timestamp(now()) - as_timestamp(states.sensor.plant_16_illuminance.last_updated) > 43200 %}
        true
      {% else %}
        false
      {% endif %}
trigger:
  - platform: state
    entity_id: sensor.last_reading_date
    to: ~
    for: '24:00:00'

That’ll trigger when the state of the sensor hasn’t changed in 24 hours.

Keep in mind that when HA restarts that resets the clock (same goes for last_updated).

Great, that should work, thanks for the HA restart warning.
That shouldn’t be an issue, as I don’t restart every day. I will set the trigger to two days, and if its delayed for 2 days more (maximum) due to a restart, it wont be an issue.

I was just trying to avoid not noticing the levels for week(s) or more then having a big surprise when it gets to (nearly or close to) empty :wink:

Examples

1 Like