Cloning the Z-Wave JS to MQTT Add-On to run multiple Z-Wave Networks

So, I recently decided the best solution to keep a good Z-Wave mesh was to have a second Z-Wave network for the energy meter that generate tons of traffic and also a couple of old non-plus devices which may cause trouble…

I already had 2 UZB-7 sticks and they are cheap anyways so I searched the forums for the best way to do this and found other people have done it in difference ways (using the core Z-Wave JS add-on for the second network, manually creating a container for the second Z-Wave JS 2 MQTT outside HA, having a second HomeAssistant installation and getting them to talk to each other using MQTT or some HA to HA communication add-on, etc.). None of these are ideal so after some research and testing I found a way to clone the zwavejs2mqtt add-on inside Home Assistant which is working great for me and wanted to share with the community for feedback and in case someone else is looking to do the same thing.

Benefits:

  • Single Home Assistant Installation, no messing around with HA to HA communication, MQTT, etc.
  • Both ZWaveJS2MQTT are fully managed and integrated inside HA
  • Both original and clone add-on updates are detected and can be safely updated (or auto-updated) from HA
  • No need to manually manage external docker containers, etc.

I run HA in supervised mode in a Raspberry Pi 4 (64-bit) with latest Raspberry OS (bullseye). Cloning the module is simple, this is what I did:

  1. Copy the module from the community addon repository into the local addon folder:
repo="git/a0d7b954"
addon="zwavejs2mqtt"
cloneid="2"
sudo cp -r /usr/share/hassio/addons/$repo/$addon /usr/share/hassio/addons/local/$addon$cloneid
sudo chown -R pi /usr/share/hassio/addons/local/$addon$cloneid
  1. Created a bash script ~/homeassistant/update_local_addon_clones.sh to check for updates and update the clone if a newer version is found, this script also adds the clone number to the add-on name, panel title and slug so it is easily identifiable and does not conflict with the main one:
#!/bin/bash
repo="git/a0d7b954"
addon="zwavejs2mqtt"
cloneid="2"

sourceVersion="$(grep -F "version:" /usr/share/hassio/addons/$repo/$addon/config.yaml)"
sourceSlug="$(grep -F "slug:" /usr/share/hassio/addons/$repo/$addon/config.yaml)"
targetVersion="$(grep -F "version:" /usr/share/hassio/addons/local/$addon$cloneid/config.yaml)"
targetSlug="$(grep -F "slug:" /usr/share/hassio/addons/local/$addon$cloneid/config.yaml)"

if [ "$sourceVersion" != "$targetVersion" -o "$sourceSlug" = "$targetSlug" ]
then
        cp -r /usr/share/hassio/addons/$repo/$addon/* /usr/share/hassio/addons/local/$addon$cloneid

        sed -i "s/^name:.*$/& $cloneid/g" /usr/share/hassio/addons/local/$addon$cloneid/config.yaml
        sed -i "s/^panel_title:.*$/& $cloneid/g" /usr/share/hassio/addons/local/$addon$cloneid/config.yaml
        sed -i "s/^slug:.*$/&$cloneid/g" /usr/share/hassio/addons/local/$addon$cloneid/config.yaml
fi
  1. Execute the script the first time and add a cron job to run the script every hour
chmod +x ~/homeassistant/update_local_addon_clones.sh
bash ~/homeassistant/update_local_addon_clones.sh
crontab -e            (Add the following line at the end)
0 * * * * bash /home/pi/homeassistant/update_local_addon_clones.sh
  1. Install the new module:
    4.1. Go to HomeAssistant / Configuration / Add-ons, Backups & Supervisor
    4.2. Click on ADD-ON STORE button
    4.3. Click on the dots at the top right corner and “Check for updates”
    4.4. The new local module should now show up at the top, install it.
    4.5. In the module configuration enable “Start on boot”, “Watchdog” and “Show in sidebar”

  2. Configure the new “Z-Wave JS 2” in the side panel to use the second USB stick, you can get the address of the second stick by running ls /dev/serial/by-id/, you should now see the stick in the device list.

  3. Add the second Z-Wave JS Integration
    6.1 Go to Configuration / Devices & Services
    6.2 Ignore the newly discovered Z-Wave device, if you add it this way it will install the Core Z-Wave JS add-on.
    6.3 Click on Add Integration and add Z-Wave JS
    6.4 Uncheck “Use the Z-Wave JS Supervisor add-on”
    6.5 Use the following URL: ws://local-zwavejs2mqtt2:3000
    6.6 Rename the new integration to “Z-Wave JS 2”

  4. Profit!

image

I guess this method could be used to create more than 1 clone or clone any other add-on as needed.

1 Like

I am using HomeAssistant OS rather than Supervised. Any idea how to do this under my setup? Thanks.

Sorry, I didn’t noticed there was a reply to this thread.

Honestly I have never used HomeAssistant OS and although it should be pretty much the same concept (copying the add-on repo into a new local add-on repo) I don’t really know the details of the file structure in that install, my understanding is that in HomeAssistant OS you don’t even have SSH access? I may be wrong…

In any case, I actually improved this a lot since, in my setup it is no longer an OS cron job, now I just use a Home Assistant Shell Command to execute the above bash script using SSH to the host (This was a bit tricky to configure), it allowed me to add an automation that just runs the shell command whenever there is an update on the main add-on. Much more efficient and all integrated within Home Assistant vs doing it in the OS.

That said, SSH to the host is required even when doing it with a shell command as those commands are executed withing the Core docker and they are very restricted on what they can do…

Sorry I cannot help you more.

This is awesome! You’re applying VLANs to your Z-Wave network! :slight_smile:
Since you’ve been running like this for a couple of months, have you noticed any improvements by leaving the chatty devices on a separate mesh?

Technically there’s no benefit from something like this, they all use the same frequency and still have to wait for the CTS (Clear to Send) on the frequency.

There is if you want to run two zwave dongles with diff frequencies, like I plan to do. The question is my technical knowledge :face_with_monocle: :joy:

You’ll need to make sure your frequencies are legal in your country. Usually running a frequency that’s not for your country can potentially get you in a lot of trouble.

I honestly do not know the technical details of the Z-Wave protocol that well, but, yes, huge improvement! and I’ll explain why form my little understanding:

By putting the very few but necessary Z-Wave (non plus) devices I still have in a separate dongle / Z-Wave network, I have definitely improved communication for Z-Wave Plus devices around them that decide to use them as next hop in the communication. When a Z-Wave Plus uses a non Plus device to communicate through, it basically downgrades the communication protocol in order to send the message trough… This fixed a bunch of issues I was having with devices around those old ones…

I have an Aeotec Energy meter that is indeed very chatty. It is not far enough to not be able to talk to the dongle directly but there are a lot of other devices in the middle and much closer so it was always sending its messages through other devices. Maybe true the communication is still dependent on the frequency being free but now by putting this device on that second dongle I basically forced it to have to talk to the dongle directly and not through other devices, those other devices may still not be able to talk while that one is talking, sure, but they do not have to re-transmit all those messages. This indeed fixed issues I was having with both the energy meter and some devices around it…

So, yes, big difference.

1 Like