gcormier / megadesk

Open-source IKEA Bekant controller board
GNU General Public License v3.0
717 stars 53 forks source link

megadesk-companion.yaml trying to add buttons to trigger right memory slots #154

Closed pokdeep closed 6 months ago

pokdeep commented 7 months ago

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 ```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: "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( 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( s.begin(), s.end() ); button: - platform: template name: "up position 2" on_press: then: - uart.write: "