I would like to resolve a ZWave Node ID given it’s HomeAssistant Entity name.
Zwave JS / JSUI
After reviewing the forums I found this template which was offered up by others to answer a similar problem
{% set ns = namespace(devices=[]) %}
{%- for device_id in states | map(attribute='entity_id') | map('device_id') | unique | reject('eq', none) %}
{%- set identifiers = device_attr(device_id, 'identifiers') | list | selectattr('0', 'eq', 'zwave_js') | selectattr('1', 'search', '^([0-9]+)-([0-9]+)$') | list | first | default %}
{%- if identifiers %}
{%- set node = identifiers[-1].split('-')[-1] | int %}
{%- set ns.devices = ns.devices + [(node, device_entities(device_id))] %}
{%- endif %}
{%- endfor %}
{%- for node, entities in ns.devices | sort(attribute='0') %}
{{ node }}:
{%- for entity in entities %}
• {{ entity }}
{%- endfor %}
{% endfor %}
That template is CLOSE - It results in a formatted list of nodes, each with its associated entities as follows:
(partial list)
6:
button.living_room_lights_ping_2
light.living_room_lights
sensor.living_room_lights_node_status
7:
sensor.back_porch_light_node_status
light.back_porch_light
sensor.back_porch_light_humidity
button.back_porch_light_ping
8:
sensor.back_porch_fan_node_status
fan.back_porch_fan
button.back_porch_fan_ping
I could modify this template and at the point where it starts looping through a given node, I COULD check each name and compare it to the one I’m looking for and if its a match - return the result. It just SEEMS messy and when I run this template, it takes a second or two - because I have a LOT of Z-Wwave entities. (Over 90 unique Z-Wave devices)
If I read the template correctly (I’m still very novice with templates) we have the device list and the nodes at the end of the for on line 8/9 Is there a way to modify the select on line 9 to just dump out a node number if we find a given target entity ID in the list?
Preferred result - given one string input - full entity ID, produces one string representation of a number - Z-Wave Node ID or NULL if not found.
In my data above, ‘fan.back_porch_fan’ would yield ‘8’
Basically I’m tired of having to update all of my ZwaveJS service based automations and Node Red flows every time I swap out a device… Took me three days to realize I needed to edit a flow with the new node ID when I swapped out a lock that died earlier this week.
Thoughts?