-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
This card and the features it provides is brilliant!!
However, when I first came across it, I almost ignored it because it was focused on Z2M and I use ZHA. It was only by continued research that I found a discussion thread that gave additional details, which I then had to update.
It would be great if the README could be extended to provide clearer instructions for ZHA users. I'm happy to assist if you are interested.
The ZHA version of the sensor template I use is:
- sensor:
- name: "ZHA Devices List"
state: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
attributes:
nodes: >
{% set ns = namespace(output=[], ieee_names={}) %}
{% for entity_id in integration_entities('zha') %}
{% set did = device_id(entity_id) %}
{% if did %}
{% for id_pair in device_attr(did, 'identifiers') | default([], true) %}
{% if id_pair[0] == 'zha' and id_pair[1] not in ns.ieee_names %}
{% set ns.ieee_names = dict(ns.ieee_names, **{id_pair[1]: device_attr(did, 'name_by_user') or device_attr(did, 'name')}) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% for device in trigger.event.data.devices %}
{% set current = {
'ieeeAddr': device.ieee,
'friendly_name': ns.ieee_names.get(device.ieee, device.friendly_name),
'type': device.device_type,
'networkAddress': device.nwk
} %}
{% set ns.output = ns.output + [current] %}
{% endfor %}
{{ ns.output }}
links: >
{% set ns = namespace(output=[]) %}
{% set relationships = {
'None': 0,
'Child': 1,
'Sibling': 2,
'Parent': 3,
'Neighbor': 4
} %}
{% set relationship = 0 %}
{% for device in trigger.event.data.devices %}
{% for neighbor in device.neighbors %}
{% set current = {
'source': {'ieeeAddr': device.ieee },
'target': {'ieeeAddr': neighbor.ieee},
'lqi': int(neighbor.lqi),
'relationship': relationships.get(neighbor.relationship)
} %}
{% set ns.output = ns.output + [current] %}
{% endfor %}
{% endfor %}
{{ ns.output }}
trigger:
- trigger: event
event_type: "zha_device_list"
The automation created to update the ZHA list is:
alias: ZHA Device List Refresh
description: ""
triggers:
- trigger: time_pattern
hours: "*"
minutes: "10"
seconds: "0"
conditions: []
actions:
- action: zha_toolkit.zha_devices
data:
event_success: zha_device_list
mode: single
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels