ashald / home-assistant-lywsd02

A customer component for HomeAssistant to configure LYWSD02
The Unlicense
22 stars 0 forks source link

TimeOut Error #6

Open ZoidbergZulu opened 7 months ago

ZoidbergZulu commented 7 months ago

Hi! Thanks for this project which could finally solve my lagging e-ink clocks around the house. Unfortunately, I don't seem to get it to work as it runs into timeout all the time. I'm using four BLE proxies, one of which very close to the clock in question.

Here's the log of the ESP32 connecting to the watch:

[12:55:58][I][bluetooth_proxy:282]: [0] [XX:XX:XX:XX:XX:XX] Connecting v3 without cache [12:55:58][D][esp32_ble_tracker:215]: Pausing scan to make connection... [12:55:58][I][esp32_ble_client:067]: [0] [XX:XX:XX:XX:XX:XX] 0x00 Attempting BLE connection [12:56:07][D][esp32_ble_client:110]: [0] [XX:XX:XX:XX:XX:XX] ESP_GATTC_CONNECT_EVT [12:56:07][D][esp32_ble_client:110]: [0] [XX:XX:XX:XX:XX:XX] ESP_GATTC_OPEN_EVT [12:56:07][D][esp32_ble_tracker:266]: Starting scan... [12:56:08][I][esp32_ble_client:084]: [0] [XX:XX:XX:XX:XX:XX] Disconnecting. [12:56:08][D][esp-idf:000]: E (57775) BT_GATT: GATTC_ConfigureMTU GATT_BUSY conn_id = 3

[12:56:08][D][esp32_ble_client:110]: [0] [XX:XX:XX:XX:XX:XX] ESP_GATTC_SEARCH_CMPL_EVT [12:56:08][I][esp32_ble_client:227]: [0] [XX:XX:XX:XX:XX:XX] Connected [12:56:08][D][esp32_ble_client:110]: [0] [XX:XX:XX:XX:XX:XX] ESP_GATTC_CLOSE_EVT [12:56:08][D][esp32_ble_client:172]: [0] [XX:XX:XX:XX:XX:XX] ESP_GATTC_DISCONNECT_EVT, reason 22

The time on the clock is not set and the HA log file shows a time out error:

File "/config/custom_components/lywsd02/init.py", line 78, in set_time async with BleakClient(ble_device) as client: 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 300, 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_esphome/backend/client.py", line 79, in _async_wrap_bluetooth_operation raise asyncio.TimeoutError(str(err)) from err TimeoutError: Timeout waiting for connect response while connecting to XX:XX:XX:XX:XX:XX after 10.0s, disconnect timed out: True, after 20.0s

Setting the clock via the webapp (https://saso5.github.io/LYWSD02-clock-sync/) works just fine.

Any help is greatly appreciated :).

lranders commented 7 months ago

@ZoidbergZulu I have no experience with that clock sync thingie, but it sounds like you have a bit of a complex network going.

Is it possible for you to move the clock closer to the HA base radio perhaps and see if that makes any difference? If you have another Linux box, how does gattool work if say, you connected directly to the clock from it?

I think we should try to simplify your setup a bit and then start to rule out some of the variables in the puzzle. Does that sound like a viable path forward?

ZoidbergZulu commented 6 months ago

Thanks for your reply @lranders. The situation of the matter is that my HA box runs in my basement without any physical bluetooth devices. I use a range of ESP32 boards as bluetooth proxies which works fine so far. I understand that I could use the service without having a physical bluetooth device present, or am I mistaken?

lranders commented 6 months ago

I am not completely sure, as I have no experience with ESP32 proxy devices.

I was curious as to whether you could get the clock to work if it was close enough to your HA box, i.e. put the clock in the basement as an experiment and see if the script works when it is then.

Just out of curiosity, can you give some examples of end-point-devices that do work through your proxies?

wnoisephx commented 6 months ago

