core icon indicating copy to clipboard operation
core copied to clipboard

Failed to restart Bluetooth scanner

Open cookiestheone opened this issue 2 years ago • 6 comments

The problem

Failed to restart Bluetooth scanner: hci0 (00:1A:7D:DA:71:13): Timed out starting Bluetooth after 15 seconds after 2022.9.0 update.

At 2022.8 it was "Failed to start Bluetooth: [org.bluez.Error.InProgress] Operation already in progress" but now i've got a new problem.

What version of Home Assistant Core has the issue?

2022.9.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Bluetooth

Link to integration documentation on our website

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

Diagnostics information

Logger: homeassistant.components.bluetooth.scanner Source: components/bluetooth/scanner.py:277 Integration: Bluetooth (documentation, issues) First occurred: 9:49:15 AM (99 occurrences) Last logged: 10:43:16 AM

hci0 (00:1A:7D:DA:71:13): Failed to restart Bluetooth scanner: hci0 (00:1A:7D:DA:71:13): Timed out starting Bluetooth after 15 seconds Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 232, in _async_start await self.scanner.start() # type: ignore[no-untyped-call] File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 141, in start self._stop = await manager.active_scan( File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 327, in active_scan reply = await self._bus.call( File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 305, in call await future asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 231, in _async_start async with async_timeout.timeout(START_TIMEOUT): File "/usr/local/lib/python3.10/site-packages/async_timeout/init.py", line 129, in aexit self._do_exit(exc_type) File "/usr/local/lib/python3.10/site-packages/async_timeout/init.py", line 212, in _do_exit raise asyncio.TimeoutError asyncio.exceptions.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 362, in _async_scanner_watchdog await self._async_start() File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 277, in _async_start raise ScannerStartError( homeassistant.components.bluetooth.scanner.ScannerStartError: hci0 (00:1A:7D:DA:71:13): Timed out starting Bluetooth after 15 seconds

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

cookiestheone avatar Sep 08 '22 05:09 cookiestheone

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! (message by CodeOwnersMention)

Same at 2022.9.1

cookiestheone avatar Sep 09 '22 05:09 cookiestheone

I can add a +1 to this, with a little more info. Whilst my main instance is impacted, I have a second instance, also running 2022.9 with the same configuration, that isn't affected.

The hardware is different between the two systems. Working is a "HP Portable Bumble Bee" (Broadcom BCM20702A0). The non-working is a TP-Link UB400 dongle, which shows up as a "Cambridge Silicon Radio, Ltd Bluetooth Dongle". The latter had been working flawlessly using the Passive BLE Monitor integration.

AWoodley avatar Sep 10 '22 17:09 AWoodley

I have BURO-BT40A usb stick which also shows as Cambridge Silicon Radio, Ltd Bluetooth Dongle. Before new bluetooth integration it works as intended

cookiestheone avatar Sep 12 '22 02:09 cookiestheone

Adding on as another impacted by this issue. Running 2022.9.5 in a VM using Virtual Box with Ubuntu as the host OS with an Asus USB-BT400. The Bluetooth USB adapter is reported as a Broadcom Corp. Appears that after a while Home Assistant just no longer recognizes the adapter is plugged in. I can't say if this started with 2022.9 builds specifically as I changed from a TP-Link UB400 to the Asus USB-BT400 after reading that TP-Link dongle was not recommended.

mrrobotnic avatar Sep 20 '22 18:09 mrrobotnic

Same issue here on raspberry pi. Restarting hass does not fix. Reboot to fix.

RobinCutshaw avatar Sep 30 '22 00:09 RobinCutshaw

Once https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=b9c747ff82b4 makes it into the Linux kernel you are using it will likely make this problem better

bdraco avatar Oct 08 '22 18:10 bdraco

Possible for dongles but will it help builtin bluetooth on rpi? The real question is why it was working before and now it is broken.

RobinCutshaw avatar Oct 10 '22 00:10 RobinCutshaw

Seems like I have the same issue with a 3b+ running hassio os. It crashes my system in a weird way, i can't even reboot via ssh (with the ssh plugin)

pitchbent avatar Oct 20 '22 08:10 pitchbent

just piling in here to say my setup is still having this on RPi4 Home Assistant 2022.12.3 Supervisor 2022.11.2 Operating System 9.3 Frontend 20221208.0 - latest

bobloadmire avatar Dec 12 '22 21:12 bobloadmire

Well, unfortunately the latest update to the kernel with HAOs 9.4 did not resolve this issue. I am on

RPi4 Home Assistant 2022.12.4 Supervisor 2022.11.2 Operating System 9.4 Frontend 20221212.0 - latest

half5cat avatar Dec 13 '22 17:12 half5cat

I face this issue as well. The version of Homeassistant is 2022.12.1. I have 2 bluetooth devices, one built-in 4.2 Intel chip and one external realtek 5.2 dongle.

Before the integration it worked fine with Passive BLE Monitor. Sometimes it helps to restart the bluetooth service or disable a device. But it comes back after a few minutes or hours.

thomsbe avatar Dec 28 '22 15:12 thomsbe

