Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAnalogGuy authored Mar 14, 2023
1 parent c991ee0 commit f8e65d1
Showing 1 changed file with 172 additions and 0 deletions.
172 changes: 172 additions & 0 deletions esphome/megadesk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
esphome:
name: megadesk
comment: ESPHome Device controlling Megadesk controller
platform: ESP8266
# details on how to find/select your board can be found at https://esphome.io/components/esp8266.html
board: d1_mini
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."

logger:
baud_rate: 0

api:
password: ""

ota:
password: ""

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

ap:
ssid: "Desk Fallback Hotspot"
password: "xxxxxxxxxx"

captive_portal:

web_server:
port: 80

uart:
id: uart_desk
baud_rate: 115200
tx_pin: D0
rx_pin: D1

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
- 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);"
- 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);"
- 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() );
button:
- platform: template
name: "Desk Position 2"
on_press:
then:
- uart.write: "<L0,2."
- platform: template
name: "Desk Position 3"
on_press:
then:
- uart.write: "<L0,3."
- platform: template
name: "Desk Position 4"
on_press:
then:
- uart.write: "<L0,4."
- platform: template
name: "Desk Position 5"
on_press:
then:
- uart.write: "<L0,5."
- 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."

0 comments on commit f8e65d1

Please sign in to comment.