i have the same issue. Only difference is that I can run mine off the hosts bluetooth dongle. 024-04-22 12:44:29.253 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2024-04-22 12:44:29.253 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service 2024-04-22 12:44:29.253 INFO (MainThread) [custom_components.lywsd02] Found 'E7:2E:00:22:AC:AD: LYWSD02' - Attempting to update time. 2024-04-22 12:44:35.462 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: [org.bluez.Error.InvalidArguments] Invalid Length Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 507, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step response_data = await self._async_run_long_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action return await long_task ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/lywsd02/init.py", line 83, in set_time await client.write_gatt_char(_UUID_TIME, data_clock_mode) File "/usr/local/lib/python3.12/site-packages/bleak/init.py", line 776, in write_gatt_char await self._backend.write_gatt_char(characteristic, data, response) File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 861, in write_gatt_char assert_reply(reply) File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply raise BleakDBusError(reply.error_name, reply.body) bleak.exc.BleakDBusError: [org.bluez.Error.InvalidArguments] Invalid Length 2024-04-22 12:44:35.469 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140220474442560] Error handling message: Unknown error (unknown_error) Homeassist (Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 794, in handle_execute_script script_result = await script_obj.async_run( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1713, in async_run return await asyncio.shield(create_eager_task(run.async_run())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 509, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 539, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 507, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step response_data = await self._async_run_long_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action return await long_task ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/lywsd02/init.py", line 83, in set_time await client.write_gatt_char(_UUID_TIME, data_clock_mode) File "/usr/local/lib/python3.12/site-packages/bleak/init.py", line 776, in write_gatt_char await self._backend.write_gatt_char(characteristic, data, response) File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 861, in write_gatt_char assert_reply(reply) File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply raise BleakDBusError(reply.error_name, reply.body) bleak.exc.BleakDBusError: [org.bluez.Error.InvalidArguments] Invalid Length Connected