There were some updates for bluetooth scanning in the very latest HA update, but it hasn't seemed to help on my end.

bobloadmire avatar Dec 28 '22 15:12 bobloadmire

I´m having the same problem as well on the HA Yellow:

First occurred: 03:37:21 (17 occurrences)
Last logged: 03:45:21

hci0 (E4:5F:01:61:96:A0): Failed to restart Bluetooth scanner: hci0 (E4:5F:01:61:96:A0): Failed to start Bluetooth: [org.bluez.Error.NotReady] Resource Not Ready
...
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 364, in _async_scanner_watchdog
    await self._async_start()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 310, in _async_start
    raise ScannerStartError(
homeassistant.components.bluetooth.scanner.ScannerStartError: hci0 (E4:5F:01:61:96:A0): Failed to start Bluetooth: [org.bluez.Error.NotReady] Resource Not Ready

in combination with:

First occurred: 03:33:13 (3 occurrences)
Last logged: 03:37:11

hci0 (E4:5F:01:61:96:A0): Error stopping scanner: [org.bluez.Error.InProgress] Operation already in progress
hci0 (E4:5F:01:61:96:A0): Error stopping scanner: [org.bluez.Error.NotReady] Resource Not Ready

I´m on: Home Assistant 2022.12.8 Supervisor 2022.12.1 Operating System 9.4 Frontend 20221213.1 - latest

m4dm4xi avatar Dec 31 '22 09:12 m4dm4xi

I did a couple of tests. I have disabled the internal BT with rfkill and disabled in HA. It looks like it runs for a longer time. But this can be random.

The issue definitely occurs as soon as I start a computer with bluetooth active. It doesn't matter if that is the desktop or a laptop. It runs stable overnight, as soon as I turn on a computer the error occurs.

Then when restarting bleutooth.service it runs for minutes or half an hour. As long as the PC is on, the error keeps occurring. I live in a house with many people living in it, so it may be that other computers are causing the problem as well. There are almost 100 devices with Bluetooth visible with my external dongle with antenna.

thomsbe avatar Jan 05 '23 08:01 thomsbe

Hi, i confirm having the same issue on HA container 2023.1. I've the Bluetooth integrated into my PC. Archlinux as SO.

Logger: homeassistant.components.bluetooth.scanner Source: components/bluetooth/scanner.py:301 Integration: Bluetooth (documentation, issues) First occurred: 05:24:09 (174 occurrences) Last logged: 06:50:44

hci0 (54:27:1E:7A:96:B4): Failed to restart Bluetooth scanner: hci0 (54:27:1E:7A:96:B4): Failed to start Bluetooth: [org.bluez.Error.InProgress] Operation already in progress Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/homeassistant/components/bluetooth/scanner.py", line 219, in _async_start await self.scanner.start() # type: ignore[no-untyped-call] File "/usr/lib/python3.10/site-packages/bleak/init.py", line 156, in start await self._backend.start() File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 191, in start self._stop = await manager.active_scan( File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 368, in active_scan assert_reply(reply) File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply raise BleakDBusError(reply.error_name, reply.body) bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress

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

Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/homeassistant/components/bluetooth/scanner.py", line 346, in _async_restart_scanner await self._async_start() File "/usr/lib/python3.10/site-packages/homeassistant/components/bluetooth/scanner.py", line 301, in _async_start raise ScannerStartError( homeassistant.components.bluetooth.scanner.ScannerStartError: hci0 (54:27:1E:7A:96:B4): Failed to start Bluetooth: [org.bluez.Error.InProgress] Operation already in progress

toketin avatar Jan 20 '23 06:01 toketin

Hey guys, this is also happening to me, started happening when i migrated sd and went from the 32 to the 64 bit version of HA for the raspberry. I also noticed that I get some random spikes on my BT sensors, like -100ºC. If there is anything i can do to help diagnose it I will be happy to do so.

EndermanAPM avatar Jan 20 '23 08:01 EndermanAPM

I have the same issue as well, RPI 3b+; Every 5-6 days I have to disconnect the RPI and reconnect to get it work again. I am using the internal BT.

parabag avatar Jan 20 '23 17:01 parabag

Hi, I've fixed the issue using a dongle bluetooth usb.

toketin avatar Jan 21 '23 16:01 toketin

Hi, I've fixed the issue using a dongle bluetooth usb.

This is not what I would call a fix.

EndermanAPM avatar Jan 24 '23 15:01 EndermanAPM

latest HA update has some blueooth updates, which appear to be related? https://developers.home-assistant.io/blog/2023/01/12/bluetooth-adapters/

any one have experience? don't usually update on x.0

bobloadmire avatar Feb 02 '23 17:02 bobloadmire

I also have this issue with rpi4 using the built in bluetooth, raspbian, 2023.2.1 container. Bluetooth seems to work for an hour or two (devices are connected and report information) after reboot and/or bluetooth service restart, but eventually gets caught in the timeout loop. I have made sure to update the latest bluez/bluetooth packages, map dbus volume in container. I know it works because I can use the devices

Something i noticed tinkering around with bluetoothctl is that when the bluetooth integration is enabled the logs spam devices constantly with all the devices i can see. Bluetoothctl will not del the devices either until i disable the integration or manually power off in bluetoothctl. Running a manual power off will get the discoverable to stop but i guess the integration kicks it back on after next interval. Turning off the Enable newly added entities option in settings does not fix the issue.

Wondering if the integration is causing bluetoothctl to constantly scan for new devices. Cant find a way to tune this setting either, tried using the bluetooth tracker and ble tracker interval_seconds and increase the interval but that doesnt seem to change anything.

Maybe this helps with diagnosing the issue

Some of my logs

2023-02-04 11:16:34.524 DEBUG (MainThread) [btsocket.btmgmt_protocol] Socket Read: <event_code=CommandCompleteEvent, controller_idx=0, param_len=283> <command_opcode=ReadControllerInformation, status=Success> <address=DC:A6:32:0A:93:9E, bluetooth_version=9, manufacturer=305, supported_settings=114431, current_settings={Powered: True, Connectable: False, FastConnectable: False, Discoverable: False, Bondable: True, 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=3932160, name=b'raspberrypi', short_name=0>
2023-02-04 11:16:34.525 DEBUG (MainThread) [bluetooth_auto_recovery.recover] Power state of bluetooth adapter hci0 [DC:A6:32:0A:93:9E] is ON after power cycle
2023-02-04 11:16:36.028 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (DC:A6:32:0A:93:9E): adapter reset result: True
2023-02-04 11:16:36.028 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (DC:A6:32:0A:93:9E): Starting bluetooth discovery attempt: (2/3)
2023-02-04 11:16:49.275 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (DC:A6:32:0A:93:9E): Scanner watchdog time_since_last_detection: 136.65873593
2023-02-04 11:16:49.276 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (DC:A6:32:0A:93:9E): Scanner is already restarting, deferring restart
2023-02-04 11:16:51.030 ERROR (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (DC:A6:32:0A:93:9E): Failed to restart Bluetooth scanner: hci0 (DC:A6:32:0A:93:9E): Timed out starting Bluetooth after 15 seconds
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 219, in _async_start
    await self.scanner.start()  # type: ignore[no-untyped-call]
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 156, in start
    await self._backend.start()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 191, in start
    self._stop = await manager.active_scan(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 360, in active_scan
    reply = await self._bus.call(
  File "/usr/local/lib/python3.10/site-packages/dbus_fast/aio/message_bus.py", line 371, in call
    await future
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 218, in _async_start
    async with async_timeout.timeout(START_TIMEOUT):
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.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 346, in _async_restart_scanner
    await self._async_start()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/scanner.py", line 264, in _async_start
    raise ScannerStartError(
homeassistant.components.bluetooth.scanner.ScannerStartError: hci0 (DC:A6:32:0A:93:9E): Timed out starting Bluetooth after 15 seconds
2023-02-04 11:16:52.319 DEBUG (MainThread) [homeassistant.components.bluetooth] Triggering bluetooth usb discovery
2023-02-04 11:16:57.332 DEBUG (MainThread) [homeassistant.components.bluetooth] Rediscovered adapters: {'hci0': {'address': 'DC:A6:32:0A:93:9E', 'sw_version': 'raspberrypi', 'hw_version': 'usb:v1D6Bp0246d0537', 'passive_scan': False, 'manufacturer': 'Raspberry Pi Trading Ltd', 'product': None, 'vendor_id': None, 'product_id': None}}

brodly avatar Feb 04 '23 20:02 brodly

Can you try patching dbus-broker with this PR https://github.com/bus1/dbus-broker/pull/308

bdraco avatar Feb 04 '23 20:02 bdraco

Which is in dbus-broker v33 https://github.com/bus1/dbus-broker/releases

bdraco avatar Feb 04 '23 20:02 bdraco

ya give me a few, im not the best with packaging.

brodly avatar Feb 04 '23 20:02 brodly

hmm, looks like bluetooth controller is no longer detected by either bluetoothctl or HA. Built v33 for bullseye, installed, enabled service and rebooted.

brodly avatar Feb 04 '23 21:02 brodly

getting errors like ERROR:lib/bluez/adapter.c:165:adapter_get_dbus_object_path: assertion failed: (ADAPTER_IS(self)) i assume this version is incompatible with bullseye

brodly avatar Feb 04 '23 21:02 brodly

reverted back to latest dbus-broker upstream and everything is back up and running. interestingly enough im not getting any device spam in bluetoothctl. Ill keep an eye on that and HA logs and report back. Maybe it was a bad dbus-broker install

brodly avatar Feb 04 '23 21:02 brodly

Another thing I just noticed is that I had some Govee Bluetooth sensors bridged with the HomeKit integration. HomeKit was reporting some warnings:

Cannot add sensor.bedroom_govee_thermometer_humidity as this would exceed the 150 device limit. Consider using the filter option Cannot add sensor.bedroom_govee_thermometer_temperature as this would exceed the 150 device limit. Consider using the filter option

seems off that I'm hitting a device limit when I only have 2 bt devices with 3 entries each

brodly avatar Feb 05 '23 20:02 brodly