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.73k forks source link

After update from 2023.2.5 to 2023.3.6 esphome bluetooth stack takes 25 to retry connecting after error (error not seen) #90265

Closed KitHubek closed 1 year ago

KitHubek commented 1 year ago

The problem

As a topic. As we know, since 2023.3 update we had problem with error index array out of range. We have update HA 2023.3.6 and this problem was fixed, but, new problem happends.

Lock FW is newest

Iam using BT-proxy - just say this to know that BT connections and signal strength should be very fine. Hardware with High performance bt dongle, 3m USB cable, away from USB 3.0 ports. Till 2023.x HA everything working very well.

Now problem is, that lock goes offline. Not unavialable, just offline - this says log. Cant connect to it, via HA. BT proxy log, says this, HA logs too. Connection takes over 50 seconds. I must say, that if i using Switchbot app - everything working ok, lock/unlock takes less than 1 sec.

And i have other devices from Switchbot and everyone working ok, without problem, without delay etc.

What version of Home Assistant Core has the issue?

2023.3.6

What was the last working version of Home Assistant Core?

2023.2.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

SwitchBot

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

C1:89:44:4B:2B:A5

From bbt proxy log:

[13:14:00][I][bluetooth_proxy:250]: [0] [lockmacaddress] Connecting v3 with cache
[13:14:00][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[13:14:00][I][esp32_ble_client:064]: [0] [lockmacaddress] 0x01 Attempting BLE connection
......
[13:14:01][W][esp32_ble_client:134]: [0] [] Connection failed, status=133
.....
.....
[13:14:51][D][esp-idf:000]: W (60434078) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

as You see, from unlock command to completed and lock unlock - 51sec

from HA logs:

Logger: homeassistant.core
Source: components/switchbot/lock.py:54
First occurred: 12:43:35 (1 occurrences)
Last logged: 12:43:35

Error executing service: <ServiceCall lock.unlock (c:01GWC96ENHARJM7KZGYPZCJM69): entity_id=['lock.zamek_switchbot']>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 550, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 549, in bluetooth_device_connect
    async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 100, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 314, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 575, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 342, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 249, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1826, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 106, in _async_unlock
    await entity.async_unlock(**remove_entity_service_fields(service_call))
  File "/usr/src/homeassistant/homeassistant/components/switchbot/lock.py", line 54, in async_unlock
    self._last_run_success = await self._device.unlock()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 168, in unlock
    return await self._lock_unlock(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 189, in _lock_unlock
    await self._enable_notifications()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 255, in _enable_notifications
    result = await self._send_command(COMMAND_ENABLE_NOTIFICATIONS)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 299, in _send_command
    result = await self._ensure_encryption_initialized()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 314, in _ensure_encryption_initialized
    result = await self._send_command(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 297, in _send_command
    return await super()._send_command(key[:2] + "000000" + key[2:], retry)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command
    return await self._send_command_locked(key, command)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 397, in _send_command_locked
    await self._ensure_connected()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 264, in _ensure_connected
    client: BleakClientWithServiceCache = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 359, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 308, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError:  (lockmacaddress) - lockmacaddress: Failed to connect: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

and

Logger: switchbot.devices.device
Source: /usr/local/lib/python3.10/site-packages/switchbot/devices/device.py:182
First occurred: 12:43:35 (1 occurrences)
Last logged: 12:43:35

(lockmacaddress): device not found, no longer in range, or poor RSSI: -73
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 550, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 549, in bluetooth_device_connect
    async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 100, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 314, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 575, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 342, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 249, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command
    return await self._send_command_locked(key, command)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 397, in _send_command_locked
    await self._ensure_connected()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 264, in _ensure_connected
    client: BleakClientWithServiceCache = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 359, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 308, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError:  (lockmacaddress) - lockmacaddress: Failed to connect: Timeout waiting for connect response while connecting to lockmacaddress after 20.0s, disconnect timed out: True,  after 5.0s

Additional information

No response

home-assistant[bot] commented 1 year ago

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

Code owner commands Code owners of `switchbot` 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 switchbot` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


switchbot documentation switchbot source (message by IssueLinks)

KitHubek commented 1 year ago

i downgrade HA to 2023.2.5 and problem non exsist. Lock and all other devices from SwitchBot workind excellent

bdraco commented 1 year ago

I would try to solve your other issue first as it seems your instance is being overloaded by something which will make this very difficult to track down:

https://github.com/home-assistant/core/issues/90281

KitHubek commented 1 year ago

@bdraco please look at this comment: https://github.com/home-assistant/core/issues/89061#issuecomment-1484071685

the same problem as mine

bdraco commented 1 year ago

@bdraco please look at this comment: https://github.com/home-assistant/core/issues/89061#issuecomment-1484071685

the same problem as mine

There's no logs in that comment to indicate that the problem is the same so I think it's a bit premature to make that conclusion

Bluetooth devices have so many failure modes that it's best not to drawn conclusions too quickly especially without logs as we can end up spending months trying to solve the wrong problem

KitHubek commented 1 year ago

ok, so what i should to do? This is crazy, because when i downgrade to 2023.2.5 ha version problem was fixed and working till now without any errors.

bdraco commented 1 year ago

ok, so what i should to do?

This is crazy, because when i downgrade to 2023.2.5 ha version problem was fixed and working till now without any errors.

If you mail me the lock and the Bluetooth proxy I'm sure I can figure out what's going wrong.

KitHubek commented 1 year ago

thanks, but its impossible, because this devixes are on production and if i send You devices i and all users cant enter home.

bdraco commented 1 year ago

Here are a few options

bdraco commented 1 year ago

You could also try posting the logs with debug for for switchbot enabled in case there is something more obvious going on there

bdraco commented 1 year ago

I added some more debug logging as well in https://github.com/home-assistant/core/pull/90317 which will be in 2023.3.7

Note that this is not a fix. Its only to make it easier to track down the issue

KitHubek commented 1 year ago

ok, when avialable 2023.3.7 will update and send logs here. For now stays on 2023.2.5 because its lastes ver. working ok

KitHubek commented 1 year ago

today updated to 2023.4 HA core and problem still exsist. Lock seems to goes to something as sleep mode after some time. And then when i try to unlock via mobile app i must wait about 1 minutes or more to lock do action unlock. After this, lock workin ok, but if i not unlocking it some time, again must wait much time to response from lock.

Iam using bt proxy, and this problem NO exsist in version 2023.2.6 and lower, From version 2023.3 and higher this problem is all time

I turned on debug mode on SwitchBot integration, and here is log:

Logger: homeassistant.core Source: components/switchbot/lock.py:54 First occurred: 12:41:24 (1 occurrences) Last logged: 12:41:24

Error executing service: <ServiceCall lock.unlock (c:01GXB2D587KQ78QC6XK1EX8BH7): entity_id=['lock.switchbot']> Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 555, in bluetooth_device_connect await event.wait() File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 554, in bluetooth_device_connect async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation return await func(self, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect await self._client.bluetooth_device_connect( File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 580, in bluetooth_device_connect raise TimeoutAPIError( aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 344, in establish_connection await client.connect( File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 269, in connect connected = await super().connect(kwargs) File "/usr/local/lib/python3.10/site-packages/bleak/init.py", line 531, in connect return await self._backend.connect(kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation raise asyncio.TimeoutError(str(err)) from err asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1838, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 1857, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 216, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 798, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 977, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 838, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/lock/init.py", line 106, in _async_unlock await entity.async_unlock(**remove_entity_service_fields(service_call)) File "/usr/src/homeassistant/homeassistant/components/switchbot/lock.py", line 54, in async_unlock self._last_run_success = await self._device.unlock() File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 168, in unlock return await self._lock_unlock( File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 189, in _lock_unlock await self._enable_notifications() File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 255, in _enable_notifications result = await self._send_command(COMMAND_ENABLE_NOTIFICATIONS) File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 299, in _send_command result = await self._ensure_encryption_initialized() File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 314, in _ensure_encryption_initialized result = await self._send_command( File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 297, in _send_command return await super()._send_command(key[:2] + "000000" + key[2:], retry) File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command return await self._send_command_locked(key, command) File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 414, in _send_command_locked await self._ensure_connected() File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 274, in _ensure_connected client: BleakClientWithServiceCache = await establish_connection( File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 361, in establish_connection _raise_if_needed(name, device.address, exc) File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 310, in _raise_if_needed raise BleakNotFoundError(msg) from exc bleak_retry_connector.BleakNotFoundError: LOCKMACADDRESS (LOCKMACADDRESS) - LOCKMACADDRESS: Failed to connect: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

and

Logger: switchbot.devices.device Source: /usr/local/lib/python3.10/site-packages/switchbot/devices/device.py:182 First occurred: 12:41:24 (1 occurrences) Last logged: 12:41:24

(LOCKMACADDRESS): device not found, no longer in range, or poor RSSI: -68 Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 555, in bluetooth_device_connect await event.wait() File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 554, in bluetooth_device_connect async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation return await func(self, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect await self._client.bluetooth_device_connect( File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 580, in bluetooth_device_connect raise TimeoutAPIError( aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 344, in establish_connection await client.connect( File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 269, in connect connected = await super().connect(kwargs) File "/usr/local/lib/python3.10/site-packages/bleak/init.py", line 531, in connect return await self._backend.connect(kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation raise asyncio.TimeoutError(str(err)) from err asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command return await self._send_command_locked(key, command) File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 414, in _send_command_locked await self._ensure_connected() File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 274, in _ensure_connected client: BleakClientWithServiceCache = await establish_connection( File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 361, in establish_connection _raise_if_needed(name, device.address, exc) File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 310, in _raise_if_needed raise BleakNotFoundError(msg) from exc bleak_retry_connector.BleakNotFoundError: LOCKMACADDRESS (LOCKMACADDRESS) - LOCKMACADDRESS: Failed to connect: Timeout waiting for connect response while connecting to LOCKMACADDRESS after 20.0s, disconnect timed out: True, after 5.0s

and

Logger: aioesphomeapi.connection Source: runner.py:179 First occurred: 12:34:19 (1 occurrences) Last logged: 12:34:19

bt-proxy-esp32 @ 192.168.10.206: Connection error occurred: [Errno 104] Connection reset by peer

bdraco commented 1 year ago

bt-proxy-esp32 @ 192.168.10.206: Connection error occurred: [Errno 104] Connection reset by peer

Your esphome proxy is likely crashing.

Make sure you have the latest firmware and try reducing the config https://esphome.io/components/bluetooth_proxy.html

KitHubek commented 1 year ago

i have fw 2023.3.2 (Apr 6 2023, 10:49:32) and i dont think that this is the main problem, because if i downgrade HA to 2023.2.x version problem NO exsist. And if i update to nevest HA fw - problem as i wrote.

KitHubek commented 1 year ago

INFO Reading configuration /config/esphome/bt-proxy-esp32.yaml... INFO Starting log output from bt-proxy-esp32.local using esphome API INFO Successfully connected to bt-proxy-esp32.local [23:25:31][I][app:102]: ESPHome version 2023.3.2 compiled on Apr 6 2023, 10:49:32 [23:25:31][I][app:104]: Project esphome.bluetooth-proxy version 1.0

[23:25:31][C][wifi:362]: Local MAC: xx:xx:xx:xx:xx [23:25:31][C][wifi:363]: SSID: [redacted] [23:25:31][C][wifi:364]: IP Address: xxxxx [23:25:31][C][wifi:366]: BSSID: [redacted]

[23:25:31][C][wifi:369]: Signal strength: -51 dB ▂▄▆█ [23:25:31][C][wifi:373]: Channel: 6 [23:25:31][C][wifi:374]: Subnet: 255.255.255.0 [23:25:31][C][wifi:375]: Gateway: xxxxx [23:25:31][C][wifi:376]: DNS1: xxxxx [23:25:31][C][wifi:377]: DNS2: xxxxx

[23:25:31][C][logger:294]: Level: DEBUG [23:25:31][C][esp32_ble:214]: ESP32 BLE: [23:25:31][C][esp32_ble_tracker:591]: BLE Tracker: [23:25:31][C][esp32_ble_tracker:592]: Scan Duration: 300 s [23:25:31][C][esp32_ble_tracker:593]: Scan Interval: 320.0 ms [23:25:31][C][esp32_ble_tracker:594]: Scan Window: 30.0 ms [23:25:31][C][esp32_ble_tracker:595]: Scan Type: ACTIVE [23:25:31][C][esp32_ble_tracker:596]: Continuous Scanning: True

[23:25:31][C][mdns:109]: Hostname: bt-proxy-esp32 [23:25:31][C][ota:093]: Over-The-Air Updates: [23:25:31][C][ota:094]: Address: bt-proxy-esp32.local:3232 [23:25:31][C][api:138]: API Server: [23:25:31][C][api:139]: Address: bt-proxy-esp32.local:6053 [23:25:31][C][api:143]: Using noise encryption: NO [23:25:31][C][improv_serial:032]: Improv Serial:

KitHubek commented 1 year ago

and here is my config:

substitutions: name: "bt-proxy-esp32" packages: esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/esp32-generic.yaml@main esphome: name: ${name} name_add_mac_suffix: false

wifi: ssid: !secret wifi_ssid password: !secret wifi_password

bdraco commented 1 year ago

Try doing a serial flash to make sure nvs is cleared (use a cable instead of ota)

jpconfessor commented 1 year ago

I've experienced the same problem today.. but now, after trying to collect diagnostics from both, HA and esphome bt proxy, the lock works every single time... I will let it sit for like, 1h, and try again. Sometimes it takes waaay longer, like this in this one.. 24s:

[18:54:06][W][esp32_ble_client:134]: [0] [] Connection failed, status=133
[18:54:06][D][esp32_ble_tracker:246]: Starting scan...
[18:54:30][I][bluetooth_proxy:250]: [0] [F9:0B:22:xxxxxxxx] Connecting v3 with cache
[18:54:30][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[18:54:30][I][esp32_ble_client:064]: [0] [F9:0B:22:xxxxxxxx] 0x01 Attempting BLE connection
[18:54:30][I][esp32_ble_client:144]: [0] [F9:0B:22:xxxxxxxx] Connected
[18:54:30][D][esp32_ble_tracker:246]: Starting scan...

This happened after upgrading HA from 2023.3.6 to 2023.4.0 ESPHome version 2023.3.2


udpate: Even after a while, the lock is taking a long time to respond, between 20-40s Rolling back to 2023.3.6 fixed the problem like others mentioned.

Logs from after the downgrade - it only takes 1s: unlocking

[19:15:02][I][bluetooth_proxy:254]: [0] [F9:0B:22:xxxxxxxx] Connecting v3 without cache
[19:15:02][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[19:15:02][I][esp32_ble_client:064]: [0] [F9:0B:22:xxxxxxxx] 0x01 Attempting BLE connection
[19:15:02][D][esp-idf:000]: W (886091) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
[19:15:03][D][esp-idf:000]: W (886301) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
[19:15:03][D][esp-idf:000]: W (886406) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
[19:15:03][I][esp32_ble_client:196]: [0] [F9:0B:22:xxxxxxxx] Connected

locking:

[19:16:49][I][bluetooth_proxy:250]: [0] [F9:0B:22:xxxxxxxx] Connecting v3 with cache
[19:16:49][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[19:16:49][I][esp32_ble_client:064]: [0] [F9:0B:22:xxxxxxxx] 0x01 Attempting BLE connection
[19:16:49][I][esp32_ble_client:144]: [0] [F9:0B:22:xxxxxxxx] Connected
KitHubek commented 1 year ago

ok, i do flash via PC and USB cable. Now has config near from here, as You posted: https://esphome.io/components/bluetooth_proxy.html#complete-sample-recommended-configuration

substitutions:
  name: bt-proxy
  friendly_name: BT-Proxy
  board: esp32dev
packages:
  esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/esp32-generic.yaml@main
esphome:
  name: ${name}
  name_add_mac_suffix: false
  friendly_name: ${friendly_name}
esp32:
  board: ${board}
  framework:
    type: esp-idf
api:
  encryption:
    key: somesecretkey
esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

and start log fro ESP HOME:

INFO Reading configuration /config/esphome/bt-proxy.yaml...
INFO Starting log output from bt-proxy.local using esphome API
INFO Successfully connected to bt-proxy.local
[02:35:40][I][app:102]: ESPHome version 2023.3.2 compiled on Apr  7 2023, 02:28:05
[02:35:40][I][app:104]: Project esphome.bluetooth-proxy version 1.0
[02:35:40][C][wifi:504]: WiFi:
[02:35:40][C][wifi:362]:   Local MAC: macaddr
[02:35:40][C][wifi:363]:   SSID: [redacted]
[02:35:40][C][wifi:364]:   IP Address: ipaddr
[02:35:40][C][wifi:366]:   BSSID: [redacted]
[02:35:40][C][wifi:367]:   Hostname: 'bt-proxy'
[02:35:40][C][wifi:369]:   Signal strength: -58 dB ▂▄▆█
[02:35:40][C][wifi:373]:   Channel: 1
[02:35:40][C][wifi:374]:   Subnet: cut
[02:35:40][C][wifi:375]:   Gateway: cut
[02:35:40][C][wifi:376]:   DNS1: cut
[02:35:40][C][wifi:377]:   DNS2: cut
[02:35:40][C][logger:293]: Logger:
[02:35:40][C][logger:294]:   Level: DEBUG
[02:35:40][C][logger:295]:   Log Baud Rate: 115200
[02:35:40][C][logger:296]:   Hardware UART: UART0
[02:35:40][C][bluetooth_proxy:065]: Bluetooth Proxy:
[02:35:40][C][bluetooth_proxy:066]:   Active: YES
[02:35:40][C][safe_mode.button:022]: Safe Mode Button 'Safe Mode Boot'
[02:35:40][C][safe_mode.button:022]:   Icon: 'mdi:restart-alert'
[02:35:40][C][esp32_ble:214]: ESP32 BLE:
[02:35:40][C][esp32_ble_tracker:591]: BLE Tracker:
[02:35:40][C][esp32_ble_tracker:592]:   Scan Duration: 300 s
[02:35:40][C][esp32_ble_tracker:593]:   Scan Interval: 1100.0 ms
[02:35:40][C][esp32_ble_tracker:594]:   Scan Window: 1100.0 ms
[02:35:40][C][esp32_ble_tracker:595]:   Scan Type: ACTIVE
[02:35:40][C][esp32_ble_tracker:596]:   Continuous Scanning: True
[02:35:41][C][mdns:108]: mDNS:
[02:35:41][C][mdns:109]:   Hostname: bt-proxy
[02:35:41][C][ota:093]: Over-The-Air Updates:
[02:35:41][C][ota:094]:   Address: bt-proxy.local:3232
[02:35:41][W][ota:103]: Last Boot was an unhandled reset, will proceed to safe mode in 7 restarts
[02:35:41][C][api:138]: API Server:
[02:35:41][C][api:139]:   Address: bt-proxy.local:6053
[02:35:41][C][api:141]:   Using noise encryption: YES
[02:35:41][C][improv_serial:032]: Improv Serial:

will check and report if this changed something or no.

bdraco commented 1 year ago

Drop the

    interval: 1100ms
    window: 1100ms

and use the defaults

Those values are for ethernet proxies and will dedicate too much time to the bluetooth radio which may make the wifi unreliable.

jpconfessor commented 1 year ago

can someone check if this was fixed in 23.4.1? there are some fixes linked to esphome

KitHubek commented 1 year ago

for me in ver 2023.4.1 still not working.

@bdraco I do config as You say, now is:

substitutions:
  name: bt-proxy-8cf3c8
  friendly_name: BT-Proxy
  board: esp32dev
packages:
  esphome.bluetooth-proxy: github://esphome/bluetooth-proxies/esp32-generic.yaml@main
esphome:
  name: ${name}
  name_add_mac_suffix: false
  friendly_name: ${friendly_name}
esp32:
  board: ${board}
  framework:
    type: esp-idf
api:
  encryption:
    key: SY49gbpHZPhbK5xm0CQjVs60cywnRDFq23x9AM0Baeo=
esp32_ble_tracker:
  scan_parameters:
    active: true
bluetooth_proxy:
  active: true
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
INFO Reading configuration /config/esphome/bt-proxy.yaml...
INFO Starting log output from bt-proxy.local using esphome API
INFO Successfully connected to bt-proxy.local
[17:48:06][I][app:102]: ESPHome version 2023.3.2 compiled on Apr  7 2023, 09:16:41
[17:48:06][I][app:104]: Project esphome.bluetooth-proxy version 1.0
[17:48:06][C][wifi:504]: WiFi:
[17:48:06][C][wifi:362]:   Local MAC: macaddr
[17:48:06][C][wifi:363]:   SSID: [redacted]
[17:48:06][C][wifi:364]:   IP Address: ipaddr
[17:48:06][C][wifi:366]:   BSSID: [redacted]
[17:48:06][C][wifi:367]:   Hostname: 'bt-proxy'
[17:48:06][C][wifi:369]:   Signal strength: -63 dB ▂▄▆█
[17:48:06][C][wifi:373]:   Channel: 11
[17:48:06][C][wifi:374]:   Subnet: cut
[17:48:06][C][wifi:375]:   Gateway: cut
[17:48:06][C][wifi:376]:   DNS1: cut
[17:48:06][C][wifi:377]:   DNS2: cut
[17:48:06][C][logger:293]: Logger:
[17:48:06][C][logger:294]:   Level: DEBUG
[17:48:06][C][logger:295]:   Log Baud Rate: 115200
[17:48:06][C][logger:296]:   Hardware UART: UART0
[17:48:06][C][bluetooth_proxy:065]: Bluetooth Proxy:
[17:48:06][C][bluetooth_proxy:066]:   Active: YES
[17:48:06][C][safe_mode.button:022]: Safe Mode Button 'Safe Mode Boot'
[17:48:06][C][safe_mode.button:022]:   Icon: 'mdi:restart-alert'
[17:48:06][C][esp32_ble:214]: ESP32 BLE:
[17:48:06][C][esp32_ble_tracker:591]: BLE Tracker:
[17:48:06][C][esp32_ble_tracker:592]:   Scan Duration: 300 s
[17:48:06][C][esp32_ble_tracker:593]:   Scan Interval: 320.0 ms
[17:48:06][C][esp32_ble_tracker:594]:   Scan Window: 30.0 ms
[17:48:06][C][esp32_ble_tracker:595]:   Scan Type: ACTIVE
[17:48:06][C][esp32_ble_tracker:596]:   Continuous Scanning: True
[17:48:06][C][mdns:108]: mDNS:
[17:48:06][C][mdns:109]:   Hostname: bt-proxy
[17:48:06][C][ota:093]: Over-The-Air Updates:
[17:48:06][C][ota:094]:   Address: bt-proxy.local:3232
[17:48:06][C][api:138]: API Server:
[17:48:06][C][api:139]:   Address: bt-proxy.local:6053
[17:48:06][C][api:141]:   Using noise encryption: YES
[17:48:06][C][improv_serial:032]: Improv Serial:

tested with thic changes from mornig till now, and, i must say, that is worse than it was before. Before changing the BT proxy configuration, the lock performed the command after a long time, about a minute, and now the lock does not execute the opening command at all. I am sending logs from today.

Logger: homeassistant.core Source: components/switchbot/lock.py:54 First occurred: 16:14:29 (1 occurrences) Last logged: 16:14:29

Error executing service: <ServiceCall lock.unlock (c:01GXE103CBG0N8BM1VS7JWWD48): entity_id=['lock.zamek']> Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 555, in bluetooth_device_connect await event.wait() File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 554, in bluetooth_device_connect async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation return await func(self, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect await self._client.bluetooth_device_connect( File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 580, in bluetooth_device_connect raise TimeoutAPIError( aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/init.py", line 344, in establish_connection await client.connect( File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 269, in connect connected = await super().connect(kwargs) File "/usr/local/lib/python3.10/site-packages/bleak/init.py", line 531, in connect return await self._backend.connect(kwargs) File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation raise asyncio.TimeoutError(str(err)) from err asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True, after 5.0s

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1838, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1857, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 216, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 798, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 977, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 838, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 106, in _async_unlock
    await entity.async_unlock(**remove_entity_service_fields(service_call))
  File "/usr/src/homeassistant/homeassistant/components/switchbot/lock.py", line 54, in async_unlock
    self._last_run_success = await self._device.unlock()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 168, in unlock
    return await self._lock_unlock(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 189, in _lock_unlock
    await self._enable_notifications()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 255, in _enable_notifications
    result = await self._send_command(COMMAND_ENABLE_NOTIFICATIONS)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 299, in _send_command
    result = await self._ensure_encryption_initialized()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 314, in _ensure_encryption_initialized
    result = await self._send_command(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 297, in _send_command
    return await super()._send_command(key[:2] + "000000" + key[2:], retry)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command
    return await self._send_command_locked(key, command)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 414, in _send_command_locked
    await self._ensure_connected()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 274, in _ensure_connected
    client: BleakClientWithServiceCache = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 361, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 310, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError:  (macaddr) - macaddr: Failed to connect: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True,  after 5.0s
Logger: switchbot.devices.device
Source: /usr/local/lib/python3.10/site-packages/switchbot/devices/device.py:182
First occurred: 16:14:29 (1 occurrences)
Last logged: 16:14:29

(macaddr): device not found, no longer in range, or poor RSSI: -69
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 555, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 554, in bluetooth_device_connect
    async with async_timeout.timeout(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/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 580, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 344, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 269, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 531, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True,  after 5.0s

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 180, in _send_command
    return await self._send_command_locked(key, command)
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 414, in _send_command_locked
    await self._ensure_connected()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 274, in _ensure_connected
    client: BleakClientWithServiceCache = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 361, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 310, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError:  (macaddr) - macaddr: Failed to connect: Timeout waiting for connect response while connecting to macaddr after 20.0s, disconnect timed out: True,  after 5.0s

and if i want operate lock via switch bot app, response is very good. less than 1 sec.

And i have more Switch bot devices, for example door open/close sensor, and i see, that this sensor report ble rssi every some seconds, not more that every 60, and lock not report this value. Lock report this value only when operating (lock/unlock). If not locking/unlocking for example 10 hours, this value not change, rssi is the same, not changing, last report when last lock/unlock.

jpconfessor commented 1 year ago

Thank you for validating this bug in 23.4.1 @KitHubek

unless a lot was changed for esphome ble proxy stuff.. the interval and window parameters should not be part of this problem, since in both, old and new versions they have the same value and the behavior is completely different. So, something else changed in HA.

I will stay in the older version for now... wife didn't aprove having to wait 30s in front of our door last night... :(

KitHubek commented 1 year ago

and now, i downgrade to 2023.2.5 HA and lock working very good. Now on:

System Information

version core-2023.2.5
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.7
os_name Linux
os_version 5.15.84-v8
arch aarch64
timezone Europe/Warsaw
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.31.0 Stage | running Available Repositories | 1248 Downloaded Repositories | 8
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
GIOŚ can_reach_server | ok -- | --
Home Assistant Supervisor host_os | Home Assistant OS 9.5 -- | -- update_channel | stable supervisor_version | supervisor-2023.04.0 agent_version | 1.4.1 docker_version | 20.10.22 disk_total | 219.4 GB disk_used | 67.1 GB healthy | true supported | true board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | Node-RED (14.1.3), Studio Code Server (5.5.6), Mosquitto broker (6.2.0), Samba share (10.0.0), Zigbee2mqtt Edge (edge), Duck DNS (1.15.0), NGINX Home Assistant SSL proxy (3.2.0), SQLite Web (3.7.1), Zigbee2MQTT (1.30.3-1), Terminal & SSH (9.6.1), ESPHome (2023.3.2)
Dashboards dashboards | 6 -- | -- resources | 4 views | 31 mode | storage
Recorder oldest_recorder_run | 5 lutego 2023 09:16 -- | -- current_recorder_run | 7 kwietnia 2023 21:49 estimated_db_size | 13232.82 MiB database_engine | sqlite database_version | 3.38.5
Spotify api_endpoint_reachable | ok -- | --
KitHubek commented 1 year ago

i think that problem can be with update pySwitchbot between HA 2023.2.5 and 2023.3.0. I made tests and all worlking fine till 2023.2.5. All later versions are problematic. And tested this with bt-proxy and without. it doesn't matter if it's bt-proxy installed and added to HA or not. Problem still exsist also without bt-proxy

and PS. Iam using BT dongle plugged into USB 2.0 port with 3m cables away from all other USB 3.0 ports, and this dongle is from https://www.home-assistant.io/integrations/bluetooth/ HIgh Performance adapters list, Cambridge Silicon Radio (CSR) Based adapters UGREEN CM109 (CSR8510A10) and all my bt devices working OK, and all SwitchBot devices working ok, problem is only with LOCK. And i have second lock, and tested it, and problem is the same, so i dont belive, that two lock that i have are broken, specially since it works fine on version 2023.2.5 and lower :/

KitHubek commented 1 year ago

someone who has this problem installed 2023.4.2 HA and can confirm, that problem gone or still exist?

scharrrfi commented 1 year ago

someone who has this problem installed 2023.4.2 HA and can confirm, that problem gone or still exist?

For me it is still there at 2023.4.4...

It seems to fix the problem temporarily when connecting my phone with the lock.

KitHubek commented 1 year ago

today i made test.

I install newest HA system on generic miniPC. Used the same bt dongle as in my production HA instance. Add only switchbot looch to it. And.. lock workin very well. And this is crazy, because i made backup my main instance, recover it on my new miniPC, updated to newest HA and.... lock not working. Downgrade solve problem.

So, this is not problem with hardware, not problem with my lock, not problem with main HA update. I think, that this is problem with some integration, wchich updated made some problem with smooth working lock. But this is only my idea

jpconfessor commented 1 year ago

Did someone test this with Home Assistant OS 10.0? There are some fixes for Bluez, so, if you are not using btproxy, this might help/or not! hehe

btw, I've just noticed this bug talks about a change in behavior going from 2023.2.x to 2023.3.6 In my case the change in behavior was between 2023.3.6 to 2023.4.x

I am currently in 2023.3.6 and the lock is very responsive (as in previous versions)

Current versions (working properly): Home Assistant 2023.3.6 Supervisor 2023.04.0 Operating System 9.5 ESPHome 2023.4.0 pySwitchbot 0.37.4


Edit:

Nevermind.. looks like OS 10.0 is even worst! https://github.com/home-assistant/core/issues/91617

KitHubek commented 1 year ago

i tested it on newset OS an HA: 10.1 and 2023.4.6 and i say:

newest HA - not working. newest OS - 10.1 - ok

If update only OS - all working ok. If update HA - fail

KitHubek commented 1 year ago

tested today on 2023.4.6 and :(

log from bt-proxy:

[20:33:52][I][bluetooth_proxy:250]: [0] [MA:C:ADDR] Connecting v3 with cache
[20:33:52][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[20:33:52][I][esp32_ble_client:064]: [0] [MA:C:ADDR] 0x01 Attempting BLE connection
[20:33:52][D][esp-idf:000]: W (15029944) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:33:52][D][esp-idf:000]: W (15030047) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:33:52][D][esp-idf:000]: W (15030154) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:33:53][D][esp-idf:000]: W (15030259) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:33:53][D][esp-idf:000]: W (15030264) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x3e

[20:33:53][D][esp-idf:000]: W (15030266) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x3e

[20:33:53][D][esp-idf:000]: W (15030267) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x3e

[20:33:53][W][esp32_ble_client:134]: [0] [] Connection failed, status=133
[20:33:53][D][esp32_ble_tracker:246]: Starting scan...
[20:34:17][I][bluetooth_proxy:250]: [0] [MA:C:ADDR] Connecting v3 with cache
[20:34:17][D][esp32_ble_tracker:214]: Pausing scan to make connection...
[20:34:17][I][esp32_ble_client:064]: [0] [MA:C:ADDR] 0x01 Attempting BLE connection
[20:34:17][D][esp-idf:000]: W (15055145) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:34:18][D][esp-idf:000]: W (15055250) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e

[20:34:18][I][esp32_ble_client:144]: [0] [MA:C:ADDR] Connected
[20:34:18][D][esp32_ble_tracker:246]: Starting scan...
[20:34:34][I][esp32_ble_client:081]: [0] [MA:C:ADDR] Disconnecting.
[20:34:34][D][esp-idf:000]: W (15072182) BT_HCI: hci cmd send: disconnect: hdl 0x0, rsn:0x13

[20:34:34][D][esp-idf:000]: W (15072189) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x16

[20:34:34][D][esp-idf:000]: W (15072191) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x16

[20:34:34][D][esp-idf:000]: W (15072192) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x16

[20:34:35][D][esp-idf:000]: W (15072235) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x16

[20:39:18][D][esp32_ble_tracker:246]: Starting scan...

and command unlock finally ok, but delay is as we can see about 25 sec.
BT-proxy is still online for sure i pinged it every sec when do this test, saw logs from AP, bt-proxy not disconnected. Downgrade to HA 2023,2,5 and all working ok.

i dont jnow wht to do with this issue, no idea

KitHubek commented 1 year ago

today i set up Wireless Tag WT32-ETH01 as a bt-proxy and the same problem on nevest HA as with WiFi connected ESP32

update. I see, that after some time, lock last action, when i call service lock.unlock it takes every time about 26-30sec aftre device unlock door. I test now on version 2023.3.6 and unfortunately behavior is the same. I will test all lover HA version till 2023.2.5. and this is cray, because after i call service i see that entity lock rssi changing, so lock isnt offline. I tested it with two bt-proxy and the same problem. And finally testes without bt-proxy. And problem is the same. So, this isnt problem with bt-proxy iam sure 100%

Crazy is, if i manually open lock - status update immediately

tested versions:

2023.4.6 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.5 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.4 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.3 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.2 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.1 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.6 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.5 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.4 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.3 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.2 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.1 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.2.5 - working OK, lock/unlock immediately with bt proxy and without bt proxy

jpconfessor commented 1 year ago

@KitHubek have you tried to update to the latest version and downgrade just pySwitchbot (using pip from inside the home assistant container) matching the same version you have in 2023.2.5? Then, next step will be upgrading to the most recent version available PySwitchbot==0.37.6. I am not sure which version of this library HA has in 2023.4.6, but if they aren't using 0.37.6, I think we should test! At the end of the day, it will help developers to narrow down this issue and get it fixed as soon as possible.

Just for comparison, in 2023.3.6 I have pySwitchbot 0.37.4, and lock/unlock works just fine (less than 5s delay for the first time - which requires the connection setup) via bt-proxy m5-atom at 1m (3ft) away from it.

KitHubek commented 1 year ago

@jpconfessor i not downgrade pyswitchbot, byt can do this, but i dont know how to do this. I have installed ssh addon, but if i want run command: pip, pip3 - i see: command not found. My instalation is Home Assistant OS

KitHubek commented 1 year ago

@jpconfessor @bdraco I tested all HA versions 2023.2.5 - 2023.4.6

2023.4.6 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.5 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.4 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.3 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.2 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.4.1 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.6 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.5 - fail, problem is, device finally open door after about 26-30sec with bt proxy and without bt proxy 2023.3.4 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.3 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.2 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.3.1 - fail, error: ERROR - bytearray index out of range or lock not responding, cant lock and or unlock 2023.2.5 - working OK, lock/unlock immediately with bt proxy and without bt proxy

Iam using generic miniPC, Intel Core i5-6500T and 16GB RAM, nvme ssd so i think that thos is overkill, but i want be sure, that problem isnt with hardware. Iam using two bt-proxy, connected wifi ESP32 and connected via LAN WT32-ETH0, my bt dongle is from here https://www.home-assistant.io/integrations/bluetooth/ list KNOWN WORKING HIGH-PERFORMANCE ADAPTERS CSR chip UGREEN CM109 (CSR8510A10) using extended 3m cable away from another devices and USB 3.0 ports. USB adapter is about 3 meters from bt-proxy and lock is about 3 meters from bt-proxy and max 6 meters from bt-dongle. No walls. Lock batterry 98%. CPU load last 48h - 10-25%, RAM 1,4-2,1 GB (have 16GB).

My config:

System Information

version core-2023.3.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.10
os_name Linux
os_version 6.1.25
arch x86_64
timezone Europe/Warsaw
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.32.1 Stage | running Available Repositories | 1274 Downloaded Repositories | 8
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
GIOŚ can_reach_server | ok -- | --
Home Assistant Supervisor host_os | Home Assistant OS 10.1 -- | -- update_channel | stable supervisor_version | supervisor-2023.04.1 agent_version | 1.5.1 docker_version | 23.0.3 disk_total | 234.0 GB disk_used | 18.7 GB healthy | true supported | true board | generic-x86-64 supervisor_api | ok version_api | ok installed_addons | Studio Code Server (5.5.7), Mosquitto broker (6.2.1), Samba share (10.0.1), Zigbee2mqtt Edge (edge), Duck DNS (1.15.0), NGINX Home Assistant SSL proxy (3.4.0), Zigbee2MQTT (1.30.3-1), Terminal & SSH (9.7.0), ESPHome (2023.4.2), MariaDB (2.5.2)
Dashboards dashboards | 6 -- | -- resources | 4 views | 25 mode | storage
Recorder oldest_recorder_run | 30 kwietnia 2023 18:53 -- | -- current_recorder_run | 30 kwietnia 2023 20:53 estimated_db_size | 179.33 MiB database_engine | mysql database_version | 10.6.10
Spotify api_endpoint_reachable | ok -- | --

For now i tested everything what i can and what i know. I tested second lock too. For now only working solution is downgrade to HA 2023.2.5. But i want using nevest HA version :/ Please help, thanks

bdraco commented 1 year ago

There are a large number of changes to the Bluetooth stack, esphome, SwitchBot , and the library, between 2023.2.5 and 2023.3.x which makes it nearly impossible to know where the problem was introduced (especially since I can’t reproduce it)

I would try installing the 2023.2.5 version as a custom component on 2023.4.x and seeing if it works for you. That would narrow it down if it’s a problem with the integration or outside of the integration

KitHubek commented 1 year ago

ok @bdraco i can do this. Can You tell me how to do it? How to install HA as a custom component? I dont know how to do it

bdraco commented 1 year ago
git clone https://github.com/home-assistant/core
cd core
git checkout 2023.2.5
KitHubek commented 1 year ago

ok i will do this today. I have one more question tp You @bdraco @jpconfessor wrote to downgrade only pyswitchbot to lower version which was at HA 2023.2.5 what do You think about this? And how to do it if this is good idea

bdraco commented 1 year ago

The above will downgrade the switchbot integration and pyswitchbot library. I'd try that first

KitHubek commented 1 year ago

ok, so i do as You wrote here https://github.com/home-assistant/core/issues/90265#issuecomment-1529718239

and last Q after that, i have to disable oficial switchbot integration and add lock to this custom component? Am i right?

bdraco commented 1 year ago

ok, so i do as You wrote here #90265 (comment)

and last Q after that, i have to disable oficial switchbot integration and add lock to this custom component? Am i right?

You should just need to restart. If you got it installed as a custom component it will replace the core integration and you'll see a little icon Screenshot 2023-05-01 at 10 17 36 AM in the upper right hand corner of the card on the integrations page indicating you are running a custom version

KitHubek commented 1 year ago

ok, thanks for this help. I done this, and now switchbot is as a custom component

Adnotacja 2023-05-01 172837

So now i have to test if lock response immediately or not? Am i right?

bdraco commented 1 year ago

Yes

KitHubek commented 1 year ago

so, gone over 1 hour and just test now, and unlock after about 1 sec, lock under 1 second. So, for now seems to working ok with this older Switchbot integration. Will test later, but maby problem is with newest switchbot integration, no with other integrations or HA version

bdraco commented 1 year ago

There aren't any interesting changes in the integration between version 2023.2.5 and 2023.3.0

The only thing that changed of significance is the pySwitchbot library between those versions

bdraco commented 1 year ago

You could try running the current version with the old version of the pySwitchbot library

git clone https://github.com/home-assistant/core
cd core
git checkout dev
KitHubek commented 1 year ago

so what do You think? what now? Maby You remember, that when version 2023.3 cames was error: bytearray index out of range and from this version started problems. Firtst lock no working because this error, next versions lock not responding at all.

UPDATE: now tested again, and unfortunately lock still has long response, about 27sec.

ok @bdraco will do it now

KitHubek commented 1 year ago

ok, done. after checkout command i see:

Already on 'dev' Your branch is up to date with 'origin/dev'.

but maby its ok. Restarted HA, will test now