j5lien / esphome-idasen-desk-controller

ESPHome component for Ikea Idasen desk control
MIT License
187 stars 36 forks source link

Height is received only at startup #67

Closed rotarucosminleonard closed 1 year ago

rotarucosminleonard commented 1 year ago

I had this issue where after using the animated graphic card, the buttons would not work. I lost my patience and I stopped using it. Today I flashed the microcontroller again using the same code and I noticed the height measurements are no longer working. This is also the reason the hardware button stopped after using the animated card because it would continuously send commands without ever reaching the set height.

Last time I check, it was identical to the one posted here

substitutions:
  devicename: smart-desk
  friendly_name: Smart Desk

esphome:
  name: $devicename
  comment: controls the height of the desk over bluetooth

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "3e3a4320572fa2f86190f00b072843a1"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  #power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Smart-Desk Fallback Hotspot"
    password: "XDBOHjorEm4J"

captive_portal:

text_sensor:
  - platform: wifi_info
    ip_address:
      name: $friendly_name IP Address
    mac_address:
      name: $friendly_name Mac Address

external_components:
  #- source: github://j5lien/esphome-idasen-desk-controller@v3.0.0
  #- source: github://j5lien/esphome-idasen-desk-controller@pull/51/head
  - source: github://j5lien/esphome-idasen-desk-controller@v4.0.0

esp32_ble_tracker:

idasen_desk_controller:
    # Reference to the ble client component id
    # -----------
    # Required
    ble_client_id: idasen_desk
    # Fallback to use only up and down commands (less precise)
    # -----------
    # Optional
    only_up_down_command: false

cover:
  - platform: idasen_desk_controller
    name: "Desk"

globals:
  # To store the Desk Connection Status
  - id: ble_client_connected
    type: bool
    initial_value: 'false'

ble_client:
  - mac_address: !secret desk_ble_mac
    id: idasen_desk
    on_connect:
      then:
        # Update the Desk Connection Status
        - lambda: |-
            id(ble_client_connected) = true;
        - delay: 5s
        # Update desk height and speed sensors after bluetooth is connected
        - lambda: |-
            id(desk_height).update();
    on_disconnect:
      then:
        # Update the Desk Connection Status
        - lambda: |-
            id(ble_client_connected) = false;
sensor:

  # LAN Connection
  - platform: wifi_signal
    name: $friendly_name WiFi Signal
    update_interval: 30s
  - platform: uptime
    name: $friendly_name Uptime

  # 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;'

  # Device status entity in HomeAssistant.
  - platform: status
    name: ${friendly_name} Status

#restart device
switch:
  - platform: restart
    name: $friendly_name Restart
rotarucosminleonard commented 1 year ago

it may have something to do with the desk itself. It started working withoud as expected after powercycling the desk.