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

Will this work when Hass.io in a container? if yes, how can i mange it to work?

thanks

I am personally not using hass.io but I don’t see a reason why it won’t work. As part of the configuration you input the URL where HASS can be found. There’s no limitation on the URL, so you can even install this program on a completely different computer.

I seem to have installed the program and it appears to be running but how do I pick up the info in Home Assistant?

You configure the HASS url and it will submit it automatically.

Hi Sorry I’m not clear on the installation.

When we say Home Assistant will pick up the state change of the device from this program, do we need to add the device tracker section in HA? If so, which platform we have to use?

Thanks!

Not quite as fancy but I cobbled something similar here based on another member’s work:

I use it to track our BTLE Tile(s) and push the data into MQTT which I then use for presence detection in HA

Thanks a lot for your efforts, this tool not only work like a charm but also discovers devices which are connected to i.e mobile phone and therefore they’re not visible until connection is closed.
With standard HA component I could see for instance FitBit Flex at “home” only if I switch off bluetooth on my phone and stop “all day syncing”.

Really greatly appreciated!

Regards

1 Like

@kirichkov thanks for your work!
For people interested I made an hassio addon with it, it’s at testing stage but for me it works.
Simply add a hassio store with this url https://github.com/coolweb/hassio-addons

Give me feedback :wink:

2 Likes

Hi :slight_smile:

I would like to use your repo for my NUT mini.
Is it still working?

I started by following the kirichkov procedure (GitHub - kirichkov/home_assistant-ble: Companion application for home-assistant, sending bluetooth low energy detection):

Installation
For raspbian install required packages:

$ sudo apt-get install ruby-dev libcap-dev
$ gem install home_assistant-ble

No noot
Running as non-root on recent Raspbian, Ubuntu and Debian-based distros requires changes to DBus configuration and adding the user to the bluetooth group. For more information check this stackexchange post.

Make sure you have the following in your /etc/dbus-1/system.d/bluetooth.conf:

<!- allow users of bluetooth group to communicate->
<policy group = "bluetooth">
<allow send_destination = "org.bluez" />
<allow send_interface = "org.bluez.GattCharacteristic1" />
<allow send_interface = "org.bluez.GattDescriptor1" />
<allow send_interface = "org.freedesktop.DBus.ObjectManager" />
<allow send_interface = "org.freedesktop.DBus.Properties" />
</policy>

Then reload DBus:

sudo service dbus reload

In other Linux distros to be able to run with a non-root user, read Bluetooth LE scan as non root? - Unix & Linux Stack Exchange. In short (adapt if using a non-debian distribution):

sudo apt install libcap2-bin
sudo setcap ‘cap_net_raw, cap_net_admin + eip’ readlink -f \ which ruby ​​\ ``

I then installed your plugin, with the following config:

interval: 30
grace_period: 60
home_assistant_port: 8123
home_assistant_password: my_password
home_assistant_token: my long token
home_assistant_devices: []

However, I have the following error messages in the logs:


