megadesk-companion.yaml trying to add buttons to trigger right memory slots
pokdeep opened this issue · comments
Awesome devices you've created!
I'm a complete novice in esphome but looking at the layout of the yaml I thought recalling the right memory positions would be as simple as
- platform: template
name: "down position 2"
on_press:
then:
- uart.write: "<R0,2."
but the desk doesn't move, I can see a log entry for the button press
11:29:43 | [D] | [button:010] | 'down position 2' Pressed.
my megadesk-companion.yaml
# If you get errors compiling this with esphome, make sure you are on a recent version.
# 'esphome version' will output the version you are on.
#
# If you want to compile in the Home Assistant esphome addon, you need to copy megadesk.h into your esphome folder
# on your Home Assistant platform.
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
version: recommended
esphome:
name: megadesk
comment: megadesk-companion
platformio_options:
board_build.flash_mode: dio # If you don't specify this using esp-idf framework, the device will boot-loop.
includes:
- megadesk.h
on_boot:
priority: -100
then:
- delay: 1s
- uart.write: "<C0.0."
- delay: 1s
- uart.write: "<R0.11."
- delay: 1s
- uart.write: "<R0.12."
#####
# You need to make sure tx_pin and rx_pin are set properly for your device.
# For 5-pin Megadesks, this will not need changing.
#
# If you have a 3-pin megadesk, try swapping them in case of a mixup on RX/TX
# when you soldered the wires.
#####
uart:
id: uart_desk
baud_rate: 115200
tx_pin: GPIO6
rx_pin: GPIO7
logger:
hardware_uart: USB_SERIAL_JTAG # Logging over the USB-C port (WiFi will always log as well)
api:
password: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Companion Fallback"
password: "megadesk"
captive_portal:
web_server:
port: 80
sensor:
- platform: custom
lambda: |-
auto megadesk = new Megadesk(id(uart_desk));
App.register_component(megadesk);
return { megadesk->raw_height, megadesk->min_height, megadesk->max_height };
sensors:
- id: megadesk_raw
internal: true
on_value:
then:
- component.update: megadesk_height_inches
- component.update: megadesk_height_cm
- component.update: megadesk_height_raw
- component.update: megadesk_height_box
- name: "Megadesk Minimum Height"
- name: "Megadesk Maximum Height"
number:
- platform: template
name: "Megadesk Height (inches)"
id: megadesk_height_inches
min_value: 23
max_value: 47
step: 0.53
mode: slider
update_interval: never
unit_of_measurement: 'inches'
#NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
lambda: |-
return ((((id(megadesk_raw).state - 299) * (47 - 23)) / (6914 - 299)) + 23);
set_action:
- number.set:
id: megadesk_height_raw
value: !lambda "return int((((x - 23) * (6914 - 299)) / (47 - 23)) + 299);"
- number.set:
id: megadesk_height_box
value: !lambda "return int((((x - 23) * (6914 - 299)) / (47 - 23)) + 299);"
- platform: template
name: "Megadesk Height (cm)"
id: megadesk_height_cm
min_value: 58.42
max_value: 118.745
step: 0.53
mode: slider
update_interval: never
unit_of_measurement: 'cm'
#NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
lambda: |-
return ((((id(megadesk_raw).state - 299) * (119.38 - 58.42)) / (6914 - 299)) + 58.42);
set_action:
- number.set:
id: megadesk_height_raw
value: !lambda "return int((((x - 58.42) * (6640 - 299)) / (119.38 - 58.42)) + 299);"
- number.set:
id: megadesk_height_box
value: !lambda "return int((((x - 58.42) * (6640 - 299)) / (119.38 - 58.42)) + 299);"
- platform: template
name: "Megadesk Height (raw)"
id: megadesk_height_raw
# internal: true
min_value: 299
max_value: 6640
step: 1
mode: slider
update_interval: never
lambda: |-
return id(megadesk_raw).state;
set_action:
- uart.write: !lambda |-
char buf[20];
sprintf(buf, "<=%i,.", int(x));
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
- platform: template
name: "Megadesk Height box"
id: megadesk_height_box
# internal: true
min_value: 299
max_value: 6640
step: 1
mode: box
update_interval: never
lambda: |-
return id(megadesk_raw).state;
set_action:
- uart.write: !lambda |-
char buf[20];
sprintf(buf, "<=%i,.", int(x));
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
button:
- platform: template
name: "up position 2"
on_press:
then:
- uart.write: "<L0,2."
- platform: template
name: "down position 2"
on_press:
then:
- uart.write: "<R0,2."
- platform: template
name: "up position 3"
on_press:
then:
- uart.write: "<L0,3."
- platform: template
name: "down position 3"
on_press:
then:
- uart.write: "<R0,3."
- platform: template
name: "up position 4"
on_press:
then:
- uart.write: "<L0,4."
- platform: template
name: "down position 4"
on_press:
then:
- uart.write: "<R0,4."
- platform: template
name: "Toggle Minimum Desk Height"
on_press:
then:
- uart.write: "<L0,11."
- uart.write: "<R0,11."
- platform: template
name: "Toggle Maximum Desk Height"
on_press:
then:
- uart.write: "<L0,12."
- uart.write: "<R0,12."
- platform: template
name: "Recalibrate Desk"
on_press:
then:
- uart.write: "<L0,14."
- platform: template
name: "Reboot Megadesk"
on_press:
then:
- uart.write: "<L0,15."
- platform: template
name: "Toggle Audio feedback"
on_press:
then:
- uart.write: "<L0,17."
- platform: template
name: "Toggle both-button mode"
on_press:
then:
- uart.write: "<L0,18."
interval:
- interval: 300s
then:
- uart.write: "<C0.0."