home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.54k stars 29.91k forks source link

Bluetooth tracker not working in 0.98.x when running HA in Docker on NUC. #26495

Closed jcuccia closed 4 years ago

jcuccia commented 5 years ago

Home Assistant release with the issue:

0.98.0+

Last working Home Assistant release (if known): 0.97.x

Operating environment (Hass.io/Docker/Windows/etc.):

NUC/Docker/Home Assistant Component/platform:

https://www.home-assistant.io/components/bluetooth_tracker/

Description of problem: The 0.98.x Home Assistant Docker image cannot communicate with the NUC's built-in bluetooth adapter.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

  - platform: bluetooth_tracker
    request_rssi: true
    consider_home: 60
    new_device_defaults:
      track_new_devices: false

Traceback (if applicable):

2019-08-30 18:02:24 INFO (SyncWorker_15) [homeassistant.loader] Loaded bluetooth_tracker from homeassistant.components.bluetooth_tracker
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 31, in discover_devices
_bluetooth.error: (4, 'Interrupted system call')
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 97, in setup_scanner
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 72, in discover_devices
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 34, in discover_devices
    raise BluetoothError ("error communicating with local "
bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter

Additional information: If I SSH into the NUC, I can run 'hcitool scan' and 'hcitool lescan'.

Hcitool scans also work in the container, like so:

docker exec -it home-assistant sh
Leatherface75 commented 5 years ago

Here i have no hctool at all in hassio and log says

2019-09-07 18:50:10 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 77, in async_setup_legacy
    discovery_info,
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 97, in setup_scanner
    for dev in discover_devices():
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 72, in discover_devices
    device_id=device_id,
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 26, in discover_devices
    device_id = _bt.hci_get_route()
imnxnyer commented 5 years ago

Encountered the same problem as @jcuccia in Docker after upgrading from 0.97.X to 0.98.X. The Docker host is a Debian Stretch guest using a passthrough USB bluetooth adapter:

Bus 003 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

The container is using the host network.

configuration.yaml:

device_tracker:
  - platform: bluetooth_tracker
    request_rssi: true
    new_device_defaults:
    track_new_devices: true

bluetooth and device_tracker messages:

2019-09-06 00:35:42 INFO (SyncWorker_5) [homeassistant.util.package] Attempting install of pybluez==0.22
...
2019-09-06 00:35:53 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 31, in discover_devices
    lookup_class=lookup_class, device_id=device_id)
_bluetooth.error: (4, 'Interrupted system call')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 77, in async_setup_legacy
    discovery_info,
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 97, in setup_scanner
    for dev in discover_devices():
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 72, in discover_devices
    device_id=device_id,
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 34, in discover_devices
    raise BluetoothError ("error communicating with local "
bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter
2019-09-06 00:35:53 INFO (SyncWorker_8) [homeassistant.loader] Loaded stream from homeassistant.components.stream
2019-09-06 00:35:53 INFO (MainThread) [homeassistant.setup] Setup of domain device_tracker took 1.7 seconds.

Bluetooth is functional in the virtual machine and inside a Docker bash session.

point-4ward commented 5 years ago

Same issues here - for me it started (or appeared to start, I should say) when host OS upgraded to Buster.

Leatherface75 commented 5 years ago

Seems bluez and hci commands is not installed in hassio docker. Is there any way to get it installed? It doesn't work with pip3 command because it can't compile it. What's the reason for it not installed as default?

hamstercat commented 5 years ago

I have the same issue as well, happened when I updated to the latest version of the docker image (0.98.x). I'm not finding any way to make it accessible to the image anymore.

hamstercat commented 5 years ago

I managed to fix the problem after a day of tweaking. I had pulled the latest docker image, but I had just restarted the container instead of running docker-compose up -d. When I did Home Assistant saw the bluetooth adapter!

costada88 commented 5 years ago

I have the same issue when trying to set up a bluetooth device tracking.

Home Assistant version: 0.98.5 Raspberry pi 4 running a Raspbian Home Assistant is running within Docker: homeassistant/raspberrypi4-homeassistant

I am trying to use the built in bluetooth device of RPI. The host network is exposed to the container. Furthermore I have a Conbee II in /dev/ttyACM0 that is also exposed to the container.

$ uname -a
Linux raspberrypi 4.19.66-v7l+ #1253 SMP Thu Aug 15 12:02:08 BST 2019 armv7l GNU/Linux

configuration.yaml:

device_tracker:
  - platform: bluetooth_tracker
    device_id: 0
  - platform: nmap_tracker
    hosts: 192.168.1.3
    home_interval: 10
$ hcitool dev
Devices:
        hci0    DC:A6:32:00:36:13
Error setting up platform legacy

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 31, in discover_devices
    lookup_class=lookup_class, device_id=device_id)
