Sensor hasn't updated for

Ok searching through the board i’ve found a simple solution.like below to be notified if a sensor hasn’t updated for XXX minutes/hours/days.
But keeping a long long list of all the sensors is quite cubersome. Maybe there is a simplier solution currently? Groups is not an option as i understand

- id: notify_sensor_offline
  alias: Notify Sensor Offline
  description: "Сенсор не обновлялся более"
  trigger:
    - platform: state
      entity_id: sensor.living_room_temperature_1
      for: '00:10:00'
    - platform: state
      entity_id: sensor.outside_temperature
      for: '00:10:00'
    - platform: state
      entity_id: sensor.bedroom_temperature
      for: '00:10:00'
    - platform: state
      entity_id: sensor.kitchen_temperature
      for: '00:10:00'
  action:
  - service: notify.telegram
    data_template:
      message: "{{ trigger.from_state.attributes.friendly_name }} has not updated since 10 min"
- id: notify_sensor_offline
  alias: Notify Sensor Offline
  description: "Сенсор не обновлялся более"
  trigger:
    - platform: state
      entity_id:
      - sensor.living_room_temperature_1
      - sensor.outside_temperature
      - sensor.bedroom_temperature
      - sensor.kitchen_temperature
      for: '00:10:00'
  action:
  - service: notify.telegram
    data_template:
      message: "{{ trigger.from_state.attributes.friendly_name }} has not updated since 10 min"

Petro, thanks but i meant the list to get automatically populated with all the sensor entities.

There’s no quick or easy way to do that.

A list of sensors (specifically: does not include binary sensors, for example) that has not had an update in the last ten minutes:

{{ states.sensor|selectattr('last_updated','<',now()-timedelta(seconds=600))|map(attribute='entity_id')|list }}

Paste that into the template editor to see what it gives for you.

What you then do with that is a bit trickier, as it likely exceeds the 255-character limit of a sensor state. Also, you’d need to evaluate it on a regular basis which would be inefficient.

You could maybe have a sensor that stores the entity_id of the sensor with the most recent update time over ten minutes:

template:
  - sensor:
      - name: Sensor most recently over 10 mins
        state: "{{ states.sensor|selectattr('last_updated','<',now()-timedelta(seconds=600))|sort(attribute='last_updated')|map(attribute='entity_id')|reverse|first }}"

…which will change whenever a sensor exceeds the 10 minutes threshold. Then trigger off that sensor changing and send a notification.

- id: notify_sensor_offline
  alias: Notify Sensor Offline
  description: "Сенсор не обновлялся более"
  trigger:
    - platform: state
      entity_id: sensor.sensor_most_recently_over_10_mins
  action:
    - service: notify.telegram
      data_template:
        message: "{{ states[states('sensor.sensor_most_recently_over_10_mins')].attributes.friendly_name }} has not updated for 10 min"

Missing the curly brackets in your template sensor Troon.

1 Like

Thanks, fixed.

That’s quite a brillian solution! Thank you. Will give it a try and see how it goes