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
73.56k stars 30.74k forks source link

Unstable Bluetooth Adapter in Home-Assistant #93036

Closed enkama closed 1 year ago

enkama commented 1 year ago

The problem

So I have my Intel Nuc Bluetooth Adapter enabled to discover the values of my plant sensors. But the sacnner is always restarting for some reason some times resolving itself but also sometimes not so I have to press reload integration manually for it to work again.

What version of Home Assistant Core has the issue?

core-2023.5.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bluetooth

Diagnostics information

config_entry-bluetooth-13ec0f89e00a8353c4df8e7ed7e10e7d.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-05-13 20:52:59.713 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] Initializing bluetooth scanner with {'detection_callback': <bound method HaScanner._async_detection_callback of <homeassistant.components.bluetooth.scanner.HaScanner object at 0x7f5a8cb02680>>, 'scanning_mode': 'active', 'adapter': 'hci0'}
2023-05-13 20:52:59.713 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:00:57.511 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:00:57.632 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] Initializing bluetooth scanner with {'detection_callback': <bound method HaScanner._async_detection_callback of <homeassistant.components.bluetooth.scanner.HaScanner object at 0x7f5a92ba1000>>, 'scanning_mode': 'active', 'adapter': 'hci0'}
2023-05-13 21:00:57.632 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:04:57.648 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Bluetooth scanner has gone quiet for 90s, restarting
2023-05-13 21:04:57.648 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:04:57.791 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:11:27.662 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Bluetooth scanner has gone quiet for 90s, restarting
2023-05-13 21:11:27.662 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:11:27.782 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:14:57.669 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Bluetooth scanner has gone quiet for 90s, restarting
2023-05-13 21:14:57.669 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:14:57.805 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:21:27.680 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Bluetooth scanner has gone quiet for 90s, restarting
2023-05-13 21:21:27.680 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:21:27.810 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)
2023-05-13 21:26:57.689 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Bluetooth scanner has gone quiet for 90s, restarting
2023-05-13 21:26:57.690 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Stopping bluetooth discovery
2023-05-13 21:26:57.828 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (3C:E9:F7:49:D1:D9): Starting bluetooth discovery attempt: (1/3)

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (bluetooth) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `bluetooth` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign bluetooth` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


bluetooth documentation bluetooth source (message by IssueLinks)

ItsMe00007 commented 1 year ago

I too have the same problem with the built in Bluetooth adapter on my Intel NUC (Beelink Mini PC). I am currently using only the „passive scanning“ option of the hci0 adapter integration. From time to time I get the error message that it cannot reset the hci0 adapter but the adapter is still up in the device display. So my question is why it tries to reset the adapter and why it does not detect that it is still up and running. Here‘s the error message in the core log:

Logger: bluetooth_auto_recovery.recover Source: components/bluetooth/util.py:78 First occurred: May 13, 2023 at 05:14:18 (2 occurrences) Last logged: May 13, 2023 at 20:12:20 Bluetooth adapter hci0 [DC:21:48:2A:58:4F] could not be reset due to timeout after 5 seconds

mboisson commented 1 year ago

I too have issues with the Bluetooth since a month or so. I am running HA docker. I used to use version 2022.11, now recently upgraded to 2023.5 to try to fix the issues, but alas.

The issue, as far as I can see, is that HomeAssistant is constantly scanning for new devices, and overloading the BT dongle.

I tested outside of the docker, if I pause the docker, then run bluetoothctl power off; bluetoothctl power on, then a script external to the docker can read the metrics from my Airthings wave BLE device. However, as soon as I unpause the docker, I start getting a LOT of [CHG] actions in the output of bluetoothctl, such as

[CHG] Device 41:6F:1B:32:00:55 RSSI: -70
[CHG] Device 14:4D:42:D9:6D:D9 RSSI: -63
[CHG] Device 69:E4:80:93:A9:58 RSSI: -67
[CHG] Device 04:69:F8:93:0E:BF RSSI: -71
[CHG] Device 57:41:2A:C1:0B:0E RSSI: -68

and it goes on and on and on. And from the start I start seeing this scan, then the external script that reads the Airthings Wave BLE device stops being able to read the metrics.

In the HA logs, I found only this:

Logger: homeassistant.components.bluetooth.scanner
Source: components/bluetooth/scanner.py:340
Integration: Bluetooth ([documentation](https://www.home-assistant.io/integrations/bluetooth), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+bluetooth%22))
First occurred: 4:21:07 PM (1 occurrences)
Last logged: 4:21:07 PM

hci0 (5C:F3:70:A9:74:31): Error stopping scanner: [org.bluez.Error.Failed] No discovery started

but it seems clear to me that something is wrong with the Bluetooth addon. We need to be able to stop it from scanning for devices and only scan manually. I tried disabling

Enable newly added entities.

If newly discovered devices for Bluetooth should be automatically added.

in the system options, but that does not stop the scanning.

smartmatic commented 1 year ago

Is there an progress regarding this issue? It seems there are no updates to get the bluetooth errors fixed. At the end on my side it influence all Bluetooth devices. Especially the Bluetooth Proxies are no longer reliable since weeks.

Logger: homeassistant.components.bluetooth.scanner Source: components/bluetooth/scanner.py:340 Integration: Bluetooth (documentation, issues) First occurred: 18:04:13 (24 occurrences) Last logged: 21:38:44

hci0 (C0:FB:F9:61:A9:68): Error stopping scanner: [org.bluez.Error.Failed] No discovery started

ItsMe00007 commented 1 year ago

I am also still have the Bluetooth Problem (Just scanning activated, nothing else) IMG_1278 IMG_1288

bdraco commented 1 year ago

Please follow the issue in the operating system repo

enkama commented 1 year ago

Well thats happening with ubuntu with docker with ha-container. Not with HAOS in this case. So doing something like rolling back to HAOS 9.5 doesnt work for this. For reference for the others since it wasnt linked. https://github.com/home-assistant/operating-system/issues/2535

bdraco commented 1 year ago

The problem is with bluez and/or the linux kernel so its not something can be solved in core (which is why we are still waiting for a solution).

enkama commented 1 year ago

So for the time being for anyone else in here this is what I have done to fix it for the time being. Works fine for me. You can find your entry id in /.storage/core.config_entries

alias: Bluetooth Debug
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition: []
action:
  - service: homeassistant.reload_config_entry
    data:
      entry_id:  ***
mode: single
bob-u commented 1 year ago

So for the time being for anyone else in here this is what I have done to fix it for the time being. Works fine for me. You can find your entry id in /.storage/core.config_entries

This fix did not fix my issue. I still have to unplug and reconnect USB Bluetooth dongle physically every couple of days.

Is there a way to power cycle the USB port from Home Assistant?

bdraco commented 1 year ago

Is there an progress regarding this issue? It seems there are no updates to get the bluetooth errors fixed. At the end on my side it influence all Bluetooth devices. Especially the Bluetooth Proxies are no longer reliable since weeks.

Logger: homeassistant.components.bluetooth.scanner

Source: components/bluetooth/scanner.py:340

Integration: Bluetooth (documentation, issues)

First occurred: 18:04:13 (24 occurrences)

Last logged: 21:38:44

hci0 (C0:FB:F9:61:A9:68): Error stopping scanner: [org.bluez.Error.Failed] No discovery started

Is there an open issues for the proxies. I'm not aware of any unsolved problems with them

enkama commented 1 year ago

Yeea I am getting this now:

A message handler raised an exception: 'org.bluez.Device1'. Traceback (most recent call last): File "src/dbus_fast/message_bus.py", line 811, in dbus_fast.message_bus.BaseMessageBus._process_message File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 854, in _parse_msg condition_callback() File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 709, in callback self._properties[device_path][defs.DEVICE_INTERFACE][property_name] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ KeyError: 'org.bluez.Device1'

bdraco commented 1 year ago

I opened a PR to handle the case where the device is removed from the bus while we are waiting for a change https://github.com/hbldh/bleak/pull/1329

bdraco commented 1 year ago

https://github.com/home-assistant/core/pull/99520 will fix the case where the device is removed from the bus while connecting. If the adapter itself it unstable, there isn't anything we can do about that though.

If you have an unstable adapter problem, please continue in https://github.com/home-assistant/core/issues/92379