ronengr / hass_nuki_bt

Control Nuki Lock over bluetooth
MIT License
38 stars 8 forks source link

No backend with an available connection slot that can reach address #7

Closed nov1n closed 1 year ago

nov1n commented 1 year ago

System Health details

System Information

version core-2023.5.4
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 6.1.21-v8+
arch aarch64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.30.1 Stage | running Available Repositories | 1286 Downloaded Repositories | 10
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 1 -- | -- resources | 3 views | 1 mode | storage
Recorder oldest_recorder_run | 21 May 2023 at 03:27 -- | -- current_recorder_run | 30 May 2023 at 20:04 estimated_db_size | 109.45 MiB database_engine | sqlite database_version | 3.40.1
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

Cannot pair Nuki Smart Lock 3.0 using Raspberry Pi 4B with buit-in Bluetooth.

Reproduction steps

No Nuki device is automatically discovered.

I then tried adding the integration manually and filled out the device name and address. This takes me to the followup screen and after putting the Nuki in pairing mode and selecting 'Pair device automatically' I get an error.

Debug logs

2023-05-31 15:27:07.159 WARNING (MainThread) [homeassistant.helpers.frame] Detected integration that attempted to call BleakClient with an address instead of a BLEDevice. Please report issue to the custom integration author for hass_nuki_bt using this method at custom_components/hass_nuki_bt/config_flow.py, line 151: ret = await device.pair()
2023-05-31 15:27:07.162 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 267, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/hass_nuki_bt/config_flow.py", line 151, in async_step_pair
    ret = await device.pair()
  File "/usr/local/lib/python3.10/site-packages/pyNukiBT/nuki.py", line 502, in pair
    await self.connect() # connect so we can identify the device type and update self._const accordingly
  File "/usr/local/lib/python3.10/site-packages/pyNukiBT/nuki.py", line 386, in connect
    await self._client.connect()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 253, in connect
    wrapped_backend = self._async_get_best_available_backend_and_device(manager)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 355, in _async_get_best_available_backend_and_device
    raise BleakError(
bleak.exc.BleakError: No backend with an available connection slot that can reach address XX:XX:XX:XX:XX:XX was found

Diagnostics dump

No response

nov1n commented 1 year ago

So after setting up an ESP32 as a Bluetooth proxy the Nuki is detected. , When configuring automatically the wizard finishes, but it says 'Failed to setup' on the integrations page.

Logs:

2023-06-08 20:50:03.499 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Apartment door for hass_nuki_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/hass_nuki_bt/__init__.py", line 79, in async_setup_entry
    if not await coordinator.async_wait_ready():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_nuki_bt/coordinator.py", line 148, in async_wait_ready
    await self._async_update()
  File "/config/custom_components/hass_nuki_bt/coordinator.py", line 108, in _async_update
    await self.device.update_state()
  File "/usr/local/lib/python3.11/site-packages/pyNukiBT/nuki.py", line 424, in update_state
    self._const.NukiCommand.REQUEST_DATA,
    ^^^^^^^^^^^
AttributeError: 'NukiDevice' object has no attribute '_const'

Any ideas @ronengr ?

ronengr commented 1 year ago

Regarding the first issue, it seems there is no BT controller available to HA that is in range of the Nuki. So basically there is either an issue with the BT on the RPI or the RPI is too far away from the Nuki for good communication. I see that adding a BT Proxy fixed this :-)

Regarding the 2nd issue, this is strange. what version of hass_nuki_bt are you using? Have you tried removing the device and re-discovering it?

nov1n commented 1 year ago

I assumed having a Bluetooth enabled Raspberry Pi was enough, but apparently not.

I've tried everything that came to mind including your suggestion using version 0.0.5, but no luck. In the end I switched to https://github.com/technyon/nuki_hub, which works well.

ronengr commented 1 year ago

Having a BT enabled RPI should be enough. personally I have a CuBox with internal BT and is working perfectly to control the Nuki. I didn't try with RPI, but it should work. Did you add the BT adapter to HA? do you have other BT devices that HA can detect with RPI's BT? Could be an issue with the BT adapter or maybe distance/BT signal strength.

0.0.5 is the latest version, and it should work. It is strange you are getting this error. I will look at the code again and try to see if i can find the issue.

nov1n commented 1 year ago

Maybe there was something wrong with my Bluetooth config. I'd rather not touch it now that it's working so I won't be able to give you more help with debugging.

If I'm the only one facing this problem it was likely me. I think there's definitely a case for not using an ESP so I hope your project will be successful!

Feel free to close this issue.

harmptor commented 11 months ago

I am getting this error in conjunction with this warning:

2023-11-25 13:18:36.015 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'hass_nuki_bt' attempted to call BleakClient with an address instead of a BLEDevice at custom_components/hass_nuki_bt/config_flow.py, line 151: ret = await device.pair(), please create a bug report at https://github.com/ronengr/hass_nuki_bt/issues

I'm also on a Pi 4B with builtin bluetooth. My Nuki lock is version 1.0. hass_nuki_bt version is 0.0.7.

EDIT: After moving the Pi closer (From 3 meters to 2 meters [maybe the BT signal strength on the nuki 1.0 isn't very good]) I still get this error but I also get different errors which I assume don't belong to this issue.

maryum375 commented 7 months ago

Same error here with NUKI 3 (not pro) and a raspberry pi located quite close to the NUKI. First time it did work but calling the service failed. After removing the integration and trying to pair again it immediately showed "ERROR" and the logs show:

File "/usr/local/lib/python3.11/site-packages/habluetooth/wrappers.py", line 379, in _async_get_best_available_backend_and_device raise BleakError( bleak.exc.BleakError: No backend with an available connection slot that can reach address 54:D2:XX:XX:XX:XX was found

ronengr commented 7 months ago

@maryum375 if you are getting this error from bleak it means the computer cannot find a way to communicate with the Nuki BT device. either there is an issue with the BT adapter or there are interference or some other issues causing the connection issue. you can try moving the RPI closer or try adding an antenna to the RPI, or maybe use a BT proxy.

Unfortunately, if bleak (the underlying BT package for HA) cannot establish a connection to the device, there is nothing i can do