Zwave scene event automation using the node id of the event to get the friendly name of the device

Let me start with saying I am not a Yaml or jinja expert, although I have learned a lot in the last week trying to work my way through this.

What I am trying to accomplish:
Respond to a push on a zwave light switch, with an action based on the light switch that was activated. So not 1 automation per light switch, but 1 automation for scene 001 events that is smart enough to know what device it is. My back ground is in programming in C++, and I keep banging my head on things I think I should be able to do and can’t figure out how to do it.

Current environment:
Running HA in a VM in Proxmox
Core 2025.2.4
OS 14.2
Zwave Driver version 134.3.7
Server Version: 1.40.2

What I have tried: (please don’t laugh too hard)
Started by looking at blueprints and making 1 big blueprint that did the complete lighting automation. I was able to make that work, but had to create so many helpers, and so many input variables that I was not happy with the results.

Tried to create a sensor template with the output being the node/name list, but it went over the 255 limit.

Tried to figure out how to make a trigger action template, but couldn’t get it to work.

Did a lot of searching on how to get from and zwave event to the friendly name for a node or device id. Found some great jinja that generated a dictionary with the node id and friendly name and added the steps to check on a specific node id, and got it working in the developers template area.

{% set ns = namespace(name = "none") -%}
{% set ns = namespace(found_node = false) -%}
{%- for dev_id in integration_entities('zwave_js') | map('device_id') | unique -%}
    {% if (device_attr(dev_id, 'identifiers') | first | last).split('-')[1]  == '84' -%}
      {% set ns.name = device_attr(dev_id, 'name_by_user') or "" -%} 
      {% set ns.found_node = true -%}
    {% endif -%}
{% endfor -%}
{{ns.found_node}}
{{ ns.name }}

This worked giving me ns.found of true, and ns.name with the friendly name associated with that node id.
1st issue. When I change the ‘84’ to a node id that was not in use like 400, ns.found became False, but I got a jinja error on the final {{ ns.name }}
“‘jinja2.utils.Namespace object’ has no attribute ‘name’”
I would have expected it to be ‘none’ as the node is not found in the if statement, I didn’t change ns.name at all in the for or if loops.
2nd issue: I then tried to create a namespace for the node_id.

{% set ns = namespace(name = "") %}
{% set ns = namespace(node_id = "84") %}
{% set ns = namespace(found_node = false) %}
{%- for dev_id in integration_entities('zwave_js') | map('device_id') | unique %}
    {% if (device_attr(dev_id, 'identifiers') 
      | first | last).split('-')[1]  == ns.node_id %}
      {% set ns.name = device_attr(dev_id, 'name_by_user') or "" %} 
      {% set ns.found_node = true %}
    {% endif %}
{% endfor %}
{{ ns.found_node}} {{ns.name}}

I tried combinations of integers and strings for the namespace and the left side of the equation but all resulted in the node id not being found.

I also tried putting this in the condition statement of the automation and using variables, still with the same results. Any help would really be appreciated.

A Z-Wave event includes the device_id in the event data.

A state trigger for the event entity includes the entity ID, from which you can get the device_id from using the device_id(entity_id) template helper. https://www.home-assistant.io/docs/configuration/templating/#devices

So in either case there’s no need to lookup node ID. But maybe I don’t quite understand what your goal is.

I have been using the event trigger which gives a device id. I could use that to search through all the zwave nodes for the device name instead of node id but I think that would just give me the same problems.

I will look at the state trigger and see if that helps. Or i guess I could just use the device id directly and not use the friendly name at all, just makes things harder to debug etc. but would be a lot easier.

What I am trying to accomplish is to get a automation triggered on any button push on any of my in wall switches, and then take the appropriate action on the correct light switch.

I want to thank you Freshcoast because I have used a lot of your posts in trying to sort this out btw.

Ok, I looked at the state trigger and as far as I can tell I would have to make a list of all my wall switches in the entity id part of the trigger. I had looked at that before and I was trying to avoid that, but maybe I have no choice.

Wouldn’t you need to do that regardless of which trigger you are using?

Well i was thinking I could use the node id or device id from the event trigger to search through the zwave entities and find the friendly name and use it in the actions. Is that just not worth doing? I have about 35 + wall switches.

Actions don’t take “friendly names” as input though, they use entity or device IDs (or areas).

I use consistent names, can get from friendly name to entity_id. But I think what I’m hearing from you is i’m making this too complicated, just do the state change event

In my opinion going from device ID / node ID to friendly name, and then searching all devices for a friendly name is way over-complicated, when you can just use consistent entity IDs instead. Basically then all you need is a lookup table from device ID / node ID to entity ID.

It doesn’t really matter whether you use an event, or the state trigger for an event entity. To clarify, I’m talking about the zwave_js_value_notification event, not the generic state_changed event.

If you want to use node IDs the z-wave event is easier since it’s part of the event payload. Using the event entity state trigger you’d need to extract the node ID from the entity/device’s unique ID with template code, but getting the device ID from the template helper is trivial.

I might even keep it simpler, just map event entity ID to light entity ID and use the event entity state trigger. Then you don’t care about node IDs or device IDs. That would also be immune to future device replacements as long as you kept the entity IDs the same.

I don’t bother with this kind of logic, I just have a Blueprint and duplicate the automation for every device. Except I’m not trying to automate 35 of them, it’s only about 5.

i get your point on friendly name, I use the zwave_js_value_notification event.
I may be wrong, but i think that I could easily change the jinja above to give me a device_id to entity_id table, but I think I would still run into the same problems in getting variable input into the search so I could find the right entity_id. Am I misunderstanding you?

when you say event entity state trigger you mean use a state trigger on the
event.laundry_room_scene_001 entity id? or something different. If so that would mean listing the entities ids for all the items again wouldn’t it or do I not understand.

Still working my way through the rest…

Really appreciate all your help, just this is new enough to me, I am having to work through it to understand it. Guess I shouldn’t have tried to make an automation that could be be all things to all devices without some more ground work on my part.

Can you provide an example of the input variable you want to use in your automation? Maybe I’m missing something. In order to tell HA to turn on the light for a given button, you need to tell HA which button maps to which light.

I don’t understand why you’d want to search all devices for a friendly ID every trigger instance instead of just using an entity ID.

I was thinking I would trigger on zwave js value notification event for scenes.
Then use the device_id as to search through the zwave devices to get to an entity id. If i just go with an approach with triggering on a list of entity ids all this becomes easy so i’ll just go that route and go modify my blueprint. Appreciate all your help.

Are the button and the light the same device? I think I missed that.

If that’s the case you don’t need to search for anything, just toggle the light with the device_id that triggered it. That’s what I do at https://community.home-assistant.io/t/zwave-js-ge-jasco-honeywell-double-taps/280891#auto-dimming-blueprint-2.

I have been making this way too hard. Using the device_id makes it all simple. Sorry it took me so long to figure that out.