Copying device names into Z-Wave JS UI

Today I switched (upgraded? side-graded?) from “Z-Wave JS” to “Z-Wave JS UI”.
So far I really like it. I’m glad I switched. I’m hoping it is the first step in diagnosing some really strange zwave issues I have been having. Anyway…

After the migration, the Z-Wave JS UI shows all my devices and everything is working at least as well as it was before. But… in the UI, they are missing the Name / Location information.

I understand that the Z-Wave JS UI is a separate thing from HA, and isn’t aware of HA or the names of my devices in HA… no problem.

But, I was wondering… is there a way to mass-export the names (&locations) from HA, and then import them into Z-Wave JS UI?

Or do I have to manually copy-paste all those names by hand?

Here’s something I quickly wrote up, after seeing this requested many times. Let me know how it goes if you try it.

Copy and paste this code into the Dev Tools Template editor:

{%- set ns = namespace(nodes=[], export={}) %}
{%- for dev_id in integration_entities('zwave_js') | map('device_id') | unique %}
  {%- set node_id = (device_attr(dev_id, 'identifiers') | first | last).split('-')[1] %}
  {%- set ns.nodes = ns.nodes + [(node_id | int, dev_id)] %}
{%- endfor %}
{%- for node_id, dev_id in ns.nodes | sort(attribute='0') %}
  {%- set node = {(node_id | string): {}} %}
  {%- set name = device_attr(dev_id, 'name_by_user') %}
  {%- set location = area_name(dev_id) %}
  {%- if name and location %}
    {%- set node = {(node_id | string): {"name": name, "loc": location}} %}
  {%- elif name %}
    {%- set node = {(node_id | string): {"name": name}} %}
  {%- elif location %}
    {%- set node = {(node_id | string): {"loc": location}} %}
  {%- endif %}
  {%- set ns.export = dict(ns.export.items(), **node) %}
{%- endfor %}

{{ ns.export | to_json }}

It will output a JSON object in the format ZUI uses for node name and locations backups. Save the template output to a file named nodes.json (or whatever you want).

In Z-Wave JS UI, go to the Control Panel, click the blue FAB (floating action button), Advanced Actions, then IMPORT under the Backup section. Pick the file created above.

image

In the future, to keep both applications in-sync always add nodes from ZUI, as it allows you to pre-configure names and locations before including a node. During inclusion, HA will see the pre-configured values.

1 Like

Perfect!

Thanks, that did precisely what I needed. :slight_smile:

I really appreciate it.
And the advice to add new devices via the UI. Sounds like a lean solution. Will do!

1 Like

Thank you. That was a perfect fix.

1 Like