Archives mensuelles : novembre 2024

Theengs Gateway on LibreElec

I wanted HomeAssistant to use my Body Mi Scale with Home Assistant, but my server is too far from the scale and can’t detect the bluetooth data.

But I do have a Raspberry running LibreElec (in a beautiful Flirc case) near my bathroom, and I decided to use it as a bluetooth proxy. LibreElec being a « Just Enough OS », I didn’t want to mess with it, as my config should survive version upgrades.
Fortunately, LibreElec supports Docker, and a Docker image exists

Here are my quick notes :

LibreElec

Use a recent version of LibreElec (12.x in my case)

Make sure bluetooth is enable in Kodi / Settings / LibreElec / Services

Make sure the Docker addon for Kodi is installed

SSH in LibreElec as root

Pull the docker image :

# docker pull theengs/gateway

And run it with the following settings :

# docker run --restart always --network host -e MQTT_HOST=mqtt_broker_hostname -e BLE=true -e DISCOVERY=true -e SCANNING_MODE=active -e PUBLISH_ALL=false -e SCAN_TIME=1 -e TIME_BETWEEN=20 -v /var/run/dbus:/var/run/dbus --name TheengsGateway theengs/gateway

Each time you use your scale, you should see appear after ~10 secs some data into the home/TheengsGateway/BTtoMQTT topic

Optional : use passive scanning

Because passive scanning is soooo much cool than active (I guess that’s a good enough reason), you can enable it with a few extra steps.

First, enable experimental features in bluez :

# systemctl edit bluetooth.service

and add the following lines :

[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd --experimental $BLUEZ_ARGS $BLUEZ_DEBUG

Then restart bluetooth

# systemctl restart bluetooth

And replace the docker command with

# docker run --restart always --network host -e MQTT_HOST=mqtt_broker_hostname -e BLE=true -e DISCOVERY=true -e SCANNING_MODE=passive -e PUBLISH_ALL=false -v /var/run/dbus:/var/run/dbus --name TheengsGateway theengs/gateway

Note : upon reboot, because the container starts before the Wifi is up, using a hostname for the MQTT broker resulted in a connection failure and the container being stucked. I opened an issue on github. To work around this issue, i simply used the IP address for the MQTT broker instead.

HomeAssistant

If MQTT Integration is installed in Home Assistant, it should discover the scale and its sensors.
You can now install the bodymyscale integration.