Win 10 Docker Desktop + Zigbee Success Story

Wanted to post a successful deploy I had after struggling (along with seeing other folk’s post issues trying with a similar setup) hope if anyone thats trying similar things, comes across this and finds it helpful!

I am running Docker Desktop on Windows 10 with HAS running in a container, with a sonoff zigbee dongle that is successfully interfacing with a few sonoff temp sensors and ikea smart plugs. A huge issue i see and had is that Docker Desktop does not allow USB passthrough. I found a work around that if you share the USB through WSL (my default is the docker-desktop wsl, you might have to specify dd if its not your default) and then share it in your container, HAS will see it and be able to use it.

in a privledged powershell

usbipd list
usbipd bind --busid <busid of your zigbee dongle>
usbipd attach --wsl --busid <busid of your zigbee dongle>

then in your wsl you can see it under /dev I update my perms just in case chmod 666 /dev/ttyUSB0 and you should see it in lsusb as well.

Heres my docker compose.yaml I deploy from docker compose up -d

version: '3'
services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: home-assistant
    privileged: true
    volumes:
      - home-assistant-config:/config
    ports:
      - "8123:8123"
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    restart: unless-stopped
    environment:
      - TZ=America/Denver

volumes:
  home-assistant-config:
    external: true  # Reference existing volume

I have seen on Windows restarts that I lose connection to the zigbee dongle. I dont have a self healing solution (yet), but have success repeating the usbipd attach, chmod, and reloading my container docker compose up -d

1 Like

Here’s a super lazy way of achiving this.

Once you know the bus ID, make a .bat file with the following:

usbipd attach --wsl --busid <busid of your zigbee dongle>

I do this with notepad++, I hit saveas, change the file type to batch file, and saved it in my user folder.

In that user folder I right clicked the .bat file, created a shortcut, and placed this in my startup folder by pressing Win+R and typing “shell:startup” and putting the shortcut here.

For my docker launch file it looks like this:

Start-Sleep -Seconds 30; docker run -d `
  --name homeassistant `
  --privileged `
  --restart=unless-stopped `
  -e TZ=Europe/London `
  -v "C:\Home Assistant\config:/config" `
  --device /dev/ttyUSB0 `
  -p 8123:8123 `
  homeassistant/home-assistant:stable

Paste the above in to Powershell (delete your previous container if you already have one) and you’re away. The USB device will attach when your PC launches and very lazily I have the docker container start 30 seconds after launch to ensure it binds first. I know this is a bit of a hack but it does solve your problem.