Announcing home_assistant-ble to support bluetooth low energy device tracking for raspberry

Documentation for bluetooth low energy tracker states

Don’t use on a Raspberry Pi. It will become unusable slow when using this platform.

I’ve noticed that indeed :slight_smile:

In order to decouple home-assistant and bluetooth (BLE) tracking, I’ve built a very small app called home_assistant-ble.

This app can run on any computer (linux at least) with a BLE dongle and sends state changes to home assistant via its (great) api.

Feel free to use it for your own raspberry if you want to!
I’d be happy to get your feedback.

Link to the repository and README: GitHub - kirichkov/home_assistant-ble: Companion application for home-assistant, sending bluetooth low energy detection


Good job I’ll start testing and provide some feedback. I was thinking of writing something similar, however in C/C++, because that should theoretically give it the smallest memory/cpu footprint.

1 Like

I have an Eve door and window Homekit sensor which I was trying to reverse engineer with a view to creating a complnent for, see Elgato Eve door and window Could your app detect when the sensor is pinging a signal? I have a pi 3

Why not make it more generic and use MQTT?

It’s open source - you can always implement the functionality yourself!

In practice, even in ruby we get a very low foot print (~0.5% of RPi2 ram)

Good suggestion.
Actually using home-assistant API is quite efficient to talk to HA. Do you mean that we could be more generic to generate data consumed by other softwares than home-assistant?

If the sensor is advertises in bluetooth, it is very likely that it could work with home_assistant-ble. It would be great if you could try and tell me what’s going well/wrong.

1 Like

What I mean is that if the separate app would post it’s state changes over MQTT, than it would be more generic to use. For example for use with other home automation systems or MQTT centered installations. I know there are people that build their entire HA solution around MQTT.

You’re right it would more generic.
At the moment this project is a very small glue between bluetooth and home-assistant born to solve the slowness issue on raspberry.

I don’t really plan to make something larger than that unless the issue appears for other home automation systems.
If there is such a need and a good PR I’ll gladly take it.

Do we understand why ble can’t be used natively on rPI?

Unfortunately it’s not clear. I think it’s the underlying library blocking the whole HASS process for too long.

I’ve been running this code for 12 hours and there’s been no issues whatsoever with performance. For this I want to commend @kamaradclimber on the great work he’s done! :clap:

Unfortunately it’s not clear. I think it’s the underlying library blocking the whole HASS process for too long.

Exactly. The ble scanner uses gattlib which essentially just execvs gatttool binary with a bunch of options. It may be indeed stalling the loop for far too long. If that is true just putting the scanning in a thread and reaping results from the thread would fix the issue.

I actually seen the very same issue on regular PC running home assistant. I actually needed different scanner type so I implemented my own, that uses thread and the problem was gone. Let me try to fix the existing tracker the same way.


Obviously the best thing around!

I still thing this will be useful. I plan to throw around some Pi Zeros to detect presence, and I don’t need the features of the room_presence component.

Exactly. The ble scanner uses gattlib which essentially just execvs gatttool binary with a bunch of options

actually I have to take that back. Current tracker really uses gattlib. Gattlib seem to be using C binding and that stalls the loop. I moved everything to a new thread but the problem is still there.

I will try converting it to use bluepy which execs a binary that uses new bluetooth management interface… this is supposedly better way.

1 Like

Thanks :slight_smile:
To be completely frank, I’ve discovered that detection was not perfect yet (at least on my setup). There is a bug to detect properly device out of range that happen to detect my nut mini. I’ll work on that as soon as possible.

No worries, it’s a process! I have some features in mind and I’ll open a pull as soon as I have implemented them - Zone configuration; Supporting updating multiple hass instances.

I just got my nut mini and I’ll give it a shot to debug this. Can you share with me whether you’ve paired your nut with the iPhone app, or just use turned it on and use it as is?

Just turned it on and let the program do its job.
Latest version does not seem to pick up the nut-mini all the time, I need to work on this.

OK. I’ll look into it as well. Is it possible this is due to wi-fi noise? I easily detect ~30 Wi-Fi hotspots where I live and owntracks on my phone had trouble finding my RPi iBeacon 5 meters away.