Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ikea Idasen desk pairing failed using builtin Bluetooth #101452

Closed
basdejong95 opened this issue Oct 5, 2023 · 24 comments
Closed

Ikea Idasen desk pairing failed using builtin Bluetooth #101452

basdejong95 opened this issue Oct 5, 2023 · 24 comments

Comments

@basdejong95
Copy link

The problem

I just updated to 2023.10 and tried to pair my ikea idasen desks. The integration auto discovers both desks, but when i want to configure them i just get a "failed to connect" error.

Logger: homeassistant.components.idasen_desk.config_flow
Source: components/idasen_desk/config_flow.py:66
Integration: IKEA Idasen Desk (documentation, issues)
First occurred: 09:10:33 (1 occurrences)
Last logged: 09:10:33

BleakError
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/idasen_desk/config_flow.py", line 66, in async_step_user
    await desk.connect(discovery_info.device, monitor_height=False)
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 48, in connect
    await self._idasen_desk.connect()
  File "/usr/local/lib/python3.11/site-packages/idasen/__init__.py", line 145, in connect
    await self._client.connect()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 273, in connect
    wrapped_backend = self._async_get_best_available_backend_and_device(manager)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 375, in _async_get_best_available_backend_and_device
    raise BleakError(
bleak.exc.BleakError: No backend with an available connection slot that can reach address D0:99:A6:D0:C7:B0 was found

What version of Home Assistant Core has the issue?

core-2023.10.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Ikea Idasen Desk

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Oct 5, 2023

Hey there @abmantis, mind taking a look at this issue as it has been labeled with an integration (idasen_desk) you are listed as a code owner for? Thanks!

Code owner commands

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

(message by CodeOwnersMention)


idasen_desk documentation
idasen_desk source
(message by IssueLinks)

@abmantis
Copy link
Contributor

abmantis commented Oct 5, 2023

"BleakError: No backend with an available connection slot that can reach address D0:99:A6:D0:C7:B0 was found"

I think that either the desks are too far from the Bluetooth radio or the radio cannot have active connections (or is already connected to other devices and cannot connect to a new one).
Make sure your radios support active connections, and not only passive listening.

@basdejong95
Copy link
Author

Ah okay, that could explain the issue. I'm justing the built-in bluetooth of the RPI 4 which is one floor down from where the desks are. But i was curious because the integration could find the 2 desks, they have not previously been connected to another bluetooth device.

Maybe the error i'm getting could also be made a bit more user friendly in Home assistant?

And maybe this is kind of offtopic for this issue, is there some kind of documentation on how to place a new bluetooth antenna/sensor somewhere else in your house?

@abmantis
Copy link
Contributor

abmantis commented Oct 5, 2023

They were probably spotted at some point by the RPI radio.
Yeah, the error could indeed be improved, I'll have to check that out.

Regarding improving bluetooth coverage, check ESPHome Bluetooth Proxy.

@rickeydk
Copy link

rickeydk commented Oct 5, 2023

I think I have a similar issue, but a different error entry in my log.

I too get "Failed to connect" error when I try to setup the integration which auto-discovered the desk perfectly.

I've reset the desk (hold the pairing down button for +10 secs) before entering pairing mode again, but to no avail.

I've also tried physically placing my HA server right below the desk controller.

Thank you so much for taking the time to make this integration happen and please let me know if I can be of any assistance. Here's my log:

Logger: homeassistant.components.idasen_desk.config_flow
Source: components/idasen_desk/config_flow.py:66
Integration: IKEA Idasen Desk ([documentation](https://www.home-assistant.io/integrations/idasen_desk), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+idasen_desk%22))
First occurred: 14:42:02 (1 occurrences)
Last logged: 14:42:02
BleakError

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/idasen_desk/config_flow.py", line 66, in async_step_user
    await desk.connect(discovery_info.device, monitor_height=False)
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 54, in connect
    raise ex
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 50, in connect
    await self._idasen_desk.pair()
  File "/usr/local/lib/python3.11/site-packages/idasen/__init__.py", line 126, in pair
    await self._client.pair()
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 629, in pair
    return await self._backend.pair(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 473, in pair
    assert_reply(reply)
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.AuthenticationFailed] Authentication Failed

@abmantis
Copy link
Contributor

abmantis commented Oct 5, 2023 via email

@rickeydk
Copy link

rickeydk commented Oct 5, 2023

Yup!

I press the pairing button for 3 seconds and then the blue LED blinks once, then waits about 2 seconds, before it blinks again. It repeats that pattern for a while.

It's the same way I pair it to my phone to use the Desk Control app.

@abmantis
Copy link
Contributor

abmantis commented Oct 5, 2023

I was now able to reproduce this issue when using HA in my laptop, using its builtin Bluetooth. When using ESPHome Bluetooth Proxy it works fine.
It may be something in the container setup, or just some issue with bluetooth/bleak. If I pair it manually first (using bluetoothctl), then HA is able to setup the integration and connect.

I'll have to dig a bit more.

@backslashV
Copy link

backslashV commented Oct 5, 2023

I am getting another error when trying to pair. The desk is next to the HA server.

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 209, in connect
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dbus_fast/aio/message_bus.py", line 399, in call
    await future
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/idasen_desk/config_flow.py", line 66, in async_step_user
    await desk.connect(discovery_info.device, monitor_height=False)
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 48, in connect
    await self._idasen_desk.connect()
  File "/usr/local/lib/python3.11/site-packages/idasen/__init__.py", line 145, in connect
    await self._client.connect()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 292, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 605, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 146, in connect
    async with async_timeout(timeout):
  File "/usr/local/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

Actually, I also see this

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/idasen_desk/config_flow.py", line 66, in async_step_user
    await desk.connect(discovery_info.device, monitor_height=False)
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 54, in connect
    raise ex
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 50, in connect
    await self._idasen_desk.pair()
  File "/usr/local/lib/python3.11/site-packages/idasen/__init__.py", line 126, in pair
    await self._client.pair()
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 629, in pair
    return await self._backend.pair(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 473, in pair
    assert_reply(reply)
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.AuthenticationFailed] Authentication Failed

@kuzabi
Copy link

kuzabi commented Oct 5, 2023

I have simmillar errors. Desk is near HA with Ugreen CM390 adapter.

BleakError

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/idasen_desk/config_flow.py", line 66, in async_step_user
    await desk.connect(discovery_info.device, monitor_height=False)
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 54, in connect
    raise ex
  File "/usr/local/lib/python3.11/site-packages/idasen_ha/__init__.py", line 50, in connect
    await self._idasen_desk.pair()
  File "/usr/local/lib/python3.11/site-packages/idasen/__init__.py", line 126, in pair
    await self._client.pair()
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 629, in pair
    return await self._backend.pair(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 473, in pair
    assert_reply(reply)
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.AuthenticationFailed] Authentication Failed

@mokshmridul
Copy link

I'm having the same issue as above, with similar lines in my logs.

@rickeydk
Copy link

rickeydk commented Oct 5, 2023

I was now able to reproduce this issue when using HA in my laptop, using its builtin Bluetooth. When using ESPHome Bluetooth Proxy it works fine. It may be something in the container setup, or just some issue with bluetooth/bleak. If I pair it manually first (using bluetoothctl), then HA is able to setup the integration and connect.

I'll have to dig a bit more.

You're a genius @abmantis ! Connecting and pairing manually with bluetoothctl worked for me too, thanks!

I was worried I'd have to do that each time after Home Assistant restarts, since the desk cover entity becomes unavailable after rebooting, but reloading the integration was enough to bring the entity back.
I think this integration is loaded before the Bluetooth integration.

Another unexpected behavior I noticed is if I use service: cover.set_cover_position then the desk will continue to move above or below (depending on direction) of the value I requested by 1 or 2%.
So if the current position is 10% and I use cover.set_cover_position to set it to 20%, then the Desk stops at 22%.

Once again, thank you for taking the time to make this.

@abmantis
Copy link
Contributor

abmantis commented Oct 5, 2023

I was now able to reproduce this issue when using HA in my laptop, using its builtin Bluetooth. When using ESPHome Bluetooth Proxy it works fine. It may be something in the container setup, or just some issue with bluetooth/bleak. If I pair it manually first (using bluetoothctl), then HA is able to setup the integration and connect.
I'll have to dig a bit more.

You're a genius @abmantis ! Connecting and pairing manually with bluetoothctl worked for me too, thanks!

I was worried I'd have to do that each time after Home Assistant restarts, since the desk cover entity becomes unavailable after rebooting, but reloading the integration was enough to bring the entity back. I think this integration is loaded before the Bluetooth integration.

Another unexpected behavior I noticed is if I use service: cover.set_cover_position then the desk will continue to move above or below (depending on direction) of the value I requested by 1 or 2%. So if the current position is 10% and I use cover.set_cover_position to set it to 20%, then the Desk stops at 22%.

Once again, thank you for taking the time to make this.

Glad to know it works as a workaround. I am not sure if this is an issue with the integration, HA or Bleak, as it works fine with ESPHome Proxies. I'll have to dig a bit.
The integration should be loaded after Bluetooth already. I noticed that the desk sometimes fails to connect, even with some retrying, so that may be the cause. Still, the integration should reload automatically after a couple seconds.

Regarding the position, yeah, that is a known issue with the underlying mechanism that controls movement, and I am not sure it will be possible to fix since there is a delay between sending the command for it to stop and it actually stopping. Maybe we can improve it, but it is not top prio for me at the moment.

@abmantis
Copy link
Contributor

abmantis commented Oct 6, 2023

Unfortunately, this seems to be a limitation of the underlying bluetooth library that HA uses (bluez): hbldh/bleak#1434

The recommended way is to use an ESPHome Bluetooth Proxy, since it does not have that limitation and works better overall.

As a workaround for those not using ESPHome BT Proxy, you can just open bluetoothctl and setup the integration. You can close it afterwords since it just needs to be open for pairing. The Bluetooth settings menu on Gnome also works (and I assume any Bluetooth management UI will too, as long as it starts an auth agent).

The HA docs need to be updated with this, I guess.

@mokshmridul
Copy link

I got this working by adding the device using bluetoothctl as well.

@ruthem
Copy link

ruthem commented Oct 6, 2023

I had the same issue with the integration.

But pairing via bluetoothctl pair ... has also not worked.

I also tried bluetoothctl trust ... for my device, but pairing was still not working.

For me, keeping bluetoothctl (without any parameter) running in the background and configuring the integration in the mean time, did the trick in the end.

@mokshmridul
Copy link

I had the same issue with the integration.

But pairing via bluetoothctl pair ... has also not worked.

I also tried bluetoothctl trust ... for my device, but pairing was still not working.

For me, keeping bluetoothctl (without any parameter) running in the background and configuring the integration in the mean time, did the trick in the end.

Yes, the desk keeps going offline, and needs an integration reload to work again. Keeping bluetoothctl open did not fix the issue for me

@d0ugal
Copy link
Contributor

d0ugal commented Oct 25, 2023

Regarding the position, yeah, that is a known issue with the underlying mechanism that controls movement, and I am not sure it will be possible to fix since there is a delay between sending the command for it to stop and it actually stopping. Maybe we can improve it, but it is not top prio for me at the moment.

I worked around this with an automation that keeps calling cover.set_cover_position it is correct. Usually gets there on the second call :)

@mogusbi
Copy link

mogusbi commented Oct 25, 2023

Regarding the position, yeah, that is a known issue with the underlying mechanism that controls movement, and I am not sure it will be possible to fix since there is a delay between sending the command for it to stop and it actually stopping. Maybe we can improve it, but it is not top prio for me at the moment.

I worked around this with an automation that keeps calling cover.set_cover_position it is correct. Usually gets there on the second call :)

Would you be able to share this automation please? @d0ugal

@d0ugal
Copy link
Contributor

d0ugal commented Oct 25, 2023

Regarding the position, yeah, that is a known issue with the underlying mechanism that controls movement, and I am not sure it will be possible to fix since there is a delay between sending the command for it to stop and it actually stopping. Maybe we can improve it, but it is not top prio for me at the moment.

I worked around this with an automation that keeps calling cover.set_cover_position it is correct. Usually gets there on the second call :)

