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
69.03k stars 28.28k forks source link

Bluetooth receiver connection drops at startup and after some hours #107554

Closed bsjouke closed 2 weeks ago

bsjouke commented 4 months ago

The problem

The issue is that the Bluetooth adapter seems to become unreachable thus the connection with the BLE devices is lost.

The issue occurs:

  1. whenever HA is restarted
  2. after being operational for some hours. In the logging below, the connection was lost after 8 hours

Logging: See below in the details

Workaround:

What version of Home Assistant Core has the issue?

core-2023.12.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Bluetooth

Link to integration documentation on our website

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

Diagnostics information

config_entry-bluetooth-80939c045beed540f2ed6f89b57a0e32.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-01-08 16:14:01.233 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (00:E0:4C:2B:0B:EE): Bluetooth scanner has gone quiet for 90s, restarting
2024-01-08 16:14:01.235 ERROR (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (00:E0:4C:2B:0B:EE): Error stopping scanner: [org.bluez.Error.InProgress] Operation already in progress
.......
2024-01-08 16:16:01.237 INFO (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (00:E0:4C:2B:0B:EE): Bluetooth scanner has gone quiet for 90s, restarting
2024-01-08 16:16:01.239 ERROR (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (00:E0:4C:2B:0B:EE): Error stopping scanner: [org.bluez.Error.InProgress] Operation already in progress
.......
2024-01-08 16:16:36.566 ERROR (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (00:E0:4C:2B:0B:EE): Failed to restart Bluetooth scanner: hci0 (00:E0:4C:2B:0B:EE): Timed out starting Bluetooth after 15 seconds
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 223, in _async_start
    await self.scanner.start()  # type: ignore[no-untyped-call]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 198, in start
    await self._backend.start()
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 185, in start
    self._stop = await manager.active_scan(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 408, in active_scan
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dbus_fast/aio/message_bus.py", line 399, in call
    await future
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 222, in _async_start
    async with asyncio.timeout(START_TIMEOUT):
  File "/usr/local/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 353, in _async_restart_scanner
    await self._async_start()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 268, in _async_start
    raise ScannerStartError(
homeassistant.components.bluetooth.scanner.ScannerStartError: hci0 (00:E0:4C:2B:0B:EE): Timed out starting Bluetooth after 15 seconds

**Further remarks**
This last part repeats itself every minute.

Additional information

No response

home-assistant[bot] commented 4 months 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


bluetooth documentation bluetooth source (message by IssueLinks)

claytonkimber commented 4 months ago

Having this happen quite often on RPI4, with both the internal BT and a BCOM dongle.

mandeepdhillon82 commented 4 months ago

Hello, I am experiencing the exact same issue. I have a switchbot integration and it keeps losing connectivity with the bluetooth adapter. I have tried using the Raspberry PI 4 internal and a usb dongle. I am running core-2024-1.2.

The-RandomOne commented 4 months ago

Reporting the same issue with a Dell/Wyse 3040 Thin Client and internal BT. Core 2024.1.2 Supervisor 2023.12.0 Operating System 11.4 Frontend 20240104.0

2024-01-10 11:04:39.901 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Error stopping scanner: [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
2024-01-10 11:04:41.417 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Failed to restart Bluetooth scanner: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
File "src/habluetooth/scanner.py", line 232, in habluetooth.scanner.HaScanner._async_start
File "src/habluetooth/scanner.py", line 233, in habluetooth.scanner.HaScanner._async_start
File "src/habluetooth/scanner.py", line 362, in habluetooth.scanner.HaScanner._async_restart_scanner
File "src/habluetooth/scanner.py", line 315, in _async_start
habluetooth.scanner.ScannerStartError: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
2024-01-10 11:05:14.912 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not determine the power state of the Bluetooth adapter hci0 [A8:1D:16:09:05:30] due to timeout after 5 seconds
2024-01-10 11:05:20.586 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not cycle the Bluetooth adapter hci0 [A8:1D:16:09:05:30]: [Errno 110] Operation timed out
2024-01-10 11:05:20.591 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth management socket connection lost: [Errno 22] Invalid argument
2024-01-10 11:05:25.591 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth adapter hci0 [A8:1D:16:09:05:30] could not be reset:
2024-01-10 11:05:25.597 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [A8:1D:16:09:05:30] failed: [Errno 9] Bad file descriptor
2024-01-10 11:05:27.112 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Failed to restart Bluetooth scanner: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
andrezstar2 commented 4 months ago

This happens to me when I start the computer. I just can solve it by extracting the BT DG45 dongle and introducing it again It seems that the Bluetooth adapter affects also the zigbee one

bsjouke commented 4 months ago

I did two actions which make it confusing to determine which of the two helped.

  1. I changed the order of the USB devices (ZB and BT) in such a way that BT comes first. BT is now /dev/bus/usb/002/002 while ZB is /dev/bus/usb/002/003. After this, BT stayed online for 8-10 hours.
  2. Then I upgraded the OS to 11.4. After the reboot all BT devices came up and since then no errors.

I won't close this issue as I think my solution may not be suitable for all, and the root cause is still unknown.

cm-mojo commented 4 months ago

Also having this issue with RPI4 internal adaptor. @bsjouke can you explain how you change the order?

cm-mojo commented 4 months ago

FYI, this is what keeps cycling in the logs:

2024-01-13 22:21:29.198 DEBUG (MainThread) [homeassistant.components.bluetooth] Rediscovered adapters: {'hci0': {'address': 'D8:3A:DD:10:0E:72', 'sw_version': 'homeassistant', 'hw_version': 'usb:v1D6Bp0246d0546', 'passive_scan': True, 'manufacturer': None, 'product': None, 'vendor_id': None, 'product_id': None}} 2024-01-13 22:21:29.331 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Attempting to recover bluetooth adapter hci0 with mac address D8:3A:DD:10:0E:72 2024-01-13 22:21:29.332 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Attempting to power cycle bluetooth adapter hci0 [D8:3A:DD:10:0E:72] 2024-01-13 22:21:29.334 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Found adapters from hci: {0: {'dev_id': 0, 'name': 'hci0', 'bdaddr': 'D8:3A:DD:10:0E:72', 'flags': 5, 'type': 3, 'features': <ifaddr._shared.c_ubyte_Array_8 object at 0x7f7b53af00>, 'pkt_type': 52472, 'link_policy': 5, 'link_mode': 32768, 'acl_mtu': 1021, 'acl_pkts': 8, 'sco_mtu': 64, 'sco_pkts': 1, 'stat': <bluetooth_adapters.systems.linux_hci.hci_dev_stats object at 0x7f7b53b530>}} 2024-01-13 22:21:29.335 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Found adapter D8:3A:DD:10:0E:72 in hci device as 0 2024-01-13 22:21:29.335 DEBUG (MainThread) [bluetooth_auto_recovery.recover] hci0 (D8:3A:DD:10:0E:72) idx is 0 2024-01-13 22:21:29.338 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Attempting to power cycle bluetooth adapter hci0 [D8:3A:DD:10:0E:72] 2024-01-13 22:21:29.349 DEBUG (MainThread) [btsocket.btmgmt_protocol] Decoding bluetooth_version as type IntUL 2024-01-13 22:21:29.357 DEBUG (MainThread) [btsocket.btmgmt_protocol] Socket Read: <address=D8:3A:DD:10:0E:72, bluetooth_version=9, manufacturer=15, supported_settings=130815, current_settings={Powered: True, Connectable: False, FastConnectable: False, Discoverable: False, Bondable: False, LinkLevelSecurity: False, SecureSimplePairing: True, BREDR: True, HighSpeed: False, LowEnergy: True, Advertising: False, SecureConnections: True, DebugKeys: False, Privacy: False, ControllerConfiguration: False, StaticAddress: False, PHYConfiguration: False, WidebandSpeech: False}, class_of_device=7077888, name=b'homeassistant', short_name=0> 2024-01-13 22:21:29.359 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Current power state of bluetooth adapter is ON. 2024-01-13 22:21:29.376 DEBUG (MainThread) [btsocket.btmgmt_protocol] Decoding bluetooth_version as type IntUL 2024-01-13 22:21:29.379 DEBUG (MainThread) [btsocket.btmgmt_protocol] Socket Read: <address=D8:3A:DD:10:0E:72, bluetooth_version=9, manufacturer=15, supported_settings=130815, current_settings={Powered: False, Connectable: False, FastConnectable: False, Discoverable: False, Bondable: False, LinkLevelSecurity: False, SecureSimplePairing: True, BREDR: True, HighSpeed: False, LowEnergy: True, Advertising: False, SecureConnections: True, DebugKeys: False, Privacy: False, ControllerConfiguration: False, StaticAddress: False, PHYConfiguration: False, WidebandSpeech: False}, class_of_device=0, name=b'homeassistant', short_name=0> 2024-01-13 22:21:29.381 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Bouncing Bluetooth adapter hci0 2024-01-13 22:21:29.381 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Setting hci0 down 2024-01-13 22:21:29.883 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Setting hci0 up 2024-01-13 22:21:30.538 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Finished bouncing hci0 2024-01-13 22:21:30.557 DEBUG (MainThread) [btsocket.btmgmt_protocol] Decoding bluetooth_version as type IntUL 2024-01-13 22:21:30.562 DEBUG (MainThread) [btsocket.btmgmt_protocol] Socket Read: <address=D8:3A:DD:10:0E:72, bluetooth_version=9, manufacturer=15, supported_settings=130815, current_settings={Powered: True, Connectable: False, FastConnectable: False, Discoverable: False, Bondable: False, LinkLevelSecurity: False, SecureSimplePairing: True, BREDR: True, HighSpeed: False, LowEnergy: True, Advertising: False, SecureConnections: True, DebugKeys: False, Privacy: False, ControllerConfiguration: False, StaticAddress: False, PHYConfiguration: False, WidebandSpeech: False}, class_of_device=7077888, name=b'homeassistant', short_name=0> 2024-01-13 22:21:30.563 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Power state of bluetooth adapter hci0 [D8:3A:DD:10:0E:72] is ON after power cycle

bsjouke commented 4 months ago

Also having this issue with RPI4 internal adaptor. @bsjouke can you explain how you change the order?

I'm running HA in OVA mode as VM on a Synology box. In the settings I can add attached devces like this: image

Months ago I also experienced problems, and at that moment this setting helped:

Recently it did not work anymore, @andrezstar2's remark about the adapters affecting each other gave me the idea to switch the two as in the screenprint.

All in all this doesn't seem a stable situation as to my best knowledge the order of USB devices should have no impact.

cm-mojo commented 4 months ago

I can fix it by disabling the bluetoith, rebooting the device then once it's started, enabling the device

On Sun, 14 Jan 2024, 08:02 bsjouke, @.***> wrote:

Also having this issue with RPI4 internal adaptor. @bsjouke https://github.com/bsjouke can you explain how you change the order?

I'm running HA in OVA mode as VM on a Synology box. In the settings I can add attached devces like this: image.png (view on web) https://github.com/home-assistant/core/assets/11473110/1b130cde-edad-43eb-9686-088a93a09756

Months ago I also experienced problems, and at that moment this setting helped:

  • ZB adapter
  • blank
  • BT adapter

Recently it did not work anymore, @andrezstar2 https://github.com/andrezstar2's remark about the adapters affecting each other gave me the idea to switch the two as in the screenprint.

All in all this doesn't seem a stable situation as to my best knowledge the order of USB devices should have no impact.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/107554#issuecomment-1890877354, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANS4VDQ3KAZY5QIDQA4GBVLYOOGIJAVCNFSM6AAAAABBRVM6I2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJQHA3TOMZVGQ . You are receiving this because you commented.Message ID: @.***>

orand commented 4 months ago

I can fix it by disabling the bluetoith, rebooting the device then once it's started, enabling the device

I tried that but it didn't work for me. Both built-in and dongle Bluetooth adapters are still failing.

greenhawk89 commented 4 months ago

Yeah, still seeing this issue here. No combination of reboots seems to fix it.

The-RandomOne commented 4 months ago

Reporting the same issue with a Dell/Wyse 3040 Thin Client and internal BT. Core 2024.1.2 Supervisor 2023.12.0 Operating System 11.4 Frontend 20240104.0

2024-01-10 11:04:39.901 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Error stopping scanner: [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
2024-01-10 11:04:41.417 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Failed to restart Bluetooth scanner: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
File "src/habluetooth/scanner.py", line 232, in habluetooth.scanner.HaScanner._async_start
File "src/habluetooth/scanner.py", line 233, in habluetooth.scanner.HaScanner._async_start
File "src/habluetooth/scanner.py", line 362, in habluetooth.scanner.HaScanner._async_restart_scanner
File "src/habluetooth/scanner.py", line 315, in _async_start
habluetooth.scanner.ScannerStartError: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
2024-01-10 11:05:14.912 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not determine the power state of the Bluetooth adapter hci0 [A8:1D:16:09:05:30] due to timeout after 5 seconds
2024-01-10 11:05:20.586 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not cycle the Bluetooth adapter hci0 [A8:1D:16:09:05:30]: [Errno 110] Operation timed out
2024-01-10 11:05:20.591 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth management socket connection lost: [Errno 22] Invalid argument
2024-01-10 11:05:25.591 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth adapter hci0 [A8:1D:16:09:05:30] could not be reset:
2024-01-10 11:05:25.597 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [A8:1D:16:09:05:30] failed: [Errno 9] Bad file descriptor
2024-01-10 11:05:27.112 ERROR (MainThread) [habluetooth.scanner] hci0 (A8:1D:16:09:05:30): Failed to restart Bluetooth scanner: hci0 (A8:1D:16:09:05:30): Failed to start Bluetooth: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist

I added an Asus BT400 to my setup and now have 2 adapters (internal/external) which ran for 36 hours with out any issues. I am monitoring 2 InkBird sensors and for some reason the IBS-TH2 will only pair with the internal but the IBS-TH2 will pair with either. The Asus bt400 has never had an issue going offline but the internal one, AzureWave, which is a combo wifi+bt has all the issues. I lose wifi access when the adapter goes offline. HAOS 11.3 was the first to support the wifi chip.

I have created a time based automation to reboot the host every 8 hours but have it disabled since mine appears to be less of an issue for now

cm-mojo commented 3 months ago

Any more ideas? This is becoming too frequent

LAPDragnet commented 3 months ago

Same issue here with generic x86 and built-in BT. Had BT disabled for along time but added two SwtichBot BLE sensors yesterday and enabled BT then. Issues as above in less than 24 hours. Warm restart of the host is not enough to fix it. Have not tested cold restart yet.

(Edit: ZHA went down at the same time but got back after the warm restart of the host.)

mjefferys commented 3 months ago

An issue for me also, I have worked around it with an automation that reboots home assistant if a bluetooth sensor goes unavailable which is a band-aid at best.

bschatzow commented 3 months ago

I have an issue where my Bluetooth sensor becomes unavailable. I thought it was a proxy issue or the inkbird integration. A reboot of HA always fixes the issue. How do you tell if it is the Bluetooth itself causing the issue versus the other variant? First started seeing this several months ago.

The-RandomOne commented 3 months ago

I have an issue where my Bluetooth sensor becomes unavailable. I thought it was a proxy issue or the inkbird integration. A reboot of HA always fixes the issue. How do you tell if it is the Bluetooth itself causing the issue versus the other variant? First started seeing this several months ago.

I would say, does it resolve after a warm restart or do you need to do a hardware reboot? If it works with a restart then it might be the inkbird sensor connectivity, etc, but if if requires a reboot then it is the Bluetooth adapter.

Mine would only resolve with a reboot. I also can connect to my Inkbird sensors with the Engbird mobile app when HA shows it unavailable.

LAPDragnet commented 3 months ago

My new BLE adapter has been running fine for maybe eight hours now. https://github.com/home-assistant/core/issues/92379#issuecomment-1927180028

Maxrunner commented 3 months ago

I had two updates to HA, one was the OS and the other was the supervisor, bluetooth seems to be configured:

image

bschatzow commented 3 months ago

I was told in a different issue to disable the adapter 's Bluetooth as I use the Bluetooth proxy. So far this has worked successfully for me.

agile-scrum-master commented 2 months ago

I got same problem:

after x hours..I can not control Switchbot I have to go to devices -> bluetooth -> RELEAD then switchbox controls in HA is working again. (or reboot HA)

(Passive scanning ON/OFF does not make difference, problems comes back after x hours)

Core 2024.2.2 Supervisor 2024.01.1 Operating System 11.5 Frontend 20240207.1

Bluetooth info (hci0 (MAC-address)) Device info: Unknown by Raspberry Pi Trading Ltd Firmware: homeassistant

I checked the LOG VIEWER and I see a lot of times: INFO (MainThread) [habluetooth.scanner] hci0 (MAC-address): Bluetooth scanner has gone quiet for 90s, restarting

after this, it's working again...a couple of minutes

Maxrunner commented 2 months ago

Bluetooth proxy.

How do you use this? on a raspberry pi 3?

agile-scrum-master commented 2 months ago

I have Raspberry Pi 4 (rpi4-64) I do not use 'Bluetooth proxy'

(going to disable passive scan option again, just to see if there is any difference)

bdraco commented 2 weeks ago

Workaround:

  • physically disconnect and reconnect the bluetooth device from/to USB

It looks like you are using a Realtek adapter

          "manufacturer": "Realtek",
          "product": "Bluetooth Radio",
          "vendor_id": "2550",
          "product_id": "8761"

Sadly these adapters are known to lock up and require a physical unplug and replug to restore their functionality.

https://www.home-assistant.io/integrations/bluetooth/#realtek-rtl8761bu-adapters

These adapters do not have a reset pin. If they stop responding, there is currently no way for the kernel to reset them automatically.

The only solution other than to unplug and replug is to replace it with an adapter that does have a reset pin https://www.home-assistant.io/integrations/bluetooth/#cambridge-silicon-radio-csr--based-adapters

or use an ESPHome Bluetooth proxy https://esphome.io/components/bluetooth_proxy.html https://esphome.io/projects/?type=bluetooth

agile-scrum-master commented 1 week ago

I switched a couple of months ago to ESPHome Bluetooth proxy (and disabled local bluetooth) and so far no problem anymore! Cheap sollution and even better because it's now located in center of building.