iMicknl / LoctekMotion_IoT

Learn how to connect your Flexispot (LoctekMotion) desk to the internet. This repository contains a collection of scripts to get your started, combined with research and instructions.
MIT License
626 stars 61 forks source link

[No Issue] My config; more Buttons/Features/ "wakeup" #35

Open KrX3D opened 2 years ago

KrX3D commented 2 years ago

Hello, i wanted to share my config with you for Esphome:

1 2

Features:

The only thing i would like to add would be to get the height when manually driving up/down via display. but im not sure how to do that

i also changed line 9 in desk_height_sensor.h from float value = NULL; to float value = 0.0;

to solve the warning in ESPHOME when compiling

substitutions:
  device_name: Flexispot E7
  name: flexispot_e7
  min_height: "60.5" # Min height + 0.1
  max_height: "126" # Max height - 0.1

esphome:
  name: ${name}
  comment: ${device_name}
  includes:
    - desk_height_sensor.h
  on_boot:
    priority: -10
    then:
      - switch.turn_on: switch_1_2

esp8266:
  board: d1_mini

logger:
  esp8266_store_log_strings_in_flash: false
  #level: DEBUG
  baud_rate: 0

#Enable Home Assistant API
api:
  encryption:
    key: XXXXXXXXXXXXXXXXXXXXXXX

ota:
  password: XXXXXXXXXXXXXXXXXXXXX

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 60min
  manual_ip:
    static_ip: 192.168.0.24
    gateway: XXXXXX
    subnet: XXXXXXX
  fast_connect: true

  #Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Flexispot-Wemos Fallback Hotspot"
    password: XXXXXXX

captive_portal:

uart:
  id: desk_uart
  baud_rate: 9600
  tx_pin: D5
  rx_pin: D6

binary_sensor:
  - platform: status
    name: "${device_name} Status"

sensor:
  - platform: wifi_signal
    name: "${device_name} WiFi Signal"
    update_interval: 60s
    accuracy_decimals: 0

  - platform: uptime
    name: "${device_name} Uptime"
    unit_of_measurement: minutes
    update_interval: 60s
    accuracy_decimals: 0
    filters:
      - lambda: return x / 60.0;

  - platform: custom
    lambda: |-
      auto desk_height_sensor = new DeskHeightSensor(id(desk_uart));
      App.register_component(desk_height_sensor);
      return {desk_height_sensor};
    sensors:
      id: "desk_height"
      name: "${device_name} Tischhöhe"
      unit_of_measurement: cm
      accuracy_decimals: 1
      icon: "mdi:counter"

switch:
  - platform: gpio
    name: "Virtual Screen"
    pin:
      number: D2
      mode: OUTPUT
    restore_mode: ALWAYS_OFF
    internal: true

  - platform: restart
    name: "${device_name} Restart"
    id: reset

  - platform: uart
    name: "${device_name} Preset 1"
    id: switch_preset1
    icon: mdi:numeric-1-box
    data: [0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d]
    uart_id: desk_uart

  - platform: uart
    name: "${device_name} Preset 2"
    id: switch_preset2
    icon: mdi:numeric-2-box
    data: [0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d]
    uart_id: desk_uart

  - platform: uart
    name: "${device_name} Sitzen" # Preset 3 on some control panels
    id: switch_sit
    icon: mdi:chair-rolling
    data: [0x9b, 0x06, 0x02, 0x00, 0x01, 0xac, 0x60, 0x9d]
    uart_id: desk_uart
    on_turn_off:
      - delay: 7500ms
      - switch.turn_on: switch_1_2

  - platform: uart
    name: "${device_name} Stehen" # Not available for all control panels
    id: switch_stand
    icon: mdi:human-handsup
    data: [0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d]
    uart_id: desk_uart
    on_turn_off:
      - delay: 7500ms
      - switch.turn_on: switch_1_2

  - platform: uart
    name: "${device_name} Hoch"
    id: switch_up
    icon: mdi:arrow-up-bold
    data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d]
    uart_id: desk_uart
    internal: true

  - platform: uart
    name: "${device_name} Runter"
    id: switch_down
    icon: mdi:arrow-down-bold
    data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d]
    uart_id: desk_uart
    internal: true

  - platform: uart
    name: "${device_name} M"
    id: switch_m
    icon: mdi:alpha-m-circle
    data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d]
    uart_id: desk_uart

  - platform: uart
    name: "${device_name} (wake up)" # Not available on all control panels
    id: switch_wake_up
    icon: mdi:gesture-tap-button
    data: [0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d]
    uart_id: desk_uart

    #https://github.com/Dude88/loctek_IOT_box/blob/main/code_send_by_controllbox
  - platform: uart
    name: "${device_name} Anti Collision"
    id: switch_anti_kollision
    icon: mdi:card-remove
    data: [0x9b, 0x06, 0x02, 0x03, 0x00, 0x9C, 0xa1, 0x9d]
    uart_id: desk_uart
    send_every: 1ms
    on_turn_on:
      - delay: 6000ms
      - switch.turn_off: switch_anti_kollision

  - platform: uart
    name: "${device_name} Child Lock"
    id: switch_lock
    icon: mdi:account-lock
    data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d]
    uart_id: desk_uart
    send_every: 1ms
    on_turn_on:
      - delay: 5000ms
      - switch.turn_off: switch_lock

  - platform: uart
    name: "${device_name} 1 + 2" # Not available for all control panels // Could be used as wake up ?
    id: switch_1_2
    icon: mdi:counter
    data: [0x9b, 0x06, 0x02, 0x0c, 0x01, 0xac, 0x65, 0x9d]
    uart_id: desk_uart
    send_every: 1ms
    on_turn_on:
      - delay: 5000ms
      - switch.turn_off: switch_1_2

  - platform: uart
    name: "${device_name} M + sitting" # While holding it shows some numbers / M+sitting
    id: switch_m_sitting
    icon: mdi:script
    data: [0x9b, 0x06, 0x02, 0x20, 0x01, 0x6c, 0x79, 0x9d]
    uart_id: desk_uart
    send_every: 1ms
    on_turn_on:
      - delay: 15500ms
      - switch.turn_off: switch_m_sitting

    #RESET TO FACTORY SETTINGS
    #AFTER DISPLAY SHOWS RST, PRESS THE DOWN BUTTON UNTIL THE TABLE REACHES THELOWEST
    #POINT AND REBOUNDS. THAT MEANS RESET IS FINISHED
    #IF DISPLAY SHOED E01 OR E02, RETRY 18 MINUTES LATER
  - platform: uart
    name: "${device_name} Factory Reset" # M+standing 3sec
    id: switch_factory_reset
    icon: mdi:factory
    data: [0x9b, 0x06, 0x02, 0x30, 0x00, 0x6c, 0xb5, 0x9d]
    uart_id: desk_uart
    send_every: 1ms
    on_turn_on:
      - delay: 5000ms
      - switch.turn_off: switch_factory_reset

cover:
  - platform: template
    #icon: mdi:table-chair
    #icon: mdi-human-male-height-variant
    name: "${device_name} Tisch"
    assumed_state: true

    #Move desk up
    open_action:
      - while:
          condition:
            sensor.in_range:
              id: desk_height
              below: ${max_height}
          then:
          - logger.log: "Executing up command"
          - switch.turn_on: switch_up
          - delay: 10ms

    #Move desk down
    close_action:
      - while:
          condition:
            sensor.in_range:
              id: desk_height
              above: ${min_height} 
          then:
          - logger.log: "Executing down command"
          - switch.turn_on: switch_down
          - delay: 10ms

    # Stop Button
    stop_action:
      - logger.log: "Executing stop command"
      - switch.turn_on: switch_up
      - switch.turn_on: switch_down

    optimistic: true

