The Raspberry Pi is a great tool for your home to control other devices and enter the world of home automation. Besides the old and first versions of the Raspberry Pi, the new ones like the Raspberry Pi 3* and the Raspberry Pi 4* come with an integrated WiFi and Bluetooth Low Energy (BLE) module. This allows direct communication with other devices and gets rid of external USB WiFi and Bluetooth dongles. Those who have already worked with the integrated modules know that they have limited capabilities and are sometimes frustrating to use due to unexpected problems. In this article, I will show some solutions to problems that often occur on Raspberry Pi OS (former Raspbain).

Check Bluetooth

First, it should be clear how to check if Bluetooth works and which devices are configured. In the command line, just type bluetoothctl. This should show you a Controller and maybe Bluetooth devices around you. In this [bluetooth]# command line, it is further possible to use other commands like scan on or scan off or get information from other devices with info <ID>. Just give it a try!

If Bluetooth isn't available, start the service with sudo systemctl start bluetooth.

"No default controller available"

After a routine update/upgrade process, Bluetooth stopped working on my Raspberry Pi. bluetoothctl showed "No default controller available" and a restart couldn't fix the problem. In such a case, hciuart isn't running. Start it with sudo systemctl start hciuart. In my case, the start failed with the following error:

Job for hciuart.service failed because the control process exited with error code.
See "systemctl status hciuart.service" and "journalctl -xe" for details.

The logs gave me further details:

Failed to start Configure Bluetooth Modems connected by UART.

Since this problem is widely discussed on the internet, the solution that worked for me was just deleting existing Bluetooth software and reinstalling pi-bluetooth as suggested by a user in the Raspberry Pi forum:

$ sudo apt purge bluez
$ sudo apt bluez-firmware
$ sudo apt purge pi-bluetooth
$ sudo apt install pi-bluetooth

After a reboot (sudo reboot), everything worked as expected again.

Bluetooth in Docker Container

When working with containerization like docker and docker-compose, things get more interesting and complex.

As suggested in this StackOverflow answer, the best way is to install the relevant packages in the docker container (for example by adding a RUN command to the Dockerfile): sudo apt install bluez bluetooth

Next, the following two commands have to be executed when the container starts:

$ service dbus start
$ bluetoothd &

In order to get it working correctly, the bluetoothd service has to be stopped. I added the following line to my Raspberry Pi crontab with sudo crontab -e: @reboot killall -9 bluetoothd

Save on close the file by typing :wq.

This should help get Bluetooth working in home automatism software like Home Assistant or Homebridge.

References / Footnotes