Automation trigger for ANY device under ZHA?

I’d like to create an automation to let me know when ANY Zigbee device becomes unavailable/becomes available again after having been unavailable.

Is there a way to create an automation that triggers on any device under ZHA/under a specific integration, without manually labeling them or adding them to a group?

Thanks!

Currently, you can’t do it in an automation alone.

You might be able to create a template sensor that counts the number of offline devices and trigger off that. However, most templating is based around entities, not devices. I don’t think there are any device attributes that will directly indicate that a device is unavailable.

I believe all Zigbee devices expose an “Identify” button entity which becomes unavailable when the device becomes unavailable.

Then, as long as you don’t disable them, you could set up a template sensor with the following state template:

{{ integration_entities('zha')
| select('search', 'button.*identify')
| select('is_state', 'unavailable')
| list | count }}

Then you would trigger off that sensor:

triggers:
  - trigger: state
    entity_id: sensor.zigbee_offline_count
    not_to:
      - unknown
      - unavailable
    not_from:
      - unknown
      - unavailable
conditions:
  - "{{ trigger.to_state.state | int(0) > trigger.from_state.state | int(0) }}"
actions:
  # Your action sequence

Thanks! Your idea worked.

I ended up going with just a ‘friendly’ list of unavailable device names and configured an alert whenever the list changes…

{{ integration_entities('zha')
| select('search', 'button.*identify')
| select('is_state', 'unavailable')
| list
| join(', ')
| replace('button.', '')
| replace('_identify', '') }}

Thanks for your help!