Notify when no update in some amount of time

I need to create an automation which notifies me when a sensor has not been updated in X amount of minutes but not sure how to formulate the automation, i.e. what trigger to use
I assume it is the state trigger but how to set it up?

If your sensor times out and goes unavailable, you can use something like this:

- alias: lux_out_of_service
  initial_state: true
  trigger:
    platform: state
    entity_id: sensor.front_verandah_lux
    to: unavailable
    for: 00:45:00
  action:
    service: persistent_notification.create
    data_template:
      message: Front verandah lux sensor battery flat?

Te lux sensor has an expire_after value to make it go unavailable:

  - platform: mqtt
    name: "Front Verandah Lux"
    state_topic: "lux_sensor/sensor/bh1750_illuminance/state"
    device_class: illuminance
    unit_of_measurement: "lx"
    expire_after: 900
1 Like

BTW if it’s not a MQTT sensor, or doesn’t go unavailable when not updated - you can do a trigger when the state doesn’t change in x amount of time:

  trigger:
    - platform: state
      entity_id: sensor.front_verandah_lux
      for: "00:45:00"

Yoo can use a template for e.g. last_updated or last_changed, depends on what you are looking for

{{ ((as_timestamp(now()) - as_timestamp(states.YOURSENSOR.last_changed))  / 60) |  int  }}
1 Like

Yes I think this is the one as it’s value remains the same and won’t go to unavailable

Depends if it is just the state that you are looking at :slight_smile:

I tried the template but it doesn’t work for me as the value for {{states.solar_battery_power.last_changed}} is equal to None when it obviously should be 4 mins:
image

pols click on the sensor and show me the info that then shows on the top

It should be

{{ states.sensor.solar_battery_power.last_changed }}

Yes that was it, missing the sensor part :slight_smile:
Thanks

Basically, you want a “stale sensor” detector. I provided an example here: