Skip to content

Instantly share code, notes, and snippets.

@iMicknl

iMicknl/v2.yaml Secret

Created December 18, 2021 23:11
Show Gist options
  • Save iMicknl/2890d738ede31947b81fb33b8951c242 to your computer and use it in GitHub Desktop.
Save iMicknl/2890d738ede31947b81fb33b8951c242 to your computer and use it in GitHub Desktop.
substitutions:
device_name: Flexispot EK5
name: flexispot-ek5
min_height: "73.6" # Min height + 0.1
max_height: "122.9" # Max height - 0.1
esphome:
name: ${name}
comment: ${device_name}
platform: ESP8266 # TODO Change to your platform
board: nodemcuv2 # TODO Change to your board
includes:
- desk_height_sensor.h
project:
name: "imicknl.loctekmotion_iot"
version: "1.0.0"
# Wake Desk by sending the "M" command
# This will pull the current height after boot
on_boot:
priority: -10
then:
- button.press: button_m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name} Hotspot"
password: !secret ap_fallback_password
captive_portal:
# Enable logging
logger:
level: DEBUG
# level: VERBOSE # Makes uart stream available in esphome logstream
baud_rate: 0 # Disable logging over uart
# Enable Home Assistant API
api:
password: !secret ha_api_password
ota:
password: !secret ha_api_password
uart:
id: desk_uart
baud_rate: 9600
tx_pin: D5
rx_pin: D6
sensor:
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
- platform: uptime
name: Uptime
- 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: Desk Height
unit_of_measurement: cm
accuracy_decimals: 1
icon: "mdi:counter"
state_class: "measurement"
on_value:
then:
- cover.template.publish:
id: desk_cover
position: !lambda |-
// The sensor outputs values from min_height (cm) to max_height (cm)
// We need to translate this to 0 - 1 scale.
float position = (float(x) - float(${min_height})) / (float(${max_height}) - float(${min_height}));
ESP_LOGD("main", "X is %f", x);
ESP_LOGD("main", "Current position is %f", position);
return position;
switch:
# PIN20
- platform: gpio
name: "Virtual Screen"
pin:
number: D2
mode: OUTPUT
restore_mode: ALWAYS_ON
entity_category: "config"
internal: true
- platform: uart
name: "Up"
id: switch_up2
icon: mdi:arrow-up-bold
data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d]
uart_id: desk_uart
send_every: 108ms
- platform: uart
name: "Down"
id: switch_down2
icon: mdi:arrow-down-bold
data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d]
uart_id: desk_uart
send_every: 108ms
button:
- platform: template
name: "Preset 1"
icon: mdi:numeric-1-box
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d]
- platform: template
name: "Preset 2"
icon: mdi:numeric-2-box
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d]
- platform: template
name: "Sit" # Preset 3 on some control panels
icon: mdi:chair-rolling
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x00, 0x01, 0xac, 0x60, 0x9d]
- platform: template
name: "Stand"
icon: mdi:human-handsup
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d]
- platform: template
name: "Memory"
id: button_m
icon: mdi:alpha-m-box
entity_category: "config"
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d]
- platform: template
name: "Wake Screen"
id: button_wake_screen
icon: mdi:gesture-tap-button
entity_category: "config"
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d]
- platform: template
name: "Alarm"
id: button_alarm
icon: mdi:alarm
on_press:
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x40, 0x00, 0xAC, 0x90, 0x9d]
- platform: restart
name: "Restart"
entity_category: "config"
cover:
- platform: template
id: "desk_cover"
icon: mdi:desk # or mdi:human-male-height-variant
name: "Desk"
device_class: blind # makes it easier to integrate with Google/Alexa
has_position: true
position_action:
- logger.log: "Requesting action change"
# Move desk up
open_action:
- while:
condition:
sensor.in_range:
id: desk_height
below: ${max_height}
then:
- logger.log: "Executing up command"
- cover.template.publish:
id: desk_cover
current_operation: OPENING
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d]
- delay: 108ms
# Move desk down
close_action:
- while:
condition:
sensor.in_range:
id: desk_height
above: ${min_height}
then:
- logger.log: "Executing down command"
- cover.template.publish:
id: desk_cover
current_operation: CLOSING
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d]
- delay: 108ms
optimistic: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment