Fixing Raspberry Pi 3 B Bluetooth for HASS

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.

DIY Home Assistant Seating Detection without Soldering

In this tutorial, I quickly outline three different set-ups I tried to add seat-sensing capabilities to my Home Assistant Setup. The set ups don’t require soldering, do not require inverting states in HA, and cover both Zigbee and Wifi Connections. I tried three different boards and pressure sensors and recommend one of the boards and all of the pressure sensors – surprisingly, all of the pressure sensors excelled in different setups! However, I found that the Car Seat Sensor types work best for bed occupancy detection and thin film sensors are useful for seats and couches.

I’ve recently started re‑building my smart home setup with Home Assistant. At the moment, most of my devices are lights (with a few extras like heaters and a robot vacuum – maybe a topic for another post). Naturally, the first and most obvious automations involve switching lights on and off, usually triggered by motion. But that quickly leads to what I like to call the “toilet seat problem”: you settle onto the couch, lie in bed, or sit down for a meal – perfectly still for a while – and suddenly the lights go out. Not great UX.

A Setup Guide for the Best eSIM in Cambodia: CellCard.

While mobile data is crucial for every trip in South East Asia, finding the best eSIM can be hard. Especially for Cambodia, which is not included in many regional data plans and outrageously expensive in common providers such as Revolut, Klook or BNE-Sim (1 GB ~ $6). CellCard is a local provider that is easy to set up and cheap (15 GB ~ $6). However, a few hurdles remain, which I detail in this post.

Cambodia is a curious country for eSIMs. It is not included in many regional packages1 and even in usually-pricey-but-okay providers such as BNE or Saily you’ll pay at least $10 for a few GB2. However, there is a small, appearently very local provider of SIM cards that recently started providing eSIMs: CellCard.

Leveraging Constrained Sampling for Fill-In-the-Middle Code Completion

Two octopodes flying through space... we want to control where they go to!

Existing constrained sampling methods only focus on generating code that will be a syntactically well-formed program on its own after completion. What if we have some remaining code suffix and want the entirety to become a valid program? In this post I explore how to leverage existing tooling to create well-formed Copilot-like Fill-In-the-Middle (FIM) code completions.

Proper Well-Formedness Guarantees for Finite LLM Sampling

Even under constrained sampling, LLMs can produce syntactically invalid output. In this post I explore why this happens when restricting the maximum number of generated tokens and how to resolve the issue using results from language theory.

Teach programming with JavaScript

a person sitting in front of a computer learning to write javascript by building a nice and blinking website
DALLE-2 generated interpretation of how it fealt for me to learn JavaScript.

I recently posted on how I find current computer science education lacks motivation. Today I had the pleasure to listen to a keynote by Prof. Dr. Dennis Komm on how he approaches computer science education. He should know since he is a Professor of Algorithms and Didactics at ETH Zurich and hence at the spearhead of education for computer science in Switzerland. And in his talk he made a lot of valid points – but I still feel the issues raised in my last post remain unanswered by his talk. I will use it as an anchor to refine my demands.

Die Letzte Generation hat ein Imageproblem

Die Letzte Generation (LG) hat ein Problem. Und dieses Problem ist nicht nur die Klimakrise, gegen die sie so leidenschaftlich kämpft, sondern auch die Art und Weise, wie sie diesen Kampf führt. Die Aktionen der LG, die sich durch zivilen Ungehorsam auszeichnen, stören zunehmend die Bevölkerung und zwingen damit die Regierung, nicht auf sie einzugehen, sondern sie zu zerschlagen. Um das zu ändern, muss die LG die Regierung stören und bei der Bevölkerung beliebter werden.

Als Außenstehender, der die LG und ihre Ziele schätzt, fällt es mir schwer, diese Kritik zu äußern. Aber gerade weil ich die Notwendigkeit ihres Kampfes gegen die Umweltzerstörung sehe, ist es mir wichtig, auf die Probleme hinzuweisen, die ihre aktuelle Strategie mit sich bringt.

Stop teaching “Programming”

User: please write convincing blog post about why we should not teach programming anymore (especially not as “Introduction to Programming”) The reason is that programming is just a tool and never useful on its own. Teaching it without context is easily frustrating. Instead, recommend teaching applied courses like “Introduction to Webdesign” where users can learn programming in a context and appreciate its usefulness

Docker and DB WiFi Hotspots

TL;DR: Are you riding trains in Germany (brought to you by DB) and having trouble to connect to their WiFi Hotspot? Try uninstalling docker.

I am recently riding the train a lot. In particular, I was riding the ICE type of train by Deutsche Bahn (DB). In theory, these trains feature WI-Fi hotspots, but I am used to the fact that Wi-Fi on trains is not avilable. Either there is no signal at all or the hotspot does not offer a sign-in screen. Alternatively, the sign-in screen shows, and the screen is blank or logging in fails. You get the idea.

Recently I stumbled upon a very peculiar issue. My phone was able to connect perfectly fine but my laptop was not. I could connect to the WiFi but the login screen would not prompt. I tried restarting and the screen showed (after some restarts) and gave a weird error message – the host can not be reached. I googled how to force the login screen to show. Usually you type the default gateway address in your browser and it works fine. In this case said host-could-not-be-reached message popped up. How can that host not be reached? It is literally the first IP address in this network my laptop would know of and try to reach.. wait a minute.

Chiatura – Sachkhere via Bus and Train

Chiatura is a place that is famous for the fact that there are many cable cars throughout the city. Now that the cable cars from the soviet era are not operational anymore you might be wondering if you should still go. Let me ask you another question: Are you curious about a city where public transport includes cable cars? Are you interested in a former miner city full of soviet-style high-rise buildings in a super hilly area?

Soviet era high-rise buildings and abandoned cable car station