core: Esphome api: asyncio.exceptions.InvalidStateError: invalid state

The problem

If the esp32 module crashes (bluetooth proxy) HA will enter in a restart connection loop with the esp module.

What version of Home Assistant Core has the issue?

2022.10.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

esphome

Link to integration documentation on our website

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

Diagnostics information

config_entry-esphome-9020b7d5958c8596923f5560d8f529c8.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

From Esp32:

[14:00:10][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:00:10][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:00:10][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:00:10][D][time:042]: Synchronized time: 2022-10-10 14:00:10
[14:00:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5190.10791 s with 0 decimals of accuracy
[14:00:35][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:00:35][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:00:35][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:00:35][D][time:042]: Synchronized time: 2022-10-10 14:00:35
[14:00:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -49.00000 dBm with 0 decimals of accuracy
[14:01:00][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:01:00][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:01:00][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:01:00][D][time:042]: Synchronized time: 2022-10-10 14:01:00
[14:01:25][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:01:25][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:01:25][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:01:25][D][time:042]: Synchronized time: 2022-10-10 14:01:25
[14:01:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5250.10693 s with 0 decimals of accuracy
[14:01:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[14:01:50][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:01:50][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:01:50][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:01:50][D][time:042]: Synchronized time: 2022-10-10 14:01:50
[14:02:15][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:02:16][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:02:16][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:02:16][D][time:042]: Synchronized time: 2022-10-10 14:02:16
[14:02:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5310.10693 s with 0 decimals of accuracy
[14:02:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[14:02:41][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:02:41][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:02:41][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:02:41][D][time:042]: Synchronized time: 2022-10-10 14:02:41
[14:03:06][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:03:06][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:03:06][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:03:06][D][time:042]: Synchronized time: 2022-10-10 14:03:06
[14:03:31][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:03:31][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:03:31][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:03:31][D][time:042]: Synchronized time: 2022-10-10 14:03:31
[14:03:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5370.10693 s with 0 decimals of accuracy
[14:03:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[14:03:56][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:03:56][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:03:56][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:03:56][D][time:042]: Synchronized time: 2022-10-10 14:03:56
[14:04:21][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:04:21][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:04:21][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:04:22][D][time:042]: Synchronized time: 2022-10-10 14:04:21
[14:04:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5430.10986 s with 0 decimals of accuracy
[14:04:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -49.00000 dBm with 0 decimals of accuracy
[14:04:47][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:04:47][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:04:47][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:04:47][D][time:042]: Synchronized time: 2022-10-10 14:04:47
[14:05:12][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:05:12][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:05:12][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:05:12][D][time:042]: Synchronized time: 2022-10-10 14:05:12
[14:05:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5490.10693 s with 0 decimals of accuracy
[14:05:37][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:05:37][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:05:37][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:05:37][D][time:042]: Synchronized time: 2022-10-10 14:05:37
[14:05:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -49.00000 dBm with 0 decimals of accuracy
[14:06:02][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:06:02][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:06:02][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:06:02][D][time:042]: Synchronized time: 2022-10-10 14:06:02
[14:06:27][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:06:27][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:06:27][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:06:27][D][time:042]: Synchronized time: 2022-10-10 14:06:27
[14:06:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5550.10889 s with 0 decimals of accuracy
[14:06:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[14:06:52][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:06:52][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:06:53][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:06:53][D][time:042]: Synchronized time: 2022-10-10 14:06:53
[14:07:18][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:07:18][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:07:18][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:07:18][D][time:042]: Synchronized time: 2022-10-10 14:07:18
[14:07:31][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 5610.10693 s with 0 decimals of accuracy
[14:07:41][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[14:07:43][W][api.connection:083]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection closed
[14:07:43][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:07:43][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:07:43][D][time:042]: Synchronized time: 2022-10-10 14:07:43
[14:08:08][W][esp32_ble_tracker:281]: ESP-IDF BLE scan never terminated, rebooting to restore BLE stack...
[14:08:08][I][app:127]: Forcing a reboot...
INFO Disconnected from ESPHome API for 10.0.51.143
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for 10.0.51.143: Error while reading data: [Errno 104] Connection reset by peer
INFO Trying to reconnect to 10.0.51.143 in the background
INFO Successfully connected to 10.0.51.143
[14:08:49][W][api.connection:999]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection reset
[14:08:49][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:08:49][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:08:49][D][time:042]: Synchronized time: 2022-10-10 14:08:49
[14:09:10][D][sensor:127]: 'BT Office Proxy Uptime': Sending state 56.51100 s with 0 decimals of accuracy
[14:09:14][D][sensor:127]: 'BT Office Proxy WiFi Signal': Sending state -48.00000 dBm with 0 decimals of accuracy
[14:09:14][W][api.connection:081]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection reset
[14:09:14][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:09:14][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:09:14][D][time:042]: Synchronized time: 2022-10-10 14:09:14
[14:09:39][D][api:102]: Accepted ::FFFF:10.0.50.13
[14:09:39][W][api.connection:081]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connection reset
[14:09:39][D][api.connection:917]: Home Assistant 2022.10.2 (::FFFF:10.0.50.13): Connected successfully
[14:09:39][D][time:042]: Synchronized time: 2022-10-10 14:09:39

From HA:

2022-10-10 15:00:35.896 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:01:00.986 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:01:23.527 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection] [140256232126688] Disconnected: Did not receive auth message within 10 seconds
2022-10-10 15:01:26.180 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:01:29.339 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.346 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.347 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.350 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.354 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.356 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.357 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.362 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.363 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.364 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.366 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.366 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.367 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.369 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.370 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.374 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:29.374 ERROR (Thread-3 (_thread_main)) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-10-10 15:01:38.318 WARNING (MainThread) [aiohomekit.controller.ble.pairing] Eve Degree 3F87 [CE:1B:74:44:94:89] (id=3C:BE:A3:72:4B:1A): Failed to fetch disconnected events: Multiple Services with this UUID, refer to your desired service by the `handle` attribute instead.; rssi=-76
2022-10-10 15:01:51.168 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:02:16.343 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:02:41.455 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:03:06.832 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:03:19.541 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection] [140256570529328] Disconnected: Did not receive auth message within 10 seconds
2022-10-10 15:03:31.961 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:03:57.173 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:04:22.255 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:04:47.352 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:05:12.699 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:05:15.870 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection] [140256301947232] Disconnected: Did not receive auth message within 10 seconds
2022-10-10 15:05:37.829 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:06:02.988 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:06:28.197 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:06:53.282 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:07:11.995 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection] [140256253660848] Disconnected: Did not receive auth message within 10 seconds
2022-10-10 15:07:18.387 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:07:43.749 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:08:24.277 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:08:49.571 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:09:10.882 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection] [140256407827696] Disconnected: Did not receive auth message within 10 seconds
2022-10-10 15:09:14.749 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:09:39.913 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state
2022-10-10 15:10:05.076 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 505, in _process_loop
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 437, in on_msg
    on_bluetooth_connections_free_update(resp.free, resp.limit)
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 105, in async_update_ble_connection_limits
    fut.set_result(free)
asyncio.exceptions.InvalidStateError: invalid state

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Fixed for me with Home Assistant 2022.12.0.dev20221102 and esphome Allow multiple bluetooth proxy connections #3971, actually some versions back but this is what I run at the moment and it works great.

Thanks for confirming. I did a whole lot of chaos testing and random unplugging with all the esphome PRs for 2022.11.x that should have made this much better for the disconnects and unexpected resets.

Fixed for me with Home Assistant 2022.12.0.dev20221102 and esphome Allow multiple bluetooth proxy connections #3971, actually some versions back but this is what I run at the moment and it works great.