Trigger on state change of any entity

Could someone please help to write an automation to trigger whenever any of the 500 entities i have become unavailable for 30 seconds or more. I cant seem to find any info on how to do this. i thought maybe with trigger event on state_changed but i have no idea how to do something like this.

Could someone help me with this.

Use that one, it will update once every 60 seconds.

1 Like

Cool. Never realized you could actually enumerate all entities via “states”.

Very useful. Here’s another example where I use the same method to create a binary sensor that tells me if there is any open doors with a list of them as an attribute.

- binary_sensor:
    - name: Open Doors
      unique_id: door_open
      icon: "{{ 'mdi:door-open' if is_state('binary_sensor.door_open','on') else 'mdi:door' }}"
      state: "{{ states.binary_sensor|selectattr('attributes.device_class','eq','door')|selectattr('state','eq','on')|list|count > 0 }}"
      attributes:
        entities: "{{ states.binary_sensor|selectattr('attributes.device_class','eq','door')|selectattr('state','eq','on')|map(attribute='entity_id')|list }}"
2 Likes