Would you be able to share this automation please? @d0ugal

Sure, so it is actually a script that I use but you could just copy the sequence steps into an automation.

script:
  study_desk_set_position:
    alias: "Study desk Set Position"
    mode: restart
    fields:
      new_height:
        example: "50"
    sequence:
      - condition: >-
          {{ state_attr('cover.study_desk', 'current_position')|int != new_height }}
      - repeat:
          while:
            - condition: template
              value_template: >
                {{ state_attr('cover.study_desk', 'current_position')|int != new_height and repeat.index <= 5 }}
          sequence:
            - service: cover.set_cover_position
              data_template:
                entity_id: cover.study_desk
                position: >-
                  {{ new_height }}
            - delay: 5
            - wait_template: >
                {{ not is_state('cover.study_desk', 'closing') and not is_state('cover.study_desk', 'opening') }}

Then you can call it with something like;

     - service: script.study_desk_set_position
        data:
          new_height: 20

The script sets the position, waits for 5 seconds to give it a chance to start moving and then the wait template checks that it has stopped moving. Then if it is still out of position it will retry up to 5 times.

Its a bit confusing but hopefully it makes sense, I had to extract this out and reduce it from what I have as my desk is fully automated (it alternates between sitting and standing every hour with a few condition and light flashes to warn me its about to move etc.

@abmantis
Copy link
Contributor

abmantis commented Dec 6, 2023

@home-assistant rename Ikea Idasen desk pairing failed using builtin Bluetooth

@home-assistant home-assistant bot changed the title Ikea Idasen desk pairing failed Ikea Idasen desk pairing failed using builtin Bluetooth Dec 6, 2023
@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@d0ugal
Copy link
Contributor

d0ugal commented Mar 6, 2024

This is still an issue

@github-actions github-actions bot removed the stale label Mar 6, 2024
@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants