BluetoothHome Automation

Outsmarting the Desk V2

Ivan Lesar

Ivan Lesar

· 4 min read
Thumbnail

Declaring the issue

About a year ago I joined the ‘standing desk’ community by investing in a IKEA IDÅSEN desk powered by a Linak BLE adapter. A part of me wanted to reverse all the strain bolted onto my back from sitting through at least 8 hours a day.

The desk controls are minimal, but it bothered me from the start that I had to hold the button until the desk reached the desired height. The desire of a fully automated desk was not fulfilled.

How will I approach it?

Well, the desk controller uses Low Energy Bluetooth (BLE), which is a handy protocol which in itself defines services needed to operate the underlying functionalities. But this was not needed. The wheel was already built and we are certainly not going to reinvent it.

We need a few things…

The steps

  1. First we need to find out the MAC address of our desk controller. We’ll use the BLE Scanner Android app to find out the address.

Bluetooth Low Energy Scanner

  1. Add a HA support for IKEA Linak (Idasen) by following the installation in the GitHub repository.
  2. Install the HACS Lovelace plugin called LinakDesk Card
  3. Add a new ESPHome device configuration and add this to the end of the yaml file
 ESPHome configuration
yaml
esphome:
name: ikea-desk
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
encryption:
key: "your_api_key"
ota:
password: "your_ota_password"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Optional static IP
manual_ip:
static_ip: x.x.x.x
gateway: x.x.x.x
subnet: 255.255.255.0
ap:
ssid: "Ikea-Desk Fallback Hotspot"
password: "your fallback hotspot password"
captive_portal:
external_components:
- source: github://j5lien/esphome-idasen-desk-controller@v3.0.0
globals:
- id: ble_client_connected
type: bool
initial_value: "false"
esp32_ble_tracker:
ble_client:
# Replace with the desk bluetooth mac address
- mac_address: "11:22:33:44:55:66"
id: idasen_desk
on_connect:
then:
- lambda: |-
id(ble_client_connected) = true;
- delay: 5s
- lambda: |-
id(desk_height).update();
id(desk_speed).update();
on_disconnect:
then:
- lambda: |-
id(ble_client_connected) = false;
idasen_desk_controller:
ble_client_id: idasen_desk
only_up_down_command: false
cover:
- platform: idasen_desk_controller
name: "Desk"
sensor:
# Desk Height Sensor
- platform: ble_client
type: characteristic
ble_client_id: idasen_desk
id: desk_height
name: "Desk Height"
service_uuid: "99fa0020-338a-1024-8a49-009c0215f78a"
characteristic_uuid: "99fa0021-338a-1024-8a49-009c0215f78a"
icon: "mdi:arrow-up-down"
unit_of_measurement: "cm"
accuracy_decimals: 1
update_interval: never
notify: true
lambda: |-
uint16_t raw_height = ((uint16_t)x[1] << 8) | x[0];
unsigned short height_mm = raw_height / 10;
return (float) height_mm / 10;
# Desk Speed Sensor
- platform: ble_client
type: characteristic
ble_client_id: idasen_desk
id: desk_speed
name: "Desk Speed"
service_uuid: "99fa0020-338a-1024-8a49-009c0215f78a"
characteristic_uuid: "99fa0021-338a-1024-8a49-009c0215f78a"
icon: "mdi:speedometer"
unit_of_measurement: "cm/min" # I'm not sure this unit is correct
accuracy_decimals: 0
update_interval: never
notify: true
lambda: |-
uint16_t raw_speed = ((uint16_t)x[3] << 8) | x[2];
return raw_speed / 100;
binary_sensor:
# Desk Bluetooth Connection Status
- platform: template
name: "Desk Connection"
id: desk_connection
lambda: "return id(ble_client_connected);"
# Desk Moving Status
- platform: template
name: "Desk Moving"
id: desk_moving
lambda: "return id(desk_speed).state > 0;"
  1. That’s it. Our card is now available in the Lovelace GUI. We need to add the card and paste the raw yaml configuration provided below. Be sure to change the desk heights to your needs.
 Lovelace card configuration
yaml
type: "custom:linak-desk-card"
desk: cover.desk
height_sensor: sensor.desk_height
moving_sensor: binary_sensor.desk_moving
connection_sensor: binary_sensor.desk_connection
min_height: 60
max_height: 126
presets:
- label: Stay
target: 120
- label: Sit
target: 76

An output is needed

The IKEA IDÅSEN (Linak) desk is now a bit smarter. You no longer have to hold the height buttons. Just press a button and let the smart home system do its magic.

Homeasisstant Lovel1ace Card

Of course, if you integrate it with Google Home, you can control it by voice. The Google home system will see it as window blinds.

The links to all components can be found at the top of the article. ☝️

Ivan Lesar

About Ivan Lesar

Curious overthinker with a purpose to tinker. Software engineer with a background in mathematics.
Copyright © 2023 Ivan Lesar. All rights reserved.