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:
- 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
- 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
- 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
-
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” -
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. -
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” -
Profit!
I guess this method could be used to create more than 1 clone or clone any other add-on as needed.