Can't find how to give HA bluetooth access in Docker Bridge mode

Hi,
My HA container is in bridge mode and I would like if possible to keep it that way. But I’m having trouble to give it Bluetooth access on my Raspberry Pi 4.

The container can correctly see and use the Bluetooth adapters. I can use bluetoothctl list and bluetoothctl scan from within the HA, but HA says that no adapter is found. That’s what I don’t understand, because I can list all nearby device from the console but not from HA.

Here is my docker compose configuration:

  homeassistant:
    image: lscr.io/linuxserver/homeassistant:latest
    container_name: homeassistant
    #network_mode: host
    privileged: true
    cap_add:
        - NET_ADMIN
        - NET_RAW
        - SYS_ADMIN
    networks:
      - services
    #security_opt:
    #  - no-new-privileges:true
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - UMASK=${UMASK}
    volumes:
      - ${CONFIG_FOLDER}/homeassistant:/config
      - /run/dbus:/run/dbus:ro
    #ports:
    #  - 8123:8123 #optional
    devices:
      - /dev/ttyAMA0:/dev/ttyAMA0
    restart: unless-stopped
    labels:
      caddy: homeassistant.mydomain.com
      caddy.reverse_proxy: homeassistant:8123

Could the bridge mode be the problem? What should I try to do? I couldn’t find any documentation with HA in bridge mode. Is there something I’m doing wrong in my configuration ? I find very strange that I can access bluetooth from HA container console but not from HA. I really want to find what’s wrong.

I’m stuck on this issue for months now, any answer is welcome.

Thanks in advance for any answer, have a great day.

No. Bluetooth support in HA is unrelated to the network generally speaking.
Not sure why you do, but using a non-official image will probably not help, here.

Thanks a lot for your answer.

I’ve just replaced the image by the official one, didn’t change any other setting, and I’m having the same behaviour.

What could be the cause? Where should I look?

Thanks in advance for any answer.

Permission issue maybe?

I usually start from command line in container and verifying the device is showing in container.

Are you running HA as root user? If not, try with HA as root user.

Hi, Thanks a lot for your answer.
I found what my problem was ! My problem is that the container was not running as admin. I’ve run it with PUID and PGID=0 an it partially worked.

So now my Bluetooth adapter is correctly detected by HA and I could add it to the devices.
But I still have a remaining problem : No Bluetooth device is found. I tried syncing bluetooth devices near to it, it never seems to be adding them. What am I doing wrong ? I don’t see anything in the logs. If I do a bluetoothctl scan on in the console, it correctly finds all nearby devices but HA doesn’t, even with the adapter being added.

Could you help me on that ?
Thanks in advance for any answer, have a great day.

You dont need to run as root or admin. Just need to add user to host OS and give the user Bluetooth access

Regarding other issues, i guess verify you meet all requirements

1 Like

If you are using USB3 on your RPI4, the interference is so bad the BT range is basically 10… centimeters :wink:

Are you sure about this?
Do you mean using USB3 for the Bluetooth adapter or in general? Because I am using the integrated Bluetooth chip, not an external one.
I don’t think that would be an issue because I am also using Libreelec with the same setup, it can perfectly find and use any nearby Bluetooth device without any interference. So interference is not what makes HA not detect any device. Should be something else but I can’t find what.

I may have a clue but no idea what to do with it: bluetoothctl scan on works as I said, but hcitool dev doesn’t work, it doesn’t show any device. I don’t know what the problem is but maybe this info can help.

Hi, so to sum up what state I am in now:

Here is my compose:

 homeassistant:
    image: homeassistant/homeassistant:latest
    container_name: homeassistant
    #network_mode: host
    #privileged: true
    networks:
      - services
    #security_opt:
    #  - no-new-privileges:true
    environment:
      - PUID=0 #${PUID}
      - PGID=0 #${PGID}
      - TZ=${TZ}
    #  - UMASK=${UMASK}
    volumes:
      - ${CONFIG_FOLDER}/homeassistant:/config
      - /run/dbus:/run/dbus:ro
    #ports:
    #  - 8123:8123 #optional
    devices:
      - /dev/ttyAMA0:/dev/ttyAMA0
      - /dev/ttyACM0:/dev/ttyACM0 #Carte Zigbee
      - /dev/video0:/dev/video0 #HDMI Capture Card
      - /dev/video1:/dev/video1 #PSeye
    restart: unless-stopped
    labels:
      caddy: homeassistant.mydomain.com
      caddy.reverse_proxy: homeassistant:8123

The Bluetooth adapter is correctly added in HA, but no new device is being discovered:
image
Apparently, there is nothing I can do with this device. No action, can’t manually start scanning.

In the console inside the container, here is what I can do:

root@fb9868a94580:/# bluetoothctl scan on
Discovery started
[CHG] Device D3:81:93:95:86:FA RSSI: -67
[CHG] Device 68:28:28:4E:08:D7 RSSI: -74
[CHG] Device E4:B7:5C:11:04:C3 RSSI: -76
[CHG] Device F4:EC:53:D0:24:6A RSSI: -78
[CHG] Device 0E:4A:7C:22:42:D0 RSSI: -86
[DEL] Device 27:15:4F:51:2F:DD 27-15-4F-51-2F-DD
[NEW] Device 20:50:E7:6D:C1:A5 Bouygtel4K
[CHG] Device 20:50:E7:6D:C1:A5 RSSI: -78
[CHG] Device 20:50:E7:6D:C1:A5 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 20:50:E7:6D:C1:A5 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 20:50:E7:6D:C1:A5 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 20:50:E7:6D:C1:A5 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 20:50:E7:6D:C1:A5 UUIDs: 00000000-0000-0000-0000-000000000000
[CHG] Device 68:28:28:4E:08:D7 RSSI: -64
[CHG] Device D3:81:93:95:86:FA RSSI: -67
[CHG] Device F4:EC:53:D0:24:6A RSSI: -68
[CHG] Device 62:32:0A:A8:E1:2E RSSI: -85
[CHG] Device E4:B7:5C:11:04:C3 RSSI: -76
[DEL] Device 7C:AF:4F:2A:8A:A4 7C-AF-4F-2A-8A-A4
[NEW] Device 7C:AF:4F:2A:8A:A4 7C-AF-4F-2A

But this doesn’t work:

root@fb9868a94580:/# hcitool dev
Devices:
root@fb9868a94580:/# 
root@fb9868a94580:/# hciconfig
Can't open HCI socket.: Address family not supported by protocol
root@fb9868a94580:/# hciconfig hci0 up
Can't open HCI socket.: Address family not supported by protocol
root@fb9868a94580:/# hciconfig hci0
Can't open HCI socket.: Address family not supported by protocol
root@fb9868a94580:/# 

I can also tell that Bluetooth is working correctly from the native OS itself (directly on the machine, no docker and no HA). Not sure if something on the system interfere, but I really don’t have anything installed except Kodi and Docker. I can disable Bluetooth from the OS, if I do, the adapter is no longer found in HA.

I am not sure if working hciconfig is needed, but I’ve seen this command being used in other forum posts. This is all I can tell now. I don’t know where to search, tell me if there is any command I should try to give you more infos.

I’m stuck on this problem for a long time now, if you have any idea or suggestion, I’m all ears.

Thanks in advance for any answer, have a great day.

I am also having the exact same problem, BT detected in HomeAssistant but not by the BLE plugin. hcitool dev shows no results for me neither, not sure hot to make permanent the python permission changes suggested by their FAQ since after a restart docker comes back to same state as before.

Same for me :’(