If you encounter an error trying to set up your Home Assistant Bluetooth on a Raspberry Pi 3 B, these steps might help you resolve them. Speficially, this website lists a fix for upgrading the install bluez version and installing experimental features. If everything goes wrong, we also show how to revert the changes.
This article is for you if you encounter the following issue when setting up the Bluetooth integration in Home Assistant on a Raspberry Pi 3 B:
habluetooth.scanner.ScannerStartError: hci0 (B8:27:EB:3D:23:3A): Failed to start Bluetooth: passive scanning on Linux requires BlueZ >= 5.56 with --experimental enabled and Linux kernel >= 5.10; Try power cycling the Bluetooth hardware.
This indicates that the bluez version running on your device is out of date or does not have experimental features enabled. I specifically encountered it after having already upgraded manually to 5.55 before. You can confirm the version of bluez/bluetoothd on your device by running the following command in the command line:
$ bluetoothd --version
5.55
1. Ensure to follow the HASS instructions
First of all, make sure to follow the instructions on the Home Assistant homepage to set up your device correctly. In my case I had to follow the container instructions to pass down dbus into the container running HASS, but your setup may deviate.
You can find the instructions here: https://www.home-assistant.io/integrations/bluetooth
2. Download and build the latest bluez version
Even though an upgrade to 5.56 might suffice, I figured I want to try running the latest version, 5.9.
Don’t apply the patches if you deviate from my instructions and choose a different version.
You may find a later version at the point in time where you read this and may not need to apply the manual fixes I automatically apply below. You can find different versions of the bluez package on this website: https://www.kernel.org/pub/linux/bluetooth/
Run the following commands to download, patch, configure and build bluez 5.9. Note that we need to enable experimental features for Home Assistant. It also applies this patch to the files to prevent a compilation error. You should be able to copy the following block verbatim and paste it into your command line. The last step, which builds the code might take a few minutes, so feel free to grab a cup of coffee.
# Download bluez 5.9
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.9.tar.gz
# Extract the package
tar -xzf bluez-5.9.tar.gz
# Enter the code base directory
cd bluez-5.9
# Apply a patch to build on Raspberry Pi (skip if != 5.9)
cat > add_sockios.patch <<'EOF'
diff --git a/tools/l2test.c b/tools/l2test.c
index 011a68c378..388d881c9f 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -29,6 +29,7 @@
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <linux/sockios.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
diff --git a/tools/rctest.c b/tools/rctest.c
index d31180880e..7ad9181d37 100644
--- a/tools/rctest.c
+++ b/tools/rctest.c
@@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <linux/sockios.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
EOF
patch -p1 < add_sockios.patch
# Configure with experimental settings
./configure --enable-experimental
# Build and install
sudo make install -j4
After this step, you should be able to check the version of bluetoothctl and it should show the installed version (in our case 5.9)
$ bluetoothctl --version
5.9
However, bluetoothd is not updated yet.
$ bluetoothd --version
5.55
3. Overwrite the installed bluetoothd
The newly built bluetoothd is located in a folder where it is not picked up by the system yet. To fix this, we first back up the old bluetoothd which came pre-installed, and copy the newly built bluetoothd into its location.
sudo cp $(which bluetoothd) bluetoothd-bkp
sudo cp /usr/local/libexec/bluetooth/bluetoothd $(which bluetoothd)
Now you should see the following
$ bluetoothd --version
5.9
4. Restart the Bluetooth service
The last step is to restart the bluetooth service. After restart, Home Assistant immediately was able to set up the Bluetooth integration.
sudo systemctl restart bluetooth.service
Reverting the changes
If this did not work and you don’t feel confident fixing the remaining issues on your own, run the following from the bluez-5.9 directory to revert the changes.
sudo cp bluetoothd-bkp $(which bluetoothd)
sudo apt install --reinstall pi-bluetooth bluez pulseaudio-module-bluetooth
I hope everything worked for you however, as it did for me. Otherwise, feel free to drop a comment below and explain what you had to change.