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.