lkempf / casambi-bt-hass

32 stars 12 forks source link

Connection Issues #37

Open CFenner opened 1 year ago

CFenner commented 1 year ago

Describe the bug

Regularly my BT adapter changes into debug logging (by itself?) and the casambi integration is losing its connection leading to my shelly wall switch not being able to control my lights and sometime the lights turn on in the middle of the night.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Bildschirmfoto 2023-09-22 um 09 13 08

Versions

Logs

Error setting up entry for casambi_bt
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/casambi_bt/__init__.py", line 31, in async_setup_entry
    casa_api = await async_casmbi_api_setup(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/casambi_bt/__init__.py", line 83, in async_casmbi_api_setup
    await casa.connect(device, password)
  File "/usr/local/lib/python3.11/site-packages/CasambiBt/_casambi.py", line 139, in connect
    await self._connectClient()
  File "/usr/local/lib/python3.11/site-packages/CasambiBt/_casambi.py", line 146, in _connectClient
    await self._casaClient.exchangeKey(self._casaNetwork.getKeyStore())  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/CasambiBt/_client.py", line 168, in exchangeKey
    await self._gattClient.start_notify(
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 834, in start_notify
    await self._backend.start_notify(characteristic, wrapped_callback, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 950, in start_notify
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dbus_fast/aio/message_bus.py", line 390, in call
    await future
asyncio.exceptions.CancelledError: aiohttp connection lost

See https://github.com/lkempf/casambi-bt-hass#reporting-issues on how to enable logs. Please make sure to at least include the log of the first connection with the network (be restarting HA or reloading the integration) and the log at the time an error happens (if applicable).

lkempf commented 1 year ago

This stack trace is incredibly weird so not sure if I will be able to help. I've added some additional error handling to casambi-bt and plan to test the changes sometimes this month. There's a slight possibility that these might help. I'll notify you when a new release with them is ready.

I'll also try to reproduce the error by switching the bluetooth adapter into debug but this will have to wait until I have enough time at my parents house.

CFenner commented 1 year ago

Anything I can do by now?

lkempf commented 12 months ago

Sorry I haven't had the time to look into this properly yet.

lkempf commented 10 months ago

Ok I at least can't reproduce this by manually turning on debug logging. Can you report back if this is still happening with v0.1.0?

lkempf commented 8 months ago

Is this still happening or can I close it?

schoenis commented 8 months ago

I am regulary having a similar connectivity issue.

@logger:%20CasambiBt._client%0ASource%3A%20/usr/local/lib/python3.12/site-packages/CasambiBt/_client.py:124%0AFirst%20occurred:%2006:34:13%20(254%20occurrences)%0ALast%20logged:%2018:31:19%0A%0AFailed%20to%20find%20client.%0ATraceback%20(most%20recent%20call%20last):%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py%22,%20line%20209,%20in%20connect%0A%20%20%20%20reply%20=%20await%20self._bus.call(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/dbus_fast/aio/message_bus.py%22,%20line%20384,%20in%20call%0A%20%20%20%20await%20future%0Aasyncio.exceptions.CancelledError%0A%0AThe%20above%20exception%20was%20the%20direct%20cause%20of%20the%20following%20exception:%0A%0ATraceback%20(most%20recent%20call%20last):%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak_retry_connector/init.py%22,%20line%20363,%20in%20establish_connection%0A%20%20%20%20await%20client.connect(%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/habluetooth/wrappers.py%22,%20line%20300,%20in%20connect%0A%20%20%20%20connected%20=%20await%20super().connect(kwargs)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak/init.py%22,%20line%20605,%20in%20connect%0A%20%20%20%20return%20await%20self._backend.connect(kwargs)%0A%20%20%20%20%20%20%20%20%20%20%20%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py%22,%20line%20146,%20in%20connect%0A%20%20%20%20async%20with%20async_timeout(timeout):%0A%20%20File%20%22/usr/local/lib/python3.12/asyncio/timeouts.py%22,%20line%20115,%20in%20aexit%0A%20%20%20%20raise%20TimeoutError%20from%20exc_val%0ATimeoutError%0A%0AThe%20above%20exception%20was%20the%20direct%20cause%20of%20the%20following%20exception:%0A%0ATraceback%20(most%20recent%20call%20last):%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/CasambiBt/_client.py%22,%20line%20119,%20in%20connect%0A%20%20%20%20self._gattClient%20=%20await%20establish_connection(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak_retry_connector/init.py%22,%20line%20387,%20in%20establish_connection%0A%20%20%20%20_raise_if_needed(name,%20device.address,%20exc)%0A%20%20File%20%22/usr/local/lib/python3.12/site-packages/bleak_retry_connector/init.py%22,%20line%20327,%20in%20_raise_if_needed%0A%20%20%20%20raise%20BleakNotFoundError(msg)%20from%20exc%0Ableak_retry_connector.BleakNotFoundError:%20Casambi%20Network%20-%2046:29:30:DD:95:B9:%20Failed%20to%20connect%20after%204%20attempt(s):%20TimeoutError%0A

![Uploading IMG_0461.jpeg…]()

schoenis commented 8 months ago

IMG_0462 IMG_0461

schoenis commented 8 months ago

after countless restarts of HA or the Add on it gets back on track at least for some time, then back to start..

CFenner commented 8 months ago

Is this still happening or can I close it?

I think the issue still persists on my side. The room where I have the lamps is not used during the winter 🥶 so I do not know how it is currently.

lkempf commented 8 months ago

@schoenis Your error looks like a simple bluetooth issue. Have you tried decreasing the distance between your bluetooth adapter and the network?

macflei commented 7 months ago

Vielleicht hilft es ja auch dem ein oder anderen. Passives Scannen scheint bei mir das Problem mit den sporadischen Verbindungsabbrüchen behoben zu haben. Seit über 48 h scheint die Verbindung stabil zu sein. Vorher hatte ich am Tag auch immer zwischen 10 und 20 Verbindungsabbrüche und es half nur ein kompletter Systemneustart.

mein HA-Testsystem: RasPi 4 Bluetooth: intern vom Pi Core: 2024.3.3 Supervisor: 2024.03.1 Operating System: 12.1 Casambi-Integration: v0.1.1

CFenner commented 7 months ago

Wie stellst du auf passiv um?

macflei commented 7 months ago

Einstellungen --> Geräte & Dienste --> Bluetooth Dort dann auf Konfiguration und Häckchen setzen -- Absenden

konf

CFenner commented 7 months ago

I switched on my Casambi in the last days and changed BL connection to passive. Indeed it seems to be stable now.

Alexei-vk2 commented 5 months ago

Hello! Faced with this situation: Casambi integration is installed in the home assistant. when the "unavailable" condition occurs, the lights turn on and off.

is there any way to make sure that even after the "not available" state, the devices have the last mode so that they are turned off? can you tell me how to do this? WhatsApp Image 2024-05-13 at 10 57 27

Zubredo commented 1 week ago

I switched on my Casambi in the last days and changed BL connection to passive. Indeed it seems to be stable now.

Unfortunately, this does not solve the issues with my setup.

My Hardware Home Assistant Yellow with a Realtek Bluetooth 5 Stick.

Versions Latest (HA Core 2024.10.4, HA OS 13.2, Casambi Bluetooth 0.1.3)

Bug Description The Casambi Bluetooth integration looses connection with my occhio lamp every 24h-48h. After that only a restart brings the connection back. Change Bluetooth adapter to passive scan does not seem to stop the connection errors.

From the error logs it seems that the integration somehow messes with the bluetooth hardware. It says that the bluetooth adapter would not exist anymore.

Furthermore, the logs are saying _"[CasambiBt.client] Version too new. Your network version is 11. Highest supported version is 10. Continue at your own risk." No idea what that means.

Any Suggestions how to solve the issue?

Error Log

2024-10-16 19:22:44.859 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1
2024-10-16 19:23:01.996 ERROR (MainThread) [habluetooth.scanner] hci1 (00:2A:7A:00:15:48): Error stopping scanner: [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist

2024-10-16 19:23:04.741 ERROR (MainThread) [habluetooth.scanner] hci1 (00:2A:7A:00:15:48): Failed to restart Bluetooth scanner: hci1 (00:2A:7A:00:15:48): Failed to start Bluetooth: adapter 'hci1' not found; Try power cycling the Bluetooth hardware.
Traceback (most recent call last):
  File "src/habluetooth/scanner.py", line 329, in habluetooth.scanner.HaScanner._async_start_attempt
  File "src/habluetooth/scanner.py", line 329, in habluetooth.scanner.HaScanner._async_start_attempt
  File "src/habluetooth/scanner.py", line 332, in habluetooth.scanner.HaScanner._async_start_attempt
  File "/usr/local/lib/python3.12/site-packages/bleak/__init__.py", line 203, in start
    await self._backend.start()
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/scanner.py", line 178, in start
    self._stop = await manager.passive_scan(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/manager.py", line 513, in passive_scan
    self._check_adapter(adapter_path)
  File "/usr/local/lib/python3.12/site-packages/bleak/backends/bluezdbus/manager.py", line 209, in _check_adapter
    raise BleakError(f"adapter '{adapter_path.split('/')[-1]}' not found")
bleak.exc.BleakError: adapter 'hci1' not found

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

Traceback (most recent call last):
  File "src/habluetooth/scanner.py", line 528, in habluetooth.scanner.HaScanner._async_restart_scanner
  File "src/habluetooth/scanner.py", line 286, in _async_start
  File "src/habluetooth/scanner.py", line 373, in _async_start_attempt
habluetooth.scanner.ScannerStartError: hci1 (00:2A:7A:00:15:48): Failed to start Bluetooth: adapter 'hci1' not found; Try power cycling the Bluetooth hardware.
2024-10-16 19:23:14.861 DEBUG (MainThread) [custom_components.casambi_bt] Starting delayed reconnect.
2024-10-16 19:23:15.941 WARNING (MainThread) [CasambiBt._client] Version too new. Your network version is 11. Highest supported version is 10. Continue at your own risk.
2024-10-16 19:23:17.458 ERROR (MainThread) [CasambiBt._client] Unexpected answer from device! Wrong device or protocol version? Trying to continue.
2024-10-16 19:23:21.247 DEBUG (MainThread) [custom_components.casambi_bt.light] Handling state change for unit 1