Resolve Z-Wave Node ID from Entity

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)




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.


If you use ZWaveJS UI there is an option called Replace Failed Device. It allows you to swap a device and it keeps that same NODE ID. You can find it in the same place as the Inclusion button. It will try and ping the node first to see if its alive and if it doesn’t respond then it will let you replace the device.

Let me clarify -The node could not be replaced - there were other extraneous circumstances. This is not a valid workaround. I am looking to improve the automations to be self sufficient and not care. Thank you though. :slight_smile:

1 Like