Fix for ZwaveJS USB disconnects (libvirt)

The latest ZwaveJS addon (0.1.46) added soft-resetting the USB stick on startup which causes USB passthrough to be disconnected from the VM for some hypervisors. There’s currently not a configuration option to disable this on the main ZwaveJS addon. You can roll back to the older version to get it working, or you can follow these instructions to tell udev to automatically reattach the USB to the VM.

I’m on Ubuntu Server 20.04 with libvirt (KVM) as the hypervisor. I’d imagine there’s a way to script this on ProxMox as well, but I’m not super familiar with it.

When ZWaveJS soft-resets the USB it triggers removing and re-adding the device on the host. With udev rules we can tell udev to automatically add the device back to the VM. You’ll need to create two files. The examples below are for a VM named “hassos” and the “Aeotec Z-Stick Gen5”. Replace the VM name and USB vendor and product ids with your own.

/opt/zwave-passthrough.xml (you can place this elsewhere, if you’d like):

<hostdev mode="subsystem" type="usb">
  <source>
    <vendor id="0x0658"/>
    <product id="0x0200"/>
  </source>
</hostdev>

This is a libvirt configuration snippet. Replace the vendor and product with your USB stick’s (from lsusb).

Next, create the rule at /etc/udev/rules.d/10-zwave-passthrough.rules:

ACTION=="add", \
    SUBSYSTEM=="usb", \
    ATTRS{idVendor}=="0658", \
    ATTRS{idProduct}=="0200", \
    RUN+="/usr/bin/virsh attach-device hassos /opt/zwave-passthrough.xml"
ACTION=="remove", \
    SUBSYSTEM=="usb", \
    ATTRS{idVendor}=="0658", \
    ATTRS{idProduct}=="0200", \
    RUN+="/usr/bin/virsh detach-device hassos /opt/zwave-passthrough.xml"

Again, replace the VM name (hassos) and vendor and product ids with your own.

Now reload your udev rules (sudo udevadm control --reload-rules).

As the add-on has probably reset your device and removed it from the VM, you’ll either need to reboot the VM or run from the server /usr/bin/virsh attach-device <your-vm> /opt/zwave-passthrough.xml to reattach it the first time.

Now just start/restart the add-on and it should start successfully. If you run sudo udevadm monitor on the host, you should see the device get removed and re-added during the process. Good luck!

5 Likes

Thank you so much I have been trying to get my zwave to work for the last day or two and this is exactly what I was looking for. I made an account just to say thank you.

Thank you @korylprince ,

I were forced to revert to v. 0.1.45 to get my Aeotec Z-Stick Gen5 working again.

Being a absolute beginner in HA i think i’ve made a stupid mistake. I hard reseted my Aeotec Z-Stick Gen5 and now all my z-wave entities are gone.

Please tell me if there is a way to restore them all before i start adding them manually again.

I run HASSIO in a VM in UnRaid on Ubuntu Server 20.04 with libvirt (KVM) as the hypervisor.

I will try your solution and get back to you with my progress.

Again, thank you so much and have a nice day.

Best regards
/Peter (Sweden)

Great idea ! I have Synoloy DSM, it would be so great if someone could write a such guide for DSM :slight_smile:

Hi Peter,
It’s my understanding that unless you previously backed up your Z-Stick (see Aeotec’s guide / software Z-Stick Gen5 Backup Software : Aeotec Help Desk ) you won’t be able to recover your nodes and will need to manually exclude then include each one. This is because the controller (i.e. Z-Stick) holds the node configuration, not HA.
Good luck!
~jay

1 Like

@geeknz thank you,

I guess i will bite the dust and do a fresh Hassio install. While learning and fiddeling around i’m sure there are a lot of crap in my WM so this is probably for the best.

But by now and by learning the hard way i hope i wont do the same mistakes again :slight_smile:

I will of course use the backup functions in HA but i will make a backup of my VM image in UnRaid before diving into new stuff or new updates. Also i will make a backup of my Z-Stick every now and then.

I won’t start messing with the 0.1.46 fix cause by the time i’m done rebuilding my HA i’m sure Z-Wave JS 0.1.47 will be released with the soft reset fix.

Thank you again and have a nice day.

I have no experience with Synology, but if this post is any indication, you can ssh in and follow these instructions.

Seems like the add-on will be disabling soft-reset for VMs soon, though.

1 Like

Just as a heads up, this worked fine for me for a while, but after a few restarts of ZWaveJS2MQTT it no longer reconnected automatically. Trying to manually reconnect it with virsh gave me an error of “internal error: No free USB ports.”

I’m not sure if that’s some quirk unique to my system or what, but I’m just going to leave soft reset off. I guess the standard says it’s required, but my network has been working fine for years without it.

I see that Z-Wave JS 0.1.47 has been released today with a fix …

image

1 Like

@ImSorryButWho it sounds like maybe the removal rule is not configured correctly and the usb passthroughs are building up (you can only have 6 passthroughs by default).

I’ve restarted the add-on 10+ times without any issues.