_bluetooth.error: (4, 'Interrupted system call')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 77, in async_setup_legacy
    discovery_info,
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 97, in setup_scanner
    for dev in discover_devices():
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 72, in discover_devices
    device_id=device_id,
  File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 34, in discover_devices
    raise BluetoothError ("error communicating with local "
bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter
joelprine commented 4 years ago

Any update not this one, I updated to 0.99 and still have the issue.

jcuccia commented 4 years ago

costada88,

I have the same issue when trying to set up a bluetooth device tracking.

Home Assistant version: 0.98.5 Raspberry pi 4 running a Raspbian Home Assistant is running within Docker: homeassistant/raspberrypi4-homeassistant

I am trying to use the built in bluetooth device of RPI. The host network is exposed to the container. Furthermore I have a Conbee II in /dev/ttyACM0 that is also exposed to the container.

According to this, you can't use the Pi's BT radio if you have anything else connect to ttyACM0. I'm trying to find out why it doesn't work on a NUC with a Z-Stick using ttyACM0. The hardware shouldn't have the same limitation, but I don't know about the container base image.

https://wiki.alpinelinux.org/wiki/Raspberry_Pi_3_-_Setting_Up_Bluetooth Excerpt: "You can get Bluetooth to work only if you are not using the UART (ttyAMA0) for anything else, for example serial console. Recent versions of Alpine Linux for Raspberry Pi come with the required Broadcom firmware files. If you need the UART for something else, you can use an USB Bluetooth adapter instead."

jeffh0821 commented 4 years ago

Error still present in 0.99.1

arch | x86_64 dev | false docker | true hassio | false os_name | Linux python_version | 3.7.4 timezone | America/New_York version | 0.99.1 virtualenv | false

joelprine commented 4 years ago

Updated to 0.99.3, still no go, same issues as described above, rolled back to 0.94 for now until resolution is discovered.

kevinwells22 commented 4 years ago

Any word on this issue please?

Ahoui-group commented 4 years ago

Issue still exists for me on 100.3. Worked fine before 0.95 on docker/ubuntu 18.04.1 Any update? Priority fix?

d65k commented 4 years ago

0.100.3 works fine on my docker/ubuntu 18.04.3. Upgraded from 0.97.2.

fbrinker commented 4 years ago

According to this, you can't use the Pi's BT radio if you have anything else connect to ttyACM0. I'm trying to find out why it doesn't work on a NUC with a Z-Stick using ttyACM0. The hardware shouldn't have the same limitation, but I don't know about the container base image.

https://wiki.alpinelinux.org/wiki/Raspberry_Pi_3_-_Setting_Up_Bluetooth Excerpt: "You can get Bluetooth to work only if you are not using the UART (ttyAMA0) for anything else, for example serial console. Recent versions of Alpine Linux for Raspberry Pi come with the required Broadcom firmware files. If you need the UART for something else, you can use an USB Bluetooth adapter instead."

Interesting, didn't know that.

I have the same issues and I am not sure why it is happening. My setup is a Raspi 3 with Docker HA as a slave. Same with a Zero W and HA in a Docker container as a Salve. Both devices work a while until the mentioned error above occurs. After a restart it works fine again for a while and crushes again after some undefined time...

Wondering whats happening there :thinking:

This could be related

costada88 commented 4 years ago

I just discovered that it is suddenly started to work for me on 0.100.2. The devices appeared now in known_devices.yaml and their tracking is working fine. I cannot recall any configuration I did that might be related to this. However strange that the same error is still outstanding in the log.

medelay commented 4 years ago

I just discovered that it is suddenly started to work for me on 0.100.2. The devices appeared now in known_devices.yaml and their tracking is working fine. I cannot recall any configuration I did that might be related to this. However strange that the same error is still outstanding in the log.

I am having the same issue, after doing a lot of trial and error for a couple of errors i finaly figured out that it is actualy working but i was thinking that it was not because of the errors.

Anyone have a way to get rid of the errors?

hellcry37 commented 4 years ago

@fbrinker I have the same issue on an Intel NUC8i5BEK with Conbee II in ttyACM0. The problem is not that is not working, but is working intermittent and when for example my gf phone leaves the home it shows my phone as not home also. This is just one of many issues I have with this bluetooth.

I've even reinstalled host OS (ubuntu 18.04 lts) and reinstalled home assitant from 0, no backup restore. Still same issues

hellcry37 commented 4 years ago

I solved this by disable onboard bluetooth on my NUC and bought a bluetooth adaptor, using that, seem to work for now

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

vladimirardelean commented 4 years ago

Still happens

I get the same error on the latest docker version on a build that has a miniITX board with integrated bluetooth (Gigabyte Aorus b450 I PRO wifi).

the bluetooth works inside the container using the console.

2020-05-06 13:53:24 ERROR (MainThread) [homeassistant.components.bluetooth_tracker.device_tracker] Error looking up Bluetooth device Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 31, in discover_devices lookup_class=lookup_class, device_id=device_id) _bluetooth.error: (4, 'Interrupted system call')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 140, in perform_bluetooth_update devices = await hass.async_add_executor_job(discover_devices, device_id) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 62, in discover_devices device_id=device_id, File "/usr/local/lib/python3.7/site-packages/bluetooth/bluez.py", line 34, in discover_devices raise BluetoothError ("error communicating with local " bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter

gitolicious commented 4 years ago

Same here. I am on an Odroid N2 with a LogiLink BT0015 dongle, HA 0.109.6. Seeing the same error as above, Bluetooth device tracking as well as my MiFlora sensor integrations are not working anymore. I can in fact see the sensors from the homeassistant container console:

bash-5.0# hcitool lescan
LE Scan ...
C4:7C:8D:6A:xx:xx Flower care
dodexahedron commented 4 years ago

Same here, on a RPi 4. Works on the Pi and in the Docker container but Home Assistant dies.

bash-5.0# hcitool lescan LE Scan ... 24:FC:E5:xx:xx:xx (unknown) 44:67:55:xx:xx:xx bhyve_xxxxxx