Error setting up platform bluetooth_tracker

I have encountered a problem with setting up the bluetooth_tracker where HA is initialized before the bluetoothd is finished setting up bluetooth (running HA 0.59.2 on hassbian).

If I reboot the PI, this shows up in the logs:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/init.py”, line 156, in async_setup_platform
disc_info)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/bluetooth_tracker.py”, line 64, in setup_scanner
for dev in discover_devices():
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/bluetooth_tracker.py”, line 42, in discover_devices
lookup_class=False)
File “/srv/homeassistant/lib/python3.5/site-packages/bluetooth/bluez.py”, line 26, in discover_devices
device_id = _bt.hci_get_route()
OSError: [Errno 19] No such device

Now, if I wait for the /var/run/sdp device to be ready (and change the access rights when device exist so HA has access to the device, which I do automatically on boot) and then restart the HA service manually, the bluetooth_tracker is setup correctly.

The best(?) way to solve it, I think, would be to let the bluetooth_tracker monitor the creation of /var/run/sdp, and initialize when its ready, but I don’t know if the component has support for this? At least, I can’t find anything in the docs.

Anyone else got this problem? Or better yet, the solution for it? :slight_smile:

EDIT: I am running the bluetoothd in “–compat” mode. Haven’t found a way to make it work with the new BlueZ 5 DBus API, but if anyone got a solution for it, it would be ideal.

Have you found a more permanent solution to this issue? I initially had Bluetooth Tracker loading without issue and I discovered several devices, but it crashed when those devices went out of range. I updated systemd to load bluetoothd with the --compat option, but now I’m getting errors very similar to yours:

Traceback (most recent call last): File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/device_tracker/init.py”, line 183, in async_setup_platform disc_info) File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run result = self.fn(*self.args, **self.kwargs) File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/device_tracker/bluetooth_tracker.py”, line 72, in setup_scanner for dev in discover_devices(): File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/device_tracker/bluetooth_tracker.py”, line 50, in discover_devices lookup_class=False) File “/srv/homeassistant/lib/python3.6/site-packages/bluetooth/bluez.py”, line 26, in discover_devices device_id = _bt.hci_get_route() OSError: [Errno 19] No such device

I’ve noticed if I manually issue the “power on” command in bluetoothctl, then restart Home Assistant, I get past the error above, but I will still get an error that HA can’t communicate with the device (sorry, don’t remember the exact error and am not at home). I’m not sure why I would need to manually power it on since I have it configured to power on automatically and the BT tracker previously loaded with that configuration. It sounds like you fixed this by granting access right to /var/run/sdp? I tried chown’ing to the user associated with Home Assistant, but that didn’t fix the problem for me.