loctekmotion-iot

repository·main·Indexed 21 days ago

https://github.com/imicknl/loctekmotion_iot

An ESPHome project to integrate LoctekMotion and FlexiSpot standing desks into Home Assistant using ESP32 or ESP8266 hardware. It enables desk control (up, down, stop), management of 4 presets, and height monitoring via the desk's RJ45 serial ports. The project provides configurations for standard RJ45 serial connections and pass-through setups for desks with a single port, including detailed pinout mappings for HS13B-1, HS13A-1, and HS01B-1 control panels.

Tokens
2.4K
Snippets
4
Records
9
Agent score
26%

What's inside loctekmotion-iot

  1. Overview of LoctekMotion/FlexiSpot Smart Desk Integration

    main

    This project enables turning LoctekMotion or FlexiSpot standing desks into smart devices by connecting them to Home Assistant via serial communication through the RJ45 ports.

    Key Features:

    • Control: Move the desk (up, down, stop) using a cover entity.
    • Presets: Manage 4 desk presets using button entities.
    • Monitoring: Track current desk height via a sensor entity.
    • Height Adjustment: Adjust height in cm using a number entity (experimental; note that this may overshoot due to reporting delays).
  2. Retrieve current desk height

    main

    The control box communicates height data using a 4-bit hexadecimal format, which is then decoded by the control panel to drive a 7-segment display.

    Requirements:

    • Baud Rate: Must be set to 9600.
    • Wake Up: The control box typically only broadcasts the current height for a few seconds after you send the Wake Up command. If you do not send this command, you will likely receive 0x00 0x00 0x00 as the payload.
  3. Troubleshoot Height Sensor Issues

    main

    If the height sensor is providing incorrect values or the cover entity buttons (up/down) are grayed out:

    1. Debug UART: Uncomment the debug line for UART in your ESPHome configuration to view raw data from the desk controller. Refer to ESPHome UART debugging.
    2. Fix Grayed Out Buttons: If the height sensor issues prevent the up/down buttons from working, change the internal parameter for the up/down switch from true to false in your YAML configuration.
  4. Available ESPHome Packages

    main

    The project provides two primary ESPHome configurations depending on your desk's hardware:

    1. Standard ESPHome (packages/office-desk-esp32.yaml): For desks with an available RJ45 serial port. Designed for ESP32 NodeMCU but adaptable to ESP8266 or other ESP32 variants.
    2. ESPHome Pass-through (packages/office-desk-esp32-passthrough.yaml): For desks that only have a single RJ45 port. This allows the ESP32 to sit between the controller and the keypad.
  5. Identify the RJ45 pinout for LoctekMotion control panels

    main

    To connect a LoctekMotion/FlexiSpot control box to a microcontroller (like Raspberry Pi or ESP32), you must map the RJ45 pins correctly. While multiple mappings exist, the HS13B-1 pinout is the most common and often works for all panels.

    Hardware Connection Tip: Use an RJ45 to RS232 adapter with DuPont cables, or manually split an Ethernet cable. Note that RX and TX are defined from the receiver (control panel) side; your custom controller should use RX to receive and TX to send.

    #### HS13B-1 (Most Common)
    | RJ45 pin | Name      | Original Cable Color | Ethernet cable color (T568B) |
    | -------- | --------- | -------------------- | ---------------------------- |
    | 1        | RESET     | Brown                | White-Orange                 |
    | 2        | SWIM      | White                | Orange                       |
    | 3        | EMPTY     | Purple               | White-Green                  |
    | 4        | PIN 20    | Red                  | Blue                         |
    | 5        | RX        | Green                | White-Blue                   |
    | 6        | TX        | Black                | Green                        |
    | 7        | GND       | Blue                 | White-Brown                  |
    | 8        | +5V (VDD) | Yellow               | Brown                        |
  6. Standard ESP32 Pin-out for RJ45 Serial Connection

    main

    Use this pin-out to connect an ESP32 to the desk controller's RJ45 port. This configuration is compatible with control panels featuring an RJ45 port for serial communication.

    | RJ45 pin | Name      | ESP32        |
    | -------- | --------- | ------------ |
    | 8        | +5V (VDD) | VIN          |
    | 7        | GND       | GND          |
    | 6        | TX        | TX2 (GPIO17) |
    | 5        | RX        | RX2 (GPIO16) |
    | 4        | PIN 20    | D23 (GPIO23) |
    | 3        | (unknown) |              |
    | 2        | SWIM      |              |
    | 1        | RES       |              |
  7. Pinout for HS13A-1 and HS01B-1 control panels

    main

    If the standard HS13B-1 pinout does not work, check the specific mapping for your model below.

    HS13A-1 (Flexispot EK5 / CB38M2B(IB)-1):

    RJ45 pinNameOriginal Cable ColorEthernet cable color (T568B)
    1RESET SWIMBrownWhite-Orange
    2PIN 20WhiteOrange
    3RXPurpleWhite-Green
    4TXRedBlue
    5GND1GreenWhite-Blue
    6+5V (VDD)BlackGreen
    729V+BlueWhite-Brown
    829V-YellowBrown

    HS01B-1 (Flexispot E5B / CB38M2A-1):

    RJ45 pinName
    8+5V (VDD)
    7GND
    6TX
    5RX
    4PIN 20
    3(unknown)
    2SWIM
    1RES
  8. Execute commands to the LoctekMotion control box

    main

    The control box only accepts commands when the 'screen is active'.

    Activating the Screen: To activate the screen, you must set PIN 20 to HIGH for approximately 1 second. The screen will automatically disable itself after a period of inactivity.

    Command Protocol: Commands follow a specific structure: Start | Length | Type | Payload | Checksum | End. All bytes must be combined into a single sequence to be sent to the control box.

    | Command name     | Start | Length | Type | Payload   | Checksum  | End  |
    | ---------------- | ----- | ------ | ---- | --------- | --------- | ---- |
    | Wake Up          | `9b`  | `06`   | `02` | `00` `00` | `6c` `a1` | `9d` |
    | Up               | `9b`  | `06`   | `02` | `01` `00` | `fc` `a0` | `9d` |
    | Down             | `9b`  | `06`   | `02` | `02` `00` | `0c` `a0` | `9d` |
    | M                | `9b`  | `06`   | `02` | `20` `00` | `ac` `b8` | `9d` |
    | Preset 1         | `9b`  | `06`   | `02` | `04` `00` | `ac` `a3` | `9d` |
    | Preset 2         | `9b`  | `06`   | `02` | `08` `00` | `ac` `a6` | `9d` |
    | Preset 3 (stand) | `9b`  | `06`   | `02` | `10` `00` | `ac` `ac` | `9d` |
    | Preset 4 (sit)   | `9b`  | `06`   | `02` | `00` `01` | `ac` `60` | `9d` |
  9. Pass-Through Pin-out for Single RJ45 Port Desks

    main

    If your desk controller lacks an extra RJ45 port, use the pass-through configuration. You must connect the keypad's RJ45 to the ESP32 using the following mapping.

    Note: Pins marked 'Split' must be connected to the ESP32, the desk controller, AND the keypad. Pins marked 'Pass-Through' connect the controller directly to the keypad. The current implementation does not utilize PIN20.

    | KeyPad RJ45 pin | Name      | Connection |
    | --------------- | --------- | ----------- |
    | 8               | +5V (VDD) | VIN (Split) |
    | 7               | GND       | GND (Split) |
    | 6               | TX        | RX0 (GPIO3) |
    | 5               | RX        | RX2 (Split) |
    | 4               | PIN 20    | (Not Required) |
    | 3               | (unknown) | (Not Required) |
    | 2               | SWIM      | (Pass-Through) |
    | 1               | RES       | (Pass-Through) |