Desky Standing Desk (ESPHome) [Works with Desky, Uplift, Jiecang, Assmann & others]

Thanks for replying back and helping me Mahko and @ssieb :slight_smile:

I have configured the D1 through ESPHome in Home Assistant, initially with the debug on GPIO3 (RX) and when I do that, basically the desk stops showing the values on the screen of the controller keyboard. Buttons work normally but there’s no display.

I’ve placed the configuration here: config rx3 4bytes debug - Pastebin.com to not overload the post I’m doing here, and the log is here: pastebin.com/aLFVua55 .

After this attempt, I went and changed the bytes from 4 to 9 on the config, everything else remained the same. Config here: pastebin . com/VCebH2dA and output here: pastebin . com/D0Rr2Nyn .

Both outputs were logged with me just pressing up or down in the controller keyboard.
This (pastebin . com/LBRYKkP7) 3rd output was from the 2nd memory slot when I pressed it until the desk stopped.

Question: Could it be that my controller is different somehow and the wiring is different as well?

PS: Can only put 2 links in a post… had to separate the pastebin from the TLD.

Couple of random thoughts. My gut feel is this will be ok but you’ve got to work through some buggy UART thing.

First step would probably be to work on getting some clean/consistent UART messages and then see if they are the same or different. You’ll need to tinker. You seem to be receiving something roughly resembling the right data, so that’s a start. As you mentioned it seems noisy.

I don’t have much depth of understanding of these things but here’s some things I would try:

  • Repeat the previous steps but power the ESP via a separate good quality power supply and USB cable (best ones you have from your phone etc).
  • Rewire your whole set-up and make sure all connections are really good. Especially the rx wires and grounds. Ground not being right can create noise.
  • Did you have a go at trying the previous steps with rx_pin: 1 #Labelled TX ?

This is how I got it working using Bluetooth, but without ESPHome or any of the goodness in this thread: Automatically raise your desk when joining a Microsoft Teams call or meeting – Loryan Strant, Microsoft 365 MVP

I’ve actually since replaced the Bluetooth-based solution with this one, and have my code up here for the various sensors and components:

1 Like

I finally got around to testing accessing the native memory presets as per a few posts above this one.

I can confirm the soft start/stop works with this, which is nice.

I might even move over to this approach as my main “go to height” method.

You only really need to connect up one more wire - the purple pne.

Presumbly this wouldn’t interfere with any other native functionality like collision detection etc too.

The Jarvis project also gives a nice overview of the control lines, which I believe are the same.

The project also has known commands for things like setting each memory slot to the current height, which I haven’t looked into and probably am not motivated enough to;)

The thread for turning your Desktronic desk into a smart desk can be found here: Turn your Desktronic standing desk into a smart desk!

1 Like

Thank you @Mahko_Mahko and @ssieb for your work.

I can confirm that this works on the (new) version of the BOHO OFFICE Basic Line desk.

I can also confirm that I could only get it working by using Pin D1 (5) on my ESP8266 D1 Mini.
I could not get it working by using Pin RXD (3).

I also got @dev0 method working (minus button 4 because it does not exist on my desk) and I plan on controlling the buttons via their method and get the current hight via @ssieb custom component.

The only thing I am still trying to figure out with @dev0 method is how I can e.g.: press the button “Up” with my mouse for a long(er) time which results in the button actually being pressed for a longer time. So that the behavior is the same as when I keep pressing down on the actual physical control panel button with my finger.


image


(image of the control box of my BOHO OFFICE Basic Line desk)

1 Like

Nice! I’ve added your desk to the “works with” list.

I don’t believe there is a way to mimic a “hold down button” action in ESPHome.

I think the best you can do is making a gpio switch for that wire/pin, which you’d to turn on while you want the desk to move and then turn off to stop it. Not the best but it works.

1 Like

Hello,
I have an issue with setting up my desk to esphome.
My esphome yaml file for testing purposes:

uart:
  - id: desk_uart
    baud_rate: 9600
    rx_pin: GPIO25  # R pin
    debug:
      after:
        timeout: 10ms
      dummy_receiver: true
      sequence:
        - lambda: UARTDebug::log_hex(UART_DIRECTION_RX, bytes, ':');
  - id: desk_uart1
    baud_rate: 9600
    rx_pin: GPIO27  # T pin
    debug:
      after:
        timeout: 10ms
      dummy_receiver: true
      sequence:
        - lambda: UARTDebug::log_hex(UART_DIRECTION_TX, bytes, ':');

Im using quin-esp32 board, and I soldered on my display controller T,R and GND wires and connected them to my esp32.
After run command, in my debug console, hexdecimal values are just running in infinite loop.
When I press some button on my display controller, I can see that these numbers are changed, but Im stuck from this point on, Im not sure what I need to do? I can see some reptetive pattern, but still Im not sure what is the correct block of hexdecimal values to extract some important inormation from it?
Any help would be apprecieted,
tnx

Hi.

What brand and model is your desk?
Is it a Jiecang controller?

Hi @Mahko_Mahko
Well, Im not sure, because I bought the desk from some local reseller.
But I have images, maybe you can find some markings and to match manufactrer:





awesome! So, can this be implemented into the ESPHome code or something like that?

that soft start/stop

Looking at that (particularly the number of wires), I’m pretty confident that this is not a Jiecang controller or a compatible desk.

The Desky component will not work. If you cannot find another matching project you will need to start your own project (and own thread).

You’ll see another would-be user had to do this here and has made great progress.

thanks for the info.

the main issue is that I can not find the reseller. maybe its easier or me to buy another desk controller, I’m not sure.

Definitely I will open a separate thread.

Apparently this is this desk controller: NT33-2B2 Sit to Stand Up Office Desk Motorized Standing Desk - Buy Sitting Desk, height adjustable desk, high adjustable desk Product on SHAOXING NAITE DRIVE TECHNOLOGY CO.,LTD

1 Like

I’m guessing… But there has been a proliferation of cheap Chinese desks (not sure if this is one?). I suspect many work very similarly.

So I would hunt around other projects and see if you can spot a similar one. Then use or adapt it.

Yes. You basically just use/adapt/add this to trigger the memory presets, which use the soft start/stop.

thanks, so that I understand this. What do I add to trigger the memory presets?

Here’s the relevant excerpt from my config. Note the Purple wire needs to connected to a GPIO.


substitutions:
  #Use your own ESP pin values
  desky_request_height_pin: GPIO32 #Request desk height | white wire  
  desky_purple_pin: GPIO04 #purple wire  
  desky_down_pin: GPIO23 #Move desk down | yellow wire  
  desky_up_pin: GPIO05  #Move desk up | green wire  

output:
  - platform: gpio
    pin: ${desky_up_pin}
    id: up_green_wire
    inverted: true
  - platform: gpio
    pin: ${desky_down_pin}
    id: down_yellow_wire
    inverted: true
  - platform: gpio
    pin: ${desky_purple_pin}
    id: purple_wire
    inverted: true

button:
  # Combination Buttons
  - platform: template
    name: 1
    id: button_1
    on_press:
      then:
        - output.turn_on: up_green_wire
        - output.turn_on: down_yellow_wire
        - delay: 300ms
        - output.turn_off: down_yellow_wire
        - output.turn_off: up_green_wire
  - platform: output
    output: purple_wire
    name: 2
    id: button_2
    duration: 300ms
  - platform: template
    name: 3
    id: button_3
    on_press:
      then:
        - output.turn_on: purple_wire
        - output.turn_on: down_yellow_wire
        - delay: 300ms
        - output.turn_off: down_yellow_wire
        - output.turn_off: purple_wire
  - platform: template
    name: 4
    id: button_4
    on_press:
      then:
        - output.turn_on: purple_wire
        - output.turn_on: up_green_wire
        - delay: 300ms
        - output.turn_off: up_green_wire
        - output.turn_off: purple_wire
    
  # - platform: template
    # name: Set memory 3
    # id: set_memory_3
    # on_press:
      # then:
        # - uart.write:
            # id: desk_uart
            # data: [0xF1, 0xF1, 0x25, 0x00, 0x25, 0x7E]
              # - uart.write: [0xF1, 0xF1, 0x25, 0x00, 0x25, 0x7E]

```

ok thanks!

So, at the moment, I have it wired as suggested above

image

I’ll have to add an extra wire from the purple pin (or slot 3 on the above figure) of the adapter and place it on any of the empty pins on the D1 Mini?

That’s right.

Pick a pin that has “ok” in both the Input and Output columns here.

Best Pins to Use – ESP8266

Awesome! Just did the addition and works very well.

I can now access my button presets and its a soft stop.

This project just keeps getting better and better. thanks again, all.

EDIT: @Mahko_Mahko one thing I’ve noticed is when the D1 board restarts, it goes to one of my presets (i.e. preset #2 in my case). My only concern with this is that on every update or even when the board restarts for whatever reason, it will go to a preset on its own. Is this an intended operation?

Here’s my entire yaml if there is something that is not right.

esphome:
  name: esphome-web-5bdf28   
  on_boot:
    priority: -100.0
    then:
    #Request a desk height update after boot.
      - delay: 5s
      - switch.turn_on: wake_desk_and_get_height

substitutions:
  #Use your own ESP pin values
  desky_request_height_pin: GPIO14 #Request desk height | white wire  
  desky_purple_pin: GPIO12 #purple wire  
  desky_down_pin: GPIO05 #Move desk down | yellow wire  
  desky_up_pin: GPIO04  #Move desk up | green wire  

output:
  - platform: gpio
    pin: ${desky_up_pin}
    id: up_green_wire
    inverted: true
  - platform: gpio
    pin: ${desky_down_pin}
    id: down_yellow_wire
    inverted: true
  - platform: gpio
    pin: ${desky_purple_pin}
    id: purple_wire
    inverted: true

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

## For Memory Sensor (debug platform in sensor)
debug:
  update_interval: 30s

sensor:
  # Sensors
  - platform: uptime
    name: "Desky Uptime"
  - platform: wifi_signal
    name: "Desky WiFi Signal"
    update_interval: 60s
  - platform: debug
    free:
      name: "Heap Free"
    fragmentation:
      name: "Heap Fragmentation"
    block:
      name: "Heap Max Block"
    loop_time:
      name: "Loop Time"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "[redacted]"
    password: "[redacted]"

captive_portal:

####################################################################################################
##Notes/Info
####################################################################################################

## Home Assistant Thread: https://community.home-assistant.io/t/desky-standing-desk/383790/3
## ssieb who generously donated his time and knowledge to developing the custom component may offer some support on the Discord thread (please read both threads first).
## https://discord.com/channels/429907082951524364/952464939480645642

#Notes:
# 1. Use this component at own risk. It has not had extensive testing. May void warranty or cause desk faults etc.
# 2. This controller may bypass desk safety features like collision detection.
# 3. This component doesn't know about the values stored in your desk. Values in this config are (and must be) set independently.
# 4. ssieb's solution may be a lot simpler and cleaner for most people. I've cobbled together some more features in this config because I can't programn in C++.


#Troubleshooting Tips: 
#If you ever get a flashing ASr message, you might need to reset your desk.
#https://desky.com.au/blogs/news/reset-standing-desk-control-panel#:~:text=When%20ready%2C%20press%20and%20hold,Hooray!


#TODO 
#Ask ssieb to make change requests (move logic to component code)
  # Invert pins
  # Get Desk Height On Boot
  # Interlock Up/Down Pins (If not done already)
  # Interrupt/stop movement function (Stop desk motion)

#other
  # Test collision detection
  # Limit external component fetch to just desky? 
  # Fix Desk Is moving on Boot.

external_components:
#Fetch ssieb's custom component# https://github.com/ssieb/custom_components/tree/master/components/desky
  - source:
      type: git
      url: https://github.com/ssieb/custom_components
    components: [ desky ]

uart:
  - id: desk_uart
    baud_rate: 9600
    rx_pin: 1 #Labelled TX on my D1mini clone (mislabelled?)
    ##You can uncomment the debug section below to see UART messages.
    # debug:
      # direction: RX
      # dummy_receiver: true
      # after:
        # bytes: 4
      # sequence:     
        # - lambda: UARTDebug::log_int(direction, bytes, ',');
 
desky:
  id: my_desky
  ####################################################################################
  ##Uncomment this block to use Ssieb's move_to componet function.
  # up:    
    # number: 4 #D2
    # inverted: true 
  # down:  
    # number: 5 #D1
    # inverted: true
  # stopping_distance: 15  # optional distance from target to turn off moving, default 15  
  ####################################################################################
  height:  # Sensor publishing the current height
    name: Desky Height
    id: desky_height
    accuracy_decimals: 1
    unit_of_measurement: cm
    #any other sensor options
    filters:
    - delta: 0.05 #Only send values to HA if they change
    - throttle: 200ms #Limit values sent to Ha to 5 per sec.
    - multiply: 0.1 #convert from mm to cm
    on_value:
      then:
          #If the value changes, then the desk is moving
        - binary_sensor.template.publish:
            id: desky_is_moving
            state: ON
        - delay: 300ms
          #Assume it's stopped moving if no height changes after a short time.
        - binary_sensor.template.publish:
            id: desky_is_moving
            state: Off
            
binary_sensor:
  - platform: template
    id: desky_is_moving
    name: "Desky Is Moving"
    filters:
      - delayed_off: 400ms
    #If the desk isn't moving for a bit we better turn off attempts at movement. It's like poor man's collision detection? 
    on_release:
      then:
        - button.press: desky_stop_desk

button: 
#Stop movement 
  - platform: template
    name: Stop Desk
    id: desky_stop_desk
    on_press:
      then:
        - switch.turn_off: raise_desk
        - switch.turn_off: lower_desk
# Combination Buttons
  - platform: template
    name: Desky Button 1
    id: button_1
    on_press:
      then:
        - output.turn_on: up_green_wire
        - output.turn_on: down_yellow_wire
        - delay: 300ms
        - output.turn_off: down_yellow_wire
        - output.turn_off: up_green_wire
  - platform: output
    output: purple_wire
    name: Desky Button 2
    id: button_2
    duration: 300ms
  - platform: template
    name: Desky Button 3
    id: button_3
    on_press:
      then:
        - output.turn_on: purple_wire
        - output.turn_on: down_yellow_wire
        - delay: 300ms
        - output.turn_off: down_yellow_wire
        - output.turn_off: purple_wire
  - platform: template
    name: Desky Button 4
    id: button_4
    on_press:
      then:
        - output.turn_on: purple_wire
        - output.turn_on: up_green_wire
        - delay: 300ms
        - output.turn_off: up_green_wire
        - output.turn_off: purple_wire

#Move to function
  - platform: template
    name: Go To Desky Height x
    id: go_to_desky_preset_height_x
    on_press:
      then:
      ##Option 1: Uncomment to use Ssieb's move_to componet functions
        # - lambda: id(my_desky).move_to(id(desky_target_height).state*10);  

        
      ##Option 2: Uncomment to use Mahko's lambda alternative 
      #Check if we need to move desk up or down from current position      
        if:
          condition:
          #Current height is more than target height, then move desk down
            lambda: |-
              return id(desky_target_height).state < id(desky_height).state;
          then:
            - switch.turn_on: lower_desk
            - wait_until:
              #Run until the difference between current and target state is < stopping distance 
                condition:
                  lambda: return abs((id(desky_height).state - (id(desky_target_height).state)))<(id(stopping_distance_cm).state);
            - switch.turn_off: lower_desk
          else:
          #Current height is less than target height, move desk up
            - switch.turn_on: raise_desk
            - wait_until:
                condition:
                  lambda: return abs((id(desky_height).state - (id(desky_target_height).state)))<(id(stopping_distance_cm).state);
                  #Run until the difference between current and target state is <0.3cm
            - switch.turn_off: raise_desk


number:
#Target Height ("Move desk to height x").
    #You should probably limit the range you can move the desk to to within the limits you've set via the control panel, perhaps offset a little within the range.
    #Sending commands higher/lower than this may cause error messages and require desk reset (or worse).
  - platform: template
    id: desky_target_height
    name: "Desky Target Height"
    optimistic: true
    unit_of_measurement: cm
    min_value: 65.0 
    max_value: 122.0
    step: 0.1
    
#Offset correction - Adjust until you get the best accuracy. 
#The desk keeps moving for a little while after the up/down pins are released and we try to account for this.
#1.5cm was about right on mine
  - platform: template
    name: "Desky Stopping Distance cm"
    id: stopping_distance_cm
    unit_of_measurement: cm
    optimistic: true
    min_value: 0
    max_value: 2
    step: 0.1
    restore_value: true
    initial_value: 1.5
    
###############################################
#Define some preset heights.
###############################################
#You can freely define as many adjustable presets as you like.
#These are all seperate/independant of what you've set via the control panel (we can't retrieve them currently).
 
#Standing Height #1 - Set a standing height. 
  - platform: template
    id: desky_standing_height_1
    name: "Standing Height 1"
    optimistic: true
    unit_of_measurement: cm
    #Limit the range
    min_value: 110
    max_value: 120
    step: 0.1
    restore_value: true
    initial_value: 115

#Standing Height #1 - Set a standing height. 
  - platform: template
    id: desky_standing_height_2
    name: "Standing Height 2"
    optimistic: true
    unit_of_measurement: cm
    #Limit the range
    min_value: 115
    max_value: 125
    step: 0.1
    restore_value: true
    initial_value: 120
  
#Sitting Height #1 - Set a sitting height. This is independant of what you've set via the control panel.
  - platform: template
    id: desky_sitting_height_1
    name: "Sitting Height 1"
    optimistic: true
    unit_of_measurement: cm
    #Limit the range
    min_value: 65
    max_value: 69
    step: 0.1
    restore_value: true
    initial_value: 67.0

#Sitting Height #2 - Set a sitting height. This is independant of what you've set via the control panel.
  - platform: template
    id: desky_sitting_height_2
    name: "Sitting Height 2"
    optimistic: true
    unit_of_measurement: cm
    #Limit the range
    min_value: 72.6
    max_value: 82.6
    step: 0.1
    restore_value: true
    initial_value: 77.6
      
switch:
#wake up ther desk and request it sends its height 
  - platform: gpio
    id: wake_desk_and_get_height
    name: "Request Desk Height"
    pin:
      number: D5
      inverted: true
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: wake_desk_and_get_height
  - platform: restart
    name: "Desky Restart"

#Raise the desk 
  - platform: gpio
    id: raise_desk
    name: "Raise Desk"
    pin:
      number: D2
      # mode: INPUT_PULLUP
      inverted: true
    interlock: lower_desk
    on_turn_on:
    #Auto off after 15s just in case
    - delay: 15s
    - switch.turn_off: raise_desk
#Lower the desk 
  - platform: gpio
    id: lower_desk
    name: "Lower Desk" 
    pin:
      number: D1
      # mode: INPUT_PULLUP
      inverted: true
    interlock: raise_desk
    on_turn_on:
   #Auto off after 15s just in case
    - delay: 15s
    - switch.turn_off: lower_desk