[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms ... exited 0.
[fix-attrs.d] applying ownership & permissions fixes ...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts ...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[INFO] Starting bluetooth the companion
/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require ': cannot load such file - etc (LoadError)
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/processor_counter.rb:1:in `<top (required)> '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/configuration.rb:9:in `<top (required)> '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent.rb:4:in `<top (required)> '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/ble-1.0.0/lib/ble/characteristic.rb:2:in `<top (required)> '
from /usr/local/bundle/gems/ble-1.0.0/lib/ble.rb:104:in `require_relative '
from /usr/local/bundle/gems/ble-1.0.0/lib/ble.rb:104:in `<top (required)> '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:2:in `<top (required)> '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require '
from /usr/local/bundle/gems/home_assistant-ble-1.4.2/bin/home_assistant-ble:3:in `<top (required)> '
from / usr / local / bundle / bin / home_assistant-ble: 23: in `load '
from / usr / local / bundle / bin / home_assistant-ble: 23: in `<main> '
[cmd] /run.sh exited 1
[cont-finish.d] executing container finish scripts ...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

My BLE devices are not visible in the know_devices either.

An idea ?
Thanks :slight_smile:

Sorry for being late in responding.

  1. What OS / hardware is this?
  2. Can you show me how you’re starting home assistant BLE? Ap

No problem !
I have a Debian installation, with Hassio in docker.

I launch this with:
home_assistant-ble /usr/share/hassio/homeassistant/custom_components/home_assistant-ble/config.yml

Here is the return:
Traceback (most recent call last):
2: from /usr/local/bin/home_assistant-ble:23:in <main>' 1: from /usr/lib/ruby/2.5.0/rubygems.rb:303:in activate_bin_path’
/usr/lib/ruby/2.5.0/rubygems.rb:284:in `find_spec_for_exe’: can’t find gem home_assistant-ble (>= 0.a) with executable home_assistant-ble (Gem::GemNotFoundException)

This means that you haven’t installed the gem. You have to install it from source, however, since the original author hasn’t integrated my latest changes and published them as a ruby gem. Give me a few hours to update the README.

I’ve updated the README in the repository with complete instructions how to build the gem, putting them here for reference:

git clone https://github.com/kirichkov/home_assistant-ble.git
cd home_assistant-ble
gem build home_assistant-ble.gemspec
sudo gem install home_assistant-ble-1.4.2.gem

@kirichkov, maybe we could organize a transfer of ownership of the github repository and gem on rubygems.org ?

that’d be great!

That’s me:
https://rubygems.org/profiles/kirichkov

Rubygems api requires your email to change ownership. Could you send it to me?
(you can send me an email to [email protected] if you don’t want to expose your email on a public forum)

You can retry the original commands. I just pushed the latest version to rubygems so you can install it using:

sudo gem install home_assistant-ble

Don’t know why, but have the same result.

I launch this:
uninstall all my home_assistant-ble previous configuration

in my directory /usr/share/hassio/homeassistant/custom_components:

  1. git clone https://github.com/kirichkov/home_assistant-ble.git
    => OK
  2. cd home_assistant-ble
    gem build home_assistant-ble.gemspec
    => OK
    gem install home_assistant-ble-1.4.2.gem
    => OK:
Successfully installed home_assistant-ble-1.4.2
Parsing documentation for home_assistant-ble-1.4.2
Done installing documentation for home_assistant-ble after 0 seconds
1 gem installed
  1. nano config.yml
interval: 30
grace_period: 60
home_assistant_url: https://my_local_adress:8123
home_assistant_password: my_password
home_assistant_token: my_token
home_assistant_devices: 
  BLE_CE:AC:AB:XX:XX:XX: nut
home_assistant_devices_file: /usr/share/hassio/homeassistant/known_devices.yaml
  1. sudo home_assistant-ble config.yml
Set DEBUG environment variable to activate debug logs
Could not update HA: Net::OpenTimeout
Just discovered CE:AC:AB:XX:XX:XX

Now i have a problem with my loopback. My ISP blocks loopback :frowning:

if “my_local_address”, is actually your public address, then that’s the problem.

Don’t use your public IP address, use your private internal IP address.

When i use my private internal IP address, i have a probleme with my SSL (from Letsencrypt):

Traceback (most recent call last):
        15: from /usr/local/bin/home_assistant-ble:23:in `<main>'
        14: from /usr/local/bin/home_assistant-ble:23:in `load'
        13: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/bin/home_assistant-ble:40:in `<top (required)>'
        12: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:69:in `run'
        11: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:69:in `loop'
        10: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:71:in `block in run'
         9: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:101:in `detect_new_devices'
         8: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:101:in `each'
         7: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:104:in `block in detect_new_devices'
         6: from /var/lib/gems/2.5.0/gems/home_assistant-ble-1.4.2/lib/home_assistant/ble.rb:139:in `update_home_assistant'
         5: from /usr/lib/ruby/2.5.0/net/http.rb:609:in `start'
         4: from /usr/lib/ruby/2.5.0/net/http.rb:909:in `start'
         3: from /usr/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
         2: from /usr/lib/ruby/2.5.0/net/http.rb:985:in `connect'
         1: from /usr/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/usr/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (unspecified certificate verification error) (OpenSSL::SSL::SSLError)

If you have LE certificate you must have HTTP enabled for renewal to work. You need to figure out your Let’s encrypt setup and connect via http, or resolve the SSL issue, which, most likely is that your SSL DNS name doesn’t actually match your local address. A workaround that might work is to add your public DNS name to /etc/hosts