If I setup an esp32 bluetooth proxyI get: 024-04-22 12:21:47.000 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2024-04-22 12:21:47.000 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service 2024-04-22 12:21:47.000 INFO (MainThread) [custom_components.lywsd02] Found '17:75:BD:60:D8:F9: LYWSD02' - Attempting to update time. 2024-04-22 12:21:50.049 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Bluetooth GATT Error address=17:75:BD:60:D8:F9 handle=62 error=13 description=Invalid attribute length Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/bleak_esphome/backend/client.py", line 77, in _async_wrap_bluetooth_operation return await func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/bleak_esphome/backend/client.py", line 596, in write_gatt_char await self._client.bluetooth_gatt_write( File "/usr/local/lib/python3.12/site-packages/aioesphomeapi/client.py", line 808, in bluetooth_gatt_write await self._bluetooth_gatt_write( File "/usr/local/lib/python3.12/site-packages/aioesphomeapi/client.py", line 846, in _bluetooth_gatt_write await self._send_bluetooth_message_await_response( File "/usr/local/lib/python3.12/site-packages/aioesphomeapi/client.py", line 470, in _send_bluetooth_message_await_response raise BluetoothGATTAPIError(BluetoothGATTError.from_pb(resp)) aioesphomeapi.core.BluetoothGATTAPIError: Bluetooth GATT Error address=17:75:BD:60:D8:F9 handle=62 error=13 description=Invalid attribute length

lranders commented 6 months ago

@wnoisephx I believe your issue isn't related to the one at hand. Please open a seperate issue! T. I. A.

lranders commented 6 months ago

@ZoidbergZulu This line looks suspect:

[12:56:08][D][esp-idf:000]: E (57775) BT_GATT: GATTC_ConfigureMTU GATT_BUSY conn_id = 3

Also, can you tell us what reason 22 is and what firmware you're running on those ESPs?

clau-bucur commented 4 months ago

Having the same issue, with 3 clocks and one ESPHome BLE proxy:

2024-07-10 09:40:19.473 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Timeout waiting for connect response while connecting to E7:2E:00:D2:XX:XX after 10.0s, disconnect timed out: False,  after 20.0s
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioesphomeapi/client.py", line 578, in bluetooth_device_connect
    await connect_future
TimeoutError

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/bleak_esphome/backend/client.py", line 77, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak_esphome/backend/client.py", line 297, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.12/site-packages/aioesphomeapi/client.py", line 598, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to E7:2E:00:D2:XX:XX after 10.0s, disconnect timed out: False,  after 20.0s

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/lywsd02/__init__.py", line 78, in set_time
    async with BleakClient(ble_device) as client:
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 570, in __aenter__
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/habluetooth/wrappers.py", line 310, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 615, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak_esphome/backend/client.py", line 79, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
TimeoutError: Timeout waiting for connect response while connecting to E7:2E:00:D2:XX:XX after 10.0s, disconnect timed out: False,  after 20.0s
lranders commented 4 months ago

@clau-bucur Same problem as who?

From what I'm reading, your HA isn't able to connect with any of your clocks... I know it's not quite the same, but have you tried the phone app from the exact same place as where ever your HA box is? Have you tried this with the clocks right next to the HA box?

You wouldn't happen to have an rPI 4 or 5 where you could try connecting to the clocks or at least try to scan for them, to see if they're even alive on the network?

clau-bucur commented 4 months ago

@clau-bucur Same problem as who? As the OP, at least from my understanding of the exception, in both our cases the component times-out while trying to sync the clock.

From what I'm reading, your HA isn't able to connect with any of your clocks... I know it's not quite the same, but have you tried the phone app from the exact same place as where ever your HA box is? Have you tried this with the clocks right next to the HA box?

You wouldn't happen to have an rPI 4 or 5 where you could try connecting to the clocks or at least try to scan for them, to see if they're even alive on the network?

It seems to have been some temporary problem... Not sure. I moved the clocks near the proxy and all of them synced properly. Then I moved them back to their location and again they synced.

lranders commented 4 months ago

@clau-bucur I'm happy you got it working!

klim123123 commented 1 month ago

I have two lywsd02mmc One works fine with home-assistant-lywsd02 and another always shows: Failed to perform the action lywsd02.set_time. Timeout This is exactly the same devices, i bought them at one store on the same time. The second one works with ESPHome script and other online configurator, but not with home-assistant-lywsd02

klim123123 commented 1 month ago

after i updated my HA to 2024.10 both of my lywsd02mmc stated to sync and no more TimeOut Error.

elektrinis commented 1 week ago

I get timeout error when doing service call. I have 4 clocks, 3 BLE proxies and one bluetooth adapter in the HA box (one clock close by). I get these errors on all four clocks. Anyone managed to solve this?

klim123123 commented 1 week ago

I get timeout error when doing service call. I have 4 clocks, 3 BLE proxies and one bluetooth adapter in the HA box (one clock close by). I get these errors on all four clocks. Anyone managed to solve this?

make sure your BLE proxies are in active mode.

elektrinis commented 1 week ago

make sure your BLE proxies are in active mode.

how?

klim123123 commented 1 week ago

make sure your BLE proxies are in active mode.

how?

in ESPHome just use active: trueunder bluetooth_proxy:

elektrinis commented 1 week ago

make sure your BLE proxies are in active mode.

how?

in ESPHome just use active: trueunder bluetooth_proxy:

Just checked. I already have this in my config.

elektrinis commented 1 week ago

Here's my log:


Source: helpers/script.py:525
integration: Automation (documentation, issues)
First occurred: November 7, 2024 at 05:00:12 (2 occurrences)
Last logged: 05:00:15

LYWSD02 time set: Error executing script. Unexpected error for call_service at pos 2:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 214, in connect
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/dbus_fast/aio/message_bus.py", line 385, 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/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/lywsd02/__init__.py", line 78, in set_time
    async with BleakClient(ble_device) as client:
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 570, in __aenter__
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/habluetooth/wrappers.py", line 311, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 615, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 151, 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`