#Sensors for ESP version and WIFI information
text_sensor:
  - platform: version
    name: "${device_name} ESPHome Version"

  - platform: wifi_info
    ip_address:
      name: "${device_name} ip"
    ssid:
      name: "${device_name} ssid"

EDIT: i changed the code for the cover, so the STOP button will work

thanks to guevara777 for his mushroom card here: https://github.com/iMicknl/LoctekMotion_IoT/issues/59

since i needed to make some changes because of the cover i use, this is the card:

image

type: custom:button-card
entity: cover.flexispot_e7_tisch
show_name: false
show_state: false
show_icon: false
styles:
  card:
    - overflow: unset
    - padding: 3px
  grid:
    - grid-template-areas: '"mushroom colors"'
    - grid-template-columns: auto 15rem
custom_fields:
  mushroom:
    card:
      type: custom:mushroom-template-card
      entity: '[[[ return entity.entity_id ]]]'
      tap_action:
        action: more-info
      icon_color: blue
      primary: '{{ state_attr(entity,"friendly_name") }}'
      secondary: >-
        {{ states("sensor.flexispot_e7_tischhohe") }} {{
        state_attr("sensor.flexispot_e7_tischhohe","unit_of_measurement") }}
      icon: '{{ state_attr(entity,"icon") }}'
      card_mod:
        style: |
          ha-card {
            padding: 3px 3px 3px 3px !important; #comment this line out if you want the bigger paddings around the card
            text-align: left !important;
            border: none !important;
            box-shadow: none !important;
          }
  colors:
    card:
      type: grid
      columns: 5
      square: false
      cards:
        - type: custom:button-card
          tap_action:
            action: call-service
            service: cover.close_cover
            service_data:
              entity_id: cover.flexispot_e7_tisch
          size: 70%
          show_state: false
          show_name: false
          show_icon: true
          icon: mdi:arrow-down
          styles:
            card:
              - padding: 3px
              - height: 40px
              - width: 2.5rem
              - box-shadow: none
              - border: none
              - background: var(--secondary-background-color)
        - type: custom:button-card
          tap_action:
            action: call-service
            service: cover.stop_cover
            service_data:
              entity_id: cover.flexispot_e7_tisch
          size: 70%
          show_state: false
          show_name: false
          show_icon: true
          icon: mdi:pause
          styles:
            card:
              - padding: 3px
              - height: 40px
              - width: 2.5rem
              - box-shadow: none
              - border: none
              - background: var(--secondary-background-color)
        - type: custom:button-card
          tap_action:
            action: call-service
            service: cover.open_cover
            service_data:
              entity_id: cover.flexispot_e7_tisch
          size: 70%
          show_state: false
          show_name: false
          show_icon: true
          icon: mdi:arrow-up
          styles:
            card:
              - padding: 3px
              - height: 40px
              - width: 2.5rem
              - box-shadow: none
              - border: none
              - background: var(--secondary-background-color)
        - type: custom:button-card
          tap_action:
            action: call-service
            service: switch.turn_on
            service_data:
              entity_id: switch.flexispot_e7_sitzen
          size: 70%
          show_state: false
          show_name: false
          show_icon: true
          icon: mdi:chair-rolling
          styles:
            card:
              - padding: 0px
              - height: 40px
              - width: 2.5rem
              - box-shadow: none
              - border: none
              - background: var(--secondary-background-color)
        - type: custom:button-card
          tap_action:
            action: call-service
            service: switch.turn_on
            service_data:
              entity_id: switch.flexispot_e7_stehen
          show_state: false
          show_name: false
          show_icon: true
          icon: mdi:human-handsup
          size: 70%
          styles:
            card:
              - padding: 0px
              - height: 100%
              - width: 2.5rem
              - box-shadow: none
              - border: none
              - background: var(--secondary-background-color)