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

Has there been any more progress on this? I was looking at a generic way to use the bluetooth of my PI3 to track BLE devices without pairing.

I already have the normal Bluetooth module working and that proved to have the best presence accuracy for iPhones. I have a MiBand 2 which would help with presence a lot.

I’ve contributed some code and using this for quite some time and it works quite well and reliable.

Is there a feature you’re expecting to see?

Most of the evolutions have been comitted by @kirichkov and the project is running fine on my setup as well.

From reading all the comments I wasn’t sure if this made it back into hass base code. The documentation on hass still shows bluetooth le as “We have received numerous reports that this integration will have a big impact on the performance of the server.”

I have tried adding it now, and I get this stacktrace when my Home Assistant is started:

2017-05-28 22:08:54 INFO (MainThread) [websockets.server] Connection error during opening handshake
Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/deps/websockets/”, line 64, in handler
File “/home/homeassistant/.homeassistant/deps/websockets/”, line 151, in handshake
path, headers = yield from read_request(self.reader)
File “/home/homeassistant/.homeassistant/deps/websockets/”, line 43, in read_request
request_line, headers = yield from read_message(stream)
File “/home/homeassistant/.homeassistant/deps/websockets/”, line 83, in read_message
start_line = yield from read_line(stream)
File “/home/homeassistant/.homeassistant/deps/websockets/”, line 103, in read_line
line = yield from stream.readline()
File “/usr/lib/python3.4/asyncio/”, line 418, in readline
yield from self._waiter
File “/usr/lib/python3.4/asyncio/”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/asyncio/”, line 582, in _read_ready
data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

And I also started getting:
2017-05-28 22:35:44 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

This project is actually the exact opposite of being integrated into home assistant code :grinning:. The idea was to extract presence detection code in a seperate program to isolate performance issies and make it much easier to debug.

Do you have issues running it independantly?

Another benefit of this de-coupled from main hass code base solution is that you are not forced to use it on the same computer where hass is installed.

I’ve just tried to follow instructions on hassbian but I get:

pi@hassbian:~ $ gem install home_assistant-ble
-bash: gem: command not found

I tried sudo with same results.

Update: Fixed it by running:

sudo apt-get install rubygems

I will come back once I am able to start it as a background service and integrate it with hass

Update 2: No luck:

pi@hassbian:~ $ gem install home_assistant-ble
Fetching: ruby-dbus-0.13.0.gem (100%)
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /var/lib/gems
pi@hassbian:~ $ sudo gem install home_assistant-ble
Fetching: ruby-dbus-0.13.0.gem (100%)
ERROR:  Error installing home_assistant-ble:
	ruby-dbus requires Ruby version >= 2.0.0.

Use sudo when installing the gems. You need root permissions to install gems globally.

In my post i used sudo as well. Check second update second try

You don’t have the proper version of ruby, install it before installing the gem:

sudo apt-get install ruby2.1 ruby2.1-dev

If this version is not around you should check with the people maintaining hassbian.

I was able to run your command, but I still can’t install;

pi@hassbian:/etc/alternatives $ ruby -v
ruby 2.1.5p273 (2014-11-13) [arm-linux-gnueabihf]
pi@hassbian:/etc/alternatives $  sudo gem install home_assistant-ble
ERROR:  Error installing home_assistant-ble:
	ruby-dbus requires Ruby version >= 2.0.0.

Update: I was able to install using pi@hassbian:~ $ sudo gem2.1 install home_assistant-ble

Update 2: Can this component do also discovery? I mean can it publish new devices detected to known devices?

Currently it can’t. It always checks whether an ID that is seen is in the exclusive list you supply in the configuration file. Depending on how hass behaves it might not be that difficult to implement.

The issue will be if hass does not accept new mac address supplied via the REST API, that we’re using to let hass know of which devices are seen.

I think would be even better to use mqtt if possible. That gets even more load off hass.
I was able to get the code to detect devices, but not post back to hass. I wasn’t able to determine what was wrong as it didn’t complain about anything.

I will pause trying this for now, as my purpose was also to get new devices registered, just like a normal tracker would.

I’m not aware how this will work via MQTT, since there’s no MQTT API for hass.

I have problem with this. I run it on my intel nuc. I getting this:

BlockquoteJust discovered C3:EC:82:FF:8E:C3
/usr/lib/ruby/2.3.0/net/http/response.rb:380:in inflate': incorrect header check (Zlib::DataError) from /usr/lib/ruby/2.3.0/net/http/response.rb:380:in block in inflate_adapter’
from /usr/lib/ruby/2.3.0/net/protocol.rb:411:in call_block' from /usr/lib/ruby/2.3.0/net/protocol.rb:402:in <<’
from /usr/lib/ruby/2.3.0/net/protocol.rb:108:in read' from /usr/lib/ruby/2.3.0/net/http/response.rb:402:in read’
from /usr/lib/ruby/2.3.0/net/http/response.rb:291:in block in read_body_0' from /usr/lib/ruby/2.3.0/net/http/response.rb:262:in inflater’
from /usr/lib/ruby/2.3.0/net/http/response.rb:281:in read_body_0' from /usr/lib/ruby/2.3.0/net/http/response.rb:202:in read_body’
from /usr/lib/ruby/2.3.0/net/http/response.rb:227:in body' from /usr/lib/ruby/2.3.0/net/http/response.rb:164:in reading_body’
from /usr/lib/ruby/2.3.0/net/http.rb:1445:in transport_request' from /usr/lib/ruby/2.3.0/net/http.rb:1407:in request’
from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:129:in block in update_home_assistant' from /usr/lib/ruby/2.3.0/net/http.rb:853:in start’
from /usr/lib/ruby/2.3.0/net/http.rb:584:in start' from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:128:in update_home_assistant’
from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:91:in block in detect_new_devices' from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:88:in each’
from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:88:in detect_new_devices' from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:66:in block in run’
from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:64:in loop' from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:64:in run’
from /var/lib/gems/2.3.0/gems/home_assistant-ble-1.3.1/bin/home_assistant-ble:22:in <top (required)>' from /usr/local/bin/home_assistant-ble:22:in load’
from /usr/local/bin/home_assistant-ble:22:in `’

Is it possible that you are running home assistant behind a reverse proxy, e.g. nginx? If so point home_assistant-ble directly at home assistant’s web interface.

hi. I use lubuntu on intel nuc and Hassio in docker. I getting info in HA - home but no away :frowning: Any idea?

I got this same bug. Must be a change in home-assistant. I’ll see what I can do about it.

Just to give you an update - there was indeed a change in hass’ API. I’ve made the necessary changes on my own fork. I think the original author of the gem has taken a step back from the development.

The source above can be built and installed in the following way:

git clone
cd home_assistant-ble/
gem build home_assistant-ble.gemspec
sudo gem install home_assistant-ble-1.4.1.gem

From then on you take the steps described in the documentation to configure and run the BLE scanner.

1 Like

@kirichkov Could this be used for other BLE devices, like bulbs?

@Betree thought you would like to know about this

1 Like