Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Last active June 1, 2026 13:27
Show Gist options
  • Select an option

  • Save Geek-MD/fabe75d2db008cf4a91ecc1b07f205f2 to your computer and use it in GitHub Desktop.

Select an option

Save Geek-MD/fabe75d2db008cf4a91ecc1b07f205f2 to your computer and use it in GitHub Desktop.
ZHA - Auto rejoin unavailable Zigbee devices
blueprint:
name: ZHA - Handle Join for selected unavailable Zigbee entities
description: >
Monitors selected ZHA entities. When any selected entity remains unavailable
for a configured time, this blueprint triggers the ZHA Toolkit Handle Join
action for the specific entity that became unavailable.
Requirements:
- Home Assistant with ZHA integration
- ZHA Toolkit installed and available
Notes:
- This blueprint filters the selector to ZHA entities.
- It passes the triggering entity_id as the ZHA Toolkit device reference.
- Before using it, verify that the ZHA Toolkit service exists under
Developer Tools > Actions / Services.
domain: automation
input:
target_entities:
name: Zigbee entities to monitor
description: >
Select one or more ZHA entities to monitor. If any selected entity
becomes unavailable and remains so for the configured time, Handle Join
will be triggered for that specific entity.
selector:
entity:
multiple: true
filter:
- integration: zha
unavailable_for:
name: Time in unavailable state before acting
description: >
How long the entity must remain unavailable before triggering the action.
default: "00:05:00"
selector:
duration: {}
cooldown_minutes:
name: Cooldown between executions
description: Prevent repeated executions in a short time window.
default: 30
selector:
number:
min: 1
max: 1440
step: 1
unit_of_measurement: min
mode: box
write_logbook:
name: Write to logbook
description: Log when the automation triggers.
default: true
selector:
boolean: {}
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: !input target_entities
to: "unavailable"
for: !input unavailable_for
variables:
target_entity: "{{ trigger.entity_id }}"
target_name: "{{ state_attr(trigger.entity_id, 'friendly_name') or trigger.entity_id }}"
cooldown_minutes: !input cooldown_minutes
write_logbook: !input write_logbook
condition:
- condition: template
value_template: >
{% set last = state_attr(this.entity_id, 'last_triggered') %}
{{ last is none or (as_timestamp(now()) - as_timestamp(last)) > (cooldown_minutes | int * 60) }}
action:
- if:
- condition: template
value_template: "{{ write_logbook }}"
then:
- action: logbook.log
data:
name: "ZHA Rejoin Blueprint"
message: >
Entity {{ target_name }} became unavailable.
Triggering ZHA Toolkit Handle Join.
entity_id: "{{ target_entity }}"
- action: zha_toolkit.handle_join
data:
ieee: "{{ target_entity }}"
- if:
- condition: template
value_template: "{{ write_logbook }}"
then:
- action: logbook.log
data:
name: "ZHA Rejoin Blueprint"
message: >
Handle Join executed for {{ target_name }}.
entity_id: "{{ target_entity }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment