Home Assistant in Docker - pass USB device from host

Hi, Im having issues using USB devices in Home Assistant, which I have running in Docker. I can see the USB device on the host (Ubuntu 18.04 server), but Home Assistant doesnt seem to see it.
I see a few people saying start the container with some extra flags, if this is the issue, but how do you go about that please?

Kind regards.

1 Like

Here’s my docker-compose.yaml:

version: '3'
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/raspberrypi3-homeassistant:stable
    volumes:
    - /home/pi/.hass:/config
    devices:
    - /dev/ttyUSB0:/dev/ttyUSB0
    - /dev/ttyUSB1:/dev/ttyUSB1
    - /dev/hidraw0:/dev/hidraw0
    - /dev/hidraw1:/dev/hidraw1
    environment:
    - TZ=America/Chicago
    restart: unless-stopped
    network_mode: host

The devices: section passes my USB devices from the host to the container. If you’re using a docker run command, then add the --device flag with the appropriate devices: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities

3 Likes

I followed this guide, so I dont run any docker run command:
https://www.juanmtech.com/set-up-hassio-in-docker-and-in-an-ubuntu-server/
It runs automatically on boot.

Oh boy, that video…
Anyway, using the official documentation is the way to go: https://www.home-assistant.io/hassio/installation/#alternative-install-home-assistant-supervised-on-a-generic-linux-host

But… the devices should be passed through since I believe the Supervised install methods run the home assistant container in privileged mode. However, if you connect the device when home assistant is already running it won’t be passed through. You’ll need to restart home assistant or possibly reboot the host before it’s passed through.

1 Like

And, just to check…
I am running this on a KVM VM, so is the above method the preferred way to run on Linux (ubuntu), in docker, or is there a more ‘native’ method?

If anyone tries to do this on a Raspberry Pi 4, here’s how I got HA in a docker container to access my USB Bluetooth adapter

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    # The dbus volume is essential to make bluetooth work
    volumes:
      - /docker/ha/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro # Essential
    environment:
      TZ: Pacific/Auckland
    restart: unless-stopped
    # Setting privileged to true gives the container full access to all host devices including USB
    # This is convenient but may not be ideal
    # https://robertjandegroot.wordpress.com/2021/01/03/adding-usb-devices-to-your-containers/
    privileged: true
    network_mode: host