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.14k stars 29.81k forks source link

Timeout on connect #117069

Closed mar-schmidt closed 1 month ago

mar-schmidt commented 4 months ago

The problem

Homeassistant can identify the bluetooth signal and allows me to set up the integration, but whenever I try to start the fan or start the lights Im getting a timeout. My BT device is a BCM20702A0 (0b05:17cb) by Broadcom Corp

Bluetooth integration using Fjärråskupans iOS application works fine at all times.

What version of Home Assistant Core has the issue?

core-2024.5.2

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

fjärråskupan

Link to integration documentation on our website

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

Diagnostics information

Home Assistant Log May 8 2024.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Log details (ERROR)
Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:239
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:46:20 AM (6 occurrences)
Last logged: 12:04:26 PM

[140337361935680] Unexpected exception
[140337136285760] Unexpected exception
[140337501464256] Unexpected exception
[140337497755712] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 209, in connect
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/dbus_fast/aio/message_bus.py", line 384, 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/local/lib/python3.12/site-packages/fjaraskupan/__init__.py", line 197, in _connect
    self._client = await self._client_stack.enter_async_context(BleakClient(address_or_ble_device))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/contextlib.py", line 659, in enter_async_context
    result = await _enter(cm)
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 565, in __aenter__
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/habluetooth/wrappers.py", line 309, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 605, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 146, in connect
    async with async_timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, 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/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 627, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/fjaraskupan/light.py", line 54, in async_turn_on
    async with self.coordinator.async_connect_and_update() as device:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/fjaraskupan/coordinator.py", line 93, in async_connect_and_update
    async with self.device.connect(ble_device) as device:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fjaraskupan/__init__.py", line 215, in connect
    await self._connect(address_or_ble_device)
  File "/usr/local/lib/python3.12/site-packages/fjaraskupan/__init__.py", line 200, in _connect
    raise FjaraskupanTimeout("Timeout on connect") from exc
fjaraskupan.FjaraskupanTimeout: Timeout on connect

Additional information

No response

home-assistant[bot] commented 4 months ago

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

Code owner commands Code owners of `fjaraskupan` 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 fjaraskupan` 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)


fjaraskupan documentation fjaraskupan source (message by IssueLinks)

mar-schmidt commented 4 months ago

The signal strength sensor has a value of -98 dBm

elupus commented 4 months ago

Likely a problem with the bluetooth dongle. Any way you could try an esp32 ble gateway?

mar-schmidt commented 4 months ago

I can look into it. FYI my bt device works fine with ha's plejd integration. Not sure if that makes a difference

elupus commented 4 months ago

Btw. Turn off bluetooth temporarily on your phone when testing (and possibly powercycle the fan on your house breakers). The fan can only handle one connection at a time. So if your phone keeps a connection (or the fan thinks it does) it will not accept anything new.

mar-schmidt commented 4 months ago

Unfortunately that didnt make a difference

metalmumin commented 2 months ago

Have had a similar issue recently, which happened when I cut all power in the house. After restarting the fan with the circuit breaker, as @elupus suggested, it reassociated.

Then today after having the same issue, it was because the fan had associated with my phone's Fjäråskupan app which I used to debug the prior issue. This time it sufficed to turn off Bluetooth on the phone, uninstall the app, then reboot the Home Assistant Yellow. Which worked, as @elupus also suggested.

Also note, my Fjäråskupan fan has the rotary wheel control, and a damper (in Swedish "spjäll"), which means both of the fan's motherboard I2C ports were already occupied - meaning there's no third connector for the bluetooth controller. But this is possible to workaround. To workaround this I added one more 'Molex 903270306' to the already long panel connector cable. With another Molex connection the rotary wheel control and the fan's Bluetooth module can share the same I2C port on the Fjäråskupan motherboard. The trick is (important) to connect them such that the motherboard I2C port connector from the motherboard branches out to Bluetooth on one side, and rotary panel on the other side, meaning: fan panel & bluetooth module are not connected in serial. Connecting them serially results in garbage signals. Overall: this way the Fjaraskupan Bluetooth module can be installed even on Fans that technically can't have the Bluetooth module in the first place, due to lack of free I2C ports. This is of course a solution that isn't supported by Fjaraskupan, just something I had to do myself out of necessity.

Slightly off topic, but just to share. Note that I'm using a slightly modified version of this integration (attaching patch balow), such that only house ventilation is controlled. This is because I'm using https://community.home-assistant.io/t/bathroom-humidity-exhaust-fan/509992 integration together with 'Bosch Smart Home Room Thermostat II 230V' in the restrooms, which controls floor heating, and has a humidity sensor. When the humidity sensor triggers the 'Bathroom Humidity Exhaust Fan' automation, it only sends an ON/OFF signal, hence the attached patch was required to ensure 'after_cooking_manual' is the only option in the Fjaraskupan integration, such that it can be triggered using 'Bathroom Humidity Exhaust Fan' automation's ON/OFF directives. Works quite well: bathrooms get ventilated, and any ongoing mode can get overridden at the panel. Hope this helps someone. Cheers!

fjaraskupan_bathroom_exhaust_fan_mod_v2.patch

metalmumin commented 2 months ago

One more update on this, but I have another observation.

I do notice however that 'Timeout on connect' happens from time to time, despite no Bluetooth device in my home has the Fjäråskupan app installed. Interestingly enough, when this happens, a 'HA restart' helps, and the fan re-associates (NOTE: not a system reboot of the Home Assistant Yellow).

I'm suspecting that the Fjäråskupan bluetooth module has some form of list of known prior associated devices, which it will proactively attempt to associate with. This is of course just a theory, but it would be a PITA if true.

Also, it's interesting that 'HA restart' actually helps, as that's just a reboot of the automations and script, and not the complete system - hence a software workaround for this should be possible.

Home Assistant Yellow: Core 2024.6.4 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240610.1

elupus commented 1 month ago

I'm going to close this. The mentioned bluetooth adapter is listed on https://www.home-assistant.io/integrations/bluetooth/ as needing additional OS level patches. So please try with a known good bluetooth dongle and see if it works better.