Upgrade from Ubuntu 20.04 to 22.04 broke ZHA with Conbee II using kvm virsh

Hi all,
This post is to give a solution to a problem I’ve had, and many hours spend on fixing it. I googled the internet thin, and while I could find people with similar issues, I couldn’t find anyone with exactly my problem. This post is to help the next person searching a solution for this problem. :slight_smile:

My setup before things broke.

Errors I was getting:
(I unfortunately don’t have the full error log anymore :confused: )

  • ZHA giving the error “Failed to set up”
  • asyncio.exceptions.CancelledError
  • asyncio.exceptions.TimeoutError
  • Couldn’t start deCONZ = dresden elektronik deCONZ protocol: ConBee I/II, RaspBee I/II coordinator
  • ERROR (MainThread) [homeassistant.config_entries] Error setting up entry ConBee II for zha
  • Error setting up entry ConBee II for zha

Symptoms:

  • I could see that ZHA would simply fail to start on integrations page.
  • I tried deleting ZHA integration, and then reboot. Home assistant would auto discover ZHA, and prompt setup. When I then attempted the setup, it would give me the error: “Failed to probe the usb device”

My virsh config: (virsh edit hassos)

<domain type='kvm'>
  <name>hassos</name>
  <uuid>1f91815b-f1b9-4c94-91ae-ae839ff9609d</uuid>
  <memory unit='KiB'>1572864</memory>
  <currentMemory unit='KiB'>1572864</currentMemory>
  <vcpu placement='static'>3</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-bionic'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/hassos_VARS.fd</nvram>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-model' check='partial'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/hassos-vm/hassos.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <interface type='bridge'>
      <mac address='52:54:00:2e:45:91'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x1cf1'/>
        <product id='0x0030'/>
      </source>
      <address type='usb' bus='0' port='1'/>
    </hostdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
</domain>

Solution
First shut off home assistant.

virsh shutdown hassos

(Where hassos if your VM’s name)
Then:

virsh edit hassos

Turns out I had to remove the following from my virsh config:

    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x1cf1'/>
        <product id='0x0030'/>
      </source>
      <address type='usb' bus='0' port='1'/>
    </hostdev>

And instead paste this in its place:

    <serial type='dev'>
      <source path='/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2419374-if00'/>
      <target type='usb-serial' port='1'>
        <model name='usb-serial'/>
      </target>
      <address type='usb' bus='0' port='4'/>
    </serial>

I could find the source path by running:

ls -l /dev/serial/by-id/ 

Now, start hassos again.

virsh start hassos. 

Then, SSH to your home assistant VM. I use the “SSH & Web Terminal” add-on.

Now check what the “source path” is called in home assistant, by running the following in home assistant VM terminal.

ls -l /dev/serial/by-id/ 

For me it was called:

usb-QEMU_QEMU_USB_SERIAL_1-0000:00:03.7-4-if00-port0

Now edit:

/root/config/.storage/core.config_entries

And update the ZHA configuration to this new source path.
Mine looks like this:

"entry_id": "0292a6eeceb2792928417059c5498c34",
        "version": 3,
        "domain": "zha",
        "title": "ConBee II, s/n: DEXXXXX - dresden elektronik ingenieurtechnik GmbH",
        "data": {
          "radio_type": "deconz",
          "device": {
            "path": "/dev/serial/by-id/usb-QEMU_QEMU_USB_SERIAL_1-0000:00:03.7-4-if00-port0"
          }

Now don’t restart, but shut off and on.

virsh shutdown hassos
virsh start hassos

That’s it, this fixed it for me!

Please let me know if this helped you, so I know whether or not making a post like this would be helpful in the future :slight_smile:

3 Likes

I had a similar issue after a power cut. I ended up moving ZigBee to a deCONZ docker container outside the HA VM.

I just bought a new ZigBee coordinator (a PoE version so I can avoid having to pass it to a VM), so probably won’t try this solution. But if I had seen this a few months ago, I certainly would have.

That’s just to say, I think it is very helpful to share, thanks a lot!

1 Like

Thanks for the tip.

I had been using a socat bridge between the host and the VM to work around this problem but that was quite brittle and annoying to keep working.

1 Like