core: Ikea Idasen desk pairing failed using builtin Bluetooth

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

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Comments: 23 (10 by maintainers)

Most upvoted comments

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.

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.

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

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.