Proxy Bluetooth on RBP4 to HA Container (with docker compose)

On my RaspberryPi 4 with Raspbian I am running a HA from docker image with docker compose. A lot of stuff, integration and devices are working flawlessly (including ZigBee).

I am trying now to start using Bluetooth, following Bluetooth - Home Assistant.

BlueZ is running on my host machine and /run/dbus:/run/dbus:ro added to the volumes in docker composer file, as below:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /srv/ha_config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    restart: unless-stopped
    privileged: true
    network_mode: host
    devices:
     - /dev/ttyUSB0:/dev/ttyUSB0
     - /dev/ttyACM0:/dev/ttyACM0
     - /dev/ttyAMA0:/dev/ttyAMA0
docker compose restart

`/run/dbusā€™ on my host:
image

But on the docker image the /run/dbus is still empty:
image

And of course HA Bluetooth integration is complaining:
image

Additionally
Test that BT is wokring on my host:
image

bluez service status

Did anyone manage successfully to proxy Bluetooth to HA docker container on RBP platform?

Thanks for any help!

2 Likes

I have the same issue, my setup and errors is the same, and I am able to see the Mi Flora device when scanning with bluetoothctl.

Running bluetoothd -n gives this error:

1 Like

I was searching for the same issue (ā€œRetrying setup: DBusā€¦ā€) with ā€œdocker-composeā€ and found this thread. I didnā€™t see anywhere about dbus in docker-compose (not just docker, and Iā€™m still not great with docker things). So this post helped.

I ran docker-compose up -d and it looks like itā€™s working (but I donā€™t have any bluetooth devices!).
Is it possibly as simple as not ā€œup -dā€ to recreate (vs. restarting) for you?
Thanks for your post.

3 Likes

That solved it for me

2 Likes

Glad it helped!
Docker compose is just a ā€˜wrapperā€™ over docker, so you can write down docker configuration in one .yml file, including multiple services (multiple docker images).

ā€œupā€ command creates and starts the container, ā€œ-dā€ simply detaches docker from the current process (run containers in the background).

A kind question for you - what kind of system do you have (HW/OS - Raspberry Pi 4? Raspbian?)
I understood that in your case adding /run/dbus volume was enough to get rid of startup error for Bluetooth integration in HA?
Thanks!

Well, after multiple restarts (including the whole Pi) it started working also for me.

This command might be also helpful (although I am not sure did it has any influence in my case):

sudo systemctl restart bluetooth.service

Now dbus socket is visible in the container, as expected:
image

Iā€™m glad yours is working now :slight_smile:
I use a Raspberry Pi 4 with Raspbian.
I know a ā€˜reasonableā€™ amount about docker-compose and Docker, but I donā€™t often have to translate Docker-specific options to docker-compose like this. Itā€™s obvious enough when you know (-v is for volume), but Iā€™m still getting used to that kind of thing without examples.

1 Like

Just to elaborate on what is happening here, merely running restart only restarts the existing container. Thus, even though home-assistant restarts, the container is the same. Thus, your new docker configuration is not parsed or applied. For this, a new container must be created. With the docker command you would take it down and back up. But with docker-compose up, it is smart enough to determine which containers have config changes and recreate those ones and bring them back up.

1 Like