I'm using a lot of substitiutions and additional wifi settings in this example, feel free to remove them and / or replace them by the ESPHome defaults as shown in the linked examples.
# Office Desk Bridge
# Variables
substitutions:
device_name: !secret node_26_device_name
friendly_name: !secret node_26_friendly_name
hardware_id: !secret node_26_hardware_id
static_ip: !secret node_26_static_ip
ssid: !secret not_ssid
ssid_pw: !secret not_password
ap_pw: !secret ap_password
gateway: !secret not_gateway
subnet: !secret not_subnet
ntp: !secret ntp
wifi:
manual_ip:
static_ip: $static_ip
gateway: $gateway
subnet: $subnet
networks:
- ssid: $ssid
password: $ssid_pw
# If wifi can not connect reboot with in xx hours
reboot_timeout: 0s
fast_connect: true
#Access Point
ap:
ssid: AP_${device_name}
password: $ap_pw
#Captive Portal when ap is on
captive_portal:
#Web Server for manual access
web_server:
#Log to ESPHome
logger:
#Disable logging to serial
baud_rate: 0
#Homeassitant API
api:
reboot_timeout: 0s
#ESPHome OTA
ota:
esphome:
name: "${device_name}"
name_add_mac_suffix: false
esp32:
board: esp32dev
framework:
type: arduino
external_components:
- source: github://j5lien/esphome-idasen-desk-controller@v4.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: "CE:41:99:2E:BA:4D"
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: "${friendly_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 / 5.118110236;
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;'
# Example configuration entry
switch:
- platform: restart
name: "${friendly_name} Restart"
Hi Guys, I had quite some trouble setting this up. So I'll share my finaly working ESPHome config with you.
Adding this to my config was the crucial part for it to work:
Further I adjusted the height calculation to be corret for my desk. The divider of the raw_height has been changed from 10 to 5.118110236.
I'm using a lot of substitiutions and additional wifi settings in this example, feel free to remove them and / or replace them by the ESPHome defaults as shown in the linked examples.