Notification with all the "choose" true actions

Here’s a template that outputs a list of all humidity sensors in your house which haven’t had a state change in the last 4 hours.

{{ states.sensor
    | selectattr('attributes.device_class', 'eq', 'humidity')
    | selectattr('last_changed', 'lt', now() - timedelta(hours=4))
    | list
}}

Or if you don’t want to use device_class to find these and you want to use a fixed list then can try this:

{% set sensors = [
  "sensor.broadlink_bedroom_humidity",
  ...(list all humidity sensors)...
] %}
{{ states.sensor
    | selectattr('entity_id', 'in', sensors)
    | selectattr('last_changed', 'lt', now() - timedelta(hours=4))
    | list
}}

Either way there’s really no reason to use any chooses here. Just collect all the broken sensors with a template and notify about them.

Last August, I helped someone else with an almost identical requirement. They wanted to detect “stale sensors” (any sensor whose value hasn’t been updated in the last hour or 4 hours or whatever time period you prefer).

It demonstrates the principal with a few template examples (all similar to what CentralCommand posted). It applies the technique in an automation that runs every 4 hours and checks if any sensors failed to update during the past 4 hours. If it finds stale sensors, ot reports their entity_id via a notification.

Basically, it does most everything you require, without the complexity of the choose you intended to employ.

1 Like

Thank you. I will try to adapt the code to my requirements, because I don’t use the default “last_change”, I made some variables where I store the last change, in order to keep the data after HA restart.

I made it, Thank you again!