lkempf/casambi-bt-hass

Unexpected error creating network

Closed this issue · 10 comments

Using a bt proxy I get the following error on HA restart. Reloading the integration afterwards fixes it.

Logs:

This error originated from a custom integration.

Logger: custom_components.casambi_bt
Source: custom_components/casambi_bt/__init__.py:79
Integration: Casambi Bluetooth (documentation)
First occurred: 9:19:04 AM (1 occurrences)
Last logged: 9:19:04 AM

Unexpected error creating network 6D:2A:B2:63:D8:B0
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 130, in _call_sslobject_method
    result = func(*args)
  File "/usr/local/lib/python3.10/ssl.py", line 917, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2548)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 34, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 195, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 137, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
    await self._protocol.read_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/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 32, in read
    with anyio.fail_after(timeout):
  File "/usr/local/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 191, in _receive_event
    data = await self._network_stream.read(
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 31, in read
    with map_exceptions(exc_map):
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout

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

Traceback (most recent call last):
  File "/config/custom_components/casambi_bt/__init__.py", line 79, in async_casmbi_api_setup
    await casa.connect(device, password)
  File "/usr/local/lib/python3.10/site-packages/CasambiBt/_casambi.py", line 124, in connect
    await self._casaNetwork.update()
  File "/usr/local/lib/python3.10/site-packages/CasambiBt/_network.py", line 129, in update
    res = await self._httpClient.put(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1885, in put
    return await self.request(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

I sometimes also notice the controls don't work after a while despite being connected and the device available. I'll enable the debugs and try to reproduce.

Slightly different trace this time:

This error originated from a custom integration.

Logger: custom_components.casambi_bt
Source: custom_components/casambi_bt/__init__.py:79
Integration: Casambi Bluetooth (documentation)
First occurred: 6:48:16 PM (1 occurrences)
Last logged: 6:48:16 PM

Unexpected error creating network 6D:2A:B2:63:D8:B0
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 69, in start_tls
    ssl_stream = await anyio.streams.tls.TLSStream.wrap(
  File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 122, in wrap
    await wrapper._call_sslobject_method(ssl_object.do_handshake)
  File "/usr/local/lib/python3.10/site-packages/anyio/streams/tls.py", line 168, in _call_sslobject_method
    await self.transport_stream.send(self._write_bio.read())
  File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1292, in send
    await checkpoint()
  File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 515, in checkpoint
    await sleep(0)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 596, in sleep
    await __sleep0()
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 590, in __sleep0
    yield
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/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 78, in start_tls
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 68, in start_tls
    with anyio.fail_after(timeout):
  File "/usr/local/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 150, in _connect
    stream = await stream.start_tls(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 66, in start_tls
    with map_exceptions(exc_map):
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectTimeout

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

Traceback (most recent call last):
  File "/config/custom_components/casambi_bt/__init__.py", line 79, in async_casmbi_api_setup
    await casa.connect(device, password)
  File "/usr/local/lib/python3.10/site-packages/CasambiBt/_casambi.py", line 118, in connect
    networkId = await getNetworkIdFromUuid(addr, self._httpClient)
  File "/usr/local/lib/python3.10/site-packages/CasambiBt/_network.py", line 274, in getNetworkIdFromUuid
    res = await httpClient.get(getNetworkIdUrl)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1757, in get
    return await self.request(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectTimeout

I don't really know what to make of this error. It might just be a networking issue on your side. Are there any other integrations that have issues accessing the internet when HA is starting? Otherwise it might be that the http client I get from HA isn't ready yet but I don't know how to check for that. I might look into this when I'm less busy.

Nope, all other integrations seem to behave fine.

I still don't know what's causing this but this should be mitigated somewhat since the integration will now fall back to the cached network info if the connection to the api fails. Please reopen if this is still an issue with 0.0.6.

And while thinking about it just now I spotted a case in which my fix won't work. Leaving this open until this case is also fixed.

I do experience the same issue. Is there anything how can I help to get it solved?

@lkempf Sorry for bothering you. It would be awesome to get this solved. Is there anything I can do to help?

I see 3 cases for what the issue is for you:

  1. Cached network information is used but there is still an error message in the log on startup. I'd consider this won't fix currently since it would be easy work around. This is as far as I know the problem tjorim is having with the newest version.
  2. The fallback to the cached information doesn't work. In this case the fix would be doable and I would need the debug log.
  3. The connection for you never succeedes (even not when reloading the integration some time after HA was started) and so no cached information is available. This would be the worst case. The only solution I can think of involves you setting up a remote debugging setup and checking what is actually happening. I could give you some pointers and ideas where the problem could be but you would need to be somewhat familiar with Python and probably also asyncio for this.

Can you tell me which description fits your issue best?

Thanks @lkempf for the reply and sorry for the delay.

Option 3 is out because I can use the lights initially and also if I reload the integration.

I also think it is not option 1, as it loads successfully at the beginning.

2023-06-09 09:31:36.605 INFO (MainThread) [CasambiBt._casambi] Trying to connect to casambi network xx:xx:xx:xx:xx:xx...
2023-06-09 09:31:36.607 INFO (MainThread) [CasambiBt._keystore] Loading keys...
2023-06-09 09:31:36.608 INFO (MainThread) [CasambiBt._keystore] Loaded 5 keys.
2023-06-09 09:31:36.610 INFO (MainThread) [CasambiBt._network] Loading session...
2023-06-09 09:31:36.611 INFO (MainThread) [CasambiBt._network] Loading unit type cache...
2023-06-09 09:31:36.613 INFO (MainThread) [CasambiBt._network] Getting network id...
2023-06-09 09:31:37.312 INFO (MainThread) [httpx] HTTP Request: GET https://api.casambi.com/network/uuid/xxxxxxxxxx "HTTP/1.1 200 OK"
2023-06-09 09:31:37.330 INFO (MainThread) [CasambiBt._network] Got network id xxxxxxxxxxxxxxxx
2023-06-09 09:31:37.331 INFO (MainThread) [CasambiBt._network] Updating network...
2023-06-09 09:31:37.333 INFO (MainThread) [CasambiBt._network] Loaded cached network. Revision: 98
2023-06-09 09:31:37.524 INFO (MainThread) [httpx] HTTP Request: PUT https://api.casambi.com/network/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/ "HTTP/1.1 200 OK"
2023-06-09 09:31:37.532 DEBUG (MainThread) [CasambiBt._network] Network: {"status":"UPTODATE","revision":98.0,"role":3}
2023-06-09 09:31:37.534 INFO (MainThread) [CasambiBt._keystore] Key with id 6 already exists. Skipping...
2023-06-09 09:31:37.534 INFO (MainThread) [CasambiBt._keystore] Key with id 3 already exists. Skipping...
2023-06-09 09:31:37.535 INFO (MainThread) [CasambiBt._keystore] Key with id 4 already exists. Skipping...
2023-06-09 09:31:37.536 INFO (MainThread) [CasambiBt._keystore] Key with id 5 already exists. Skipping...
2023-06-09 09:31:37.537 INFO (MainThread) [CasambiBt._keystore] Key with id 9 already exists. Skipping...
2023-06-09 09:31:37.537 INFO (MainThread) [CasambiBt._network] Fetching unit type for id 22602...
2023-06-09 09:31:37.538 INFO (MainThread) [CasambiBt._network] Using cached type.
2023-06-09 09:31:37.538 INFO (MainThread) [CasambiBt._network] Fetching unit type for id 22602...
2023-06-09 09:31:37.539 INFO (MainThread) [CasambiBt._network] Using cached type.
2023-06-09 09:31:37.539 INFO (MainThread) [CasambiBt._network] Fetching unit type for id 22602...
2023-06-09 09:31:37.540 INFO (MainThread) [CasambiBt._network] Using cached type.
2023-06-09 09:31:37.540 INFO (MainThread) [CasambiBt._network] Saving type cache...
2023-06-09 09:31:37.544 INFO (MainThread) [CasambiBt._network] Network updated.
2023-06-09 09:31:37.545 INFO (MainThread) [CasambiBt._client] Connection to xx:xx:xx:xx:xx:xx
2023-06-09 09:31:47.042 INFO (MainThread) [CasambiBt._client] Connected to xx:xx:xx:xx:xx:xx
2023-06-09 09:31:47.044 INFO (MainThread) [CasambiBt._client] Starting key exchange...
2023-06-09 09:31:47.615 DEBUG (MainThread) [CasambiBt._client] Got b'xxxxxxxxxxxxxx'
2023-06-09 09:31:47.617 DEBUG (MainThread) [CasambiBt._client] Parsed mtu 158, unit 1, flags 242, nonce b'xxxxxxxxxxxxxx'
2023-06-09 09:31:47.619 DEBUG (MainThread) [CasambiBt._client] Starting notify
2023-06-09 09:31:47.692 DEBUG (MainThread) [CasambiBt._client] Callback on handle c9ffde48-ca5a-0001-ab83-8f519b482f77 (Handle: 8): Unknown: b'02c4c57281527c54578a7aa2cc75425d69677461fe634c9c84e52a5a10c011b3fef4fc68c139cf32d1180ce7b4fd4b8216e4fd7eb0947c7db7101849f69832a706'
2023-06-09 09:31:47.693 DEBUG (MainThread) [CasambiBt._client] Got public key xxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxx
2023-06-09 09:31:47.990 DEBUG (MainThread) [CasambiBt._client] Callback on handle c9ffde48-ca5a-0001-ab83-8f519b482f77 (Handle: 8): Unknown: b'03'
2023-06-09 09:31:47.992 INFO (MainThread) [CasambiBt._client] Key exchange sucessful
2023-06-09 09:31:47.995 INFO (MainThread) [CasambiBt._client] Authenicating channel...
2023-06-09 09:31:47.997 DEBUG (MainThread) [CasambiBt._client] Auth digest: b'xxxxxxxxxxxxxxxxx'
2023-06-09 09:31:47.999 INFO (MainThread) [CasambiBt._encryption] Encrypting packet: b'xxxxxxxxxxxxxxx' of len 38 with nonce b'xxxxxxxxxxxxx'
2023-06-09 09:31:48.002 DEBUG (MainThread) [CasambiBt._encryption] Encrypted packet: b'xxxxxxxxxxxx'
2023-06-09 09:31:48.004 DEBUG (MainThread) [CasambiBt._encryption] Authenticated packet: b'xxxxxxxxxxxxxxxxxxx'
2023-06-09 09:31:48.290 DEBUG (MainThread) [CasambiBt._client] Callback on handle c9ffde48-ca5a-0001-ab83-8f519b482f77 (Handle: 8): Unknown: b'01000080ea32dc7e32707ac2dcdf56704c82c3713c10db1ef3983bbecc3921343d120afaced538323bd3007098835f77a5b40b73fa6b'
2023-06-09 09:31:48.293 INFO (MainThread) [CasambiBt._client] Processing authentication response...
2023-06-09 09:31:48.295 INFO (MainThread) [CasambiBt._encryption] Decrypting packet: b'xxxxxxxxxxxxxx' of len 54 with nonce b'xxxxxxxx'
2023-06-09 09:31:48.300 DEBUG (MainThread) [CasambiBt._encryption] Decrypted package: b'xxxxxxxxxx'
2023-06-09 09:31:48.303 INFO (MainThread) [CasambiBt._client] Authentication successful
2023-06-09 09:31:48.305 INFO (MainThread) [CasambiBt._casambi] Registerd unit changed handler <bound method CasambiApi._unit_changed_handler of <custom_components.casambi_bt.CasambiApi object at 0x7f6fb21790>>
2023-06-09 09:31:48.309 INFO (MainThread) [homeassistant.components.light] Setting up light.casambi_bt
2023-06-09 09:31:48.312 INFO (MainThread) [homeassistant.components.scene] Setting up scene.casambi_bt
2023-06-09 09:31:49.077 DEBUG (MainThread) [CasambiBt._client] Callback on handle c9ffde48-ca5a-0001-ab83-8f519b482f77 (Handle: 8): Unknown: b'02000080d55515deb2af18cd044a23daff126d999121d8862882a5050f284747480508a31634599deb18b749ab'
2023-06-09 09:31:49.081 INFO (MainThread) [CasambiBt._encryption] Decrypting packet: b'xxxxxxxxxxxx' of len 45 with nonce b'xxxxxxxx'
2023-06-09 09:31:49.083 DEBUG (MainThread) [CasambiBt._encryption] Decrypted package: b'xxxxxxxxxxxx'
2023-06-09 09:31:49.084 DEBUG (MainThread) [CasambiBt._client] Incoming data of type 6: b'xxxxxxxxxx'
2023-06-09 09:31:49.085 INFO (MainThread) [CasambiBt._client] Parsing incoming unit states...
2023-06-09 09:31:49.085 DEBUG (MainThread) [CasambiBt._client] Incoming unit state: b'xxxxxxxxxxxxxxxxxxxx'
2023-06-09 09:31:49.086 DEBUG (MainThread) [CasambiBt._client] Parsed state: Id 1, prio 3, online True, on True, state b'000041'1
2023-06-09 09:31:49.086 INFO (MainThread) [CasambiBt._casambi] Incomming data callback of type 6
2023-06-09 09:31:49.087 DEBUG (MainThread) [CasambiBt._casambi] Handling changed state b'000041' for unit 1
2023-06-09 09:31:49.087 DEBUG (MainThread) [CasambiBt._unit] Parsed b'000041' to UnitState(dimmer=0, vertical=None, rgb=None, white=None, temperature=2913)
2023-06-09 09:31:49.088 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1
2023-06-09 09:31:49.089 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1 in group 1
2023-06-09 09:31:49.090 DEBUG (MainThread) [CasambiBt._client] Parsed state: Id 2, prio 3, online True, on True, state b'000041'1
2023-06-09 09:31:49.091 INFO (MainThread) [CasambiBt._casambi] Incomming data callback of type 6
2023-06-09 09:31:49.091 DEBUG (MainThread) [CasambiBt._casambi] Handling changed state b'000041' for unit 2
2023-06-09 09:31:49.091 DEBUG (MainThread) [CasambiBt._unit] Parsed b'000041' to UnitState(dimmer=0, vertical=None, rgb=None, white=None, temperature=2913)
2023-06-09 09:31:49.092 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 2
2023-06-09 09:31:49.093 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 2 in group 1
2023-06-09 09:31:49.094 DEBUG (MainThread) [CasambiBt._client] Parsed state: Id 3, prio 3, online True, on True, state b'000041'1
2023-06-09 09:31:49.095 INFO (MainThread) [CasambiBt._casambi] Incomming data callback of type 6
2023-06-09 09:31:49.095 DEBUG (MainThread) [CasambiBt._casambi] Handling changed state b'000041' for unit 3
2023-06-09 09:31:49.096 DEBUG (MainThread) [CasambiBt._unit] Parsed b'000041' to UnitState(dimmer=0, vertical=None, rgb=None, white=None, temperature=2913)
2023-06-09 09:31:49.096 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 3
2023-06-09 09:31:49.097 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 3 in group 1
2023-06-09 09:31:49.103 DEBUG (MainThread) [CasambiBt._client] Callback on handle c9ffde48-ca5a-0001-ab83-8f519b482f77 (Handle: 8): Unknown: b'03000080f19943fab8edaa22498f6b5acc0aa440f71ade26df1dc60bd277a18eaaea32ef8f69096ec9986b0af57477a7c47279cec3'
2023-06-09 09:31:49.103 INFO (MainThread) [CasambiBt._encryption] Decrypting packet: b'xxxxxxxxxxxxxxxxxxx' of len 53 with nonce b'xxxxxxxxxx'
2023-06-09 09:31:49.107 DEBUG (MainThread) [CasambiBt._encryption] Decrypted package: b'xxxxxxxxxxxxxxx'
2023-06-09 09:31:49.109 DEBUG (MainThread) [CasambiBt._client] Incoming data of type 9: b'09040302830a080202880202820a0201028e02048a020481020387020c840a1000'

Around 10 minutes later it became unavailable.

2023-06-09 09:42:16.274 INFO (MainThread) [CasambiBt._client] Received disconnect callback from xx:xx:xx:xx:xx:xx
2023-06-09 09:42:16.275 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1
2023-06-09 09:42:16.282 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1 in group 1
2023-06-09 09:42:16.282 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 2
2023-06-09 09:42:16.284 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 2 in group 1
2023-06-09 09:42:16.285 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 3
2023-06-09 09:42:16.286 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 3 in group 1

If I use a scene at this point it takes a while but works. If I use the light switches it does not work anymore.

2023-06-09 10:35:40.550 INFO (MainThread) [custom_components.casambi_bt.scene] Switching to scene Ambiente 
2023-06-09 10:35:40.551 DEBUG (MainThread) [CasambiBt._casambi] Sending operation SetLevel with payload b'ff' for 704
2023-06-09 10:35:40.551 INFO (MainThread) [CasambiBt._casambi] Trying to reconnect broken connection once.
2023-06-09 10:35:40.552 INFO (MainThread) [CasambiBt._client] Connection to xx:xx:xx:xx:xx:xx
2023-06-09 10:35:42.063 INFO (MainThread) [CasambiBt._client] Connected to xx:xx:xx:xx:xx:xx
2023-06-09 10:35:42.066 INFO (MainThread) [CasambiBt._client] Starting key exchange...

I created a new issue for this because I don't think it is the same problem as discussed here. Closing this issue since I consider this fixed for now.