{"id":13624660,"url":"https://github.com/grssmnn/ha-flexispot-standing-desk","last_synced_at":"2025-04-16T00:32:51.926Z","repository":{"id":52718637,"uuid":"334742914","full_name":"grssmnn/ha-flexispot-standing-desk","owner":"grssmnn","description":"Home Assistant integration for a standing desk by Flexispot in micropython","archived":false,"fork":false,"pushed_at":"2021-02-13T14:55:21.000Z","size":17,"stargazers_count":66,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-01T22:01:51.549Z","etag":null,"topics":["esp32","hassio","homeassistant","micropython"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grssmnn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-31T19:49:52.000Z","updated_at":"2024-07-27T14:23:35.000Z","dependencies_parsed_at":"2022-08-22T13:01:28.361Z","dependency_job_id":null,"html_url":"https://github.com/grssmnn/ha-flexispot-standing-desk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grssmnn%2Fha-flexispot-standing-desk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grssmnn%2Fha-flexispot-standing-desk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grssmnn%2Fha-flexispot-standing-desk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grssmnn%2Fha-flexispot-standing-desk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grssmnn","download_url":"https://codeload.github.com/grssmnn/ha-flexispot-standing-desk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223691707,"owners_count":17186868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp32","hassio","homeassistant","micropython"],"created_at":"2024-08-01T21:01:44.768Z","updated_at":"2024-11-08T13:30:55.556Z","avatar_url":"https://github.com/grssmnn.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# HA Flexispot Standing Desk\n\nThis is an integration of a standing desk from Flexispot into home assistant in micropython. The height can be read out from the desk's controller and it gets pushed to Home Assistant via MQTT. I guess it should be quite simple to adapt this to any other (smarthome) system. I've also implemented remote controlling the desk via MQTT (see Control section).\n\nThe desk controller has two RJ45 ports, one is used by the default remote of the table and the other one is unused. Both can be used to control the desk. \n\n## Usage and installation\nI took an ESP32 and an old ethernet cable, cut it and soldered dupont wires with a female end to the Pins 4, 5, 6, 7 and 8. On the pin assignment table below you can have a look which ports to use on the ESP32.\n\nInstallation of Micropython on ESP32 is explained on this site: http://docs.micropython.org/en/latest/esp32/tutorial/intro.html#esp32-intro\n\nFor uploading the files I used [ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy).\n\n## Control\nIf you want to control your desk remotely, make sure to call the function `listen_mqtt()` after initializing the Flexispot Class:\n```python\n# main.py\nimport machine\nimport flexispot\n\ndef main():\n    f = flexispot.ControlPanel(publish_discovery=False, debug=True)\n    f.listen_mqtt()\n       \nif __name__ == '__main__':\n    main()\n```\nThe possible commands are just like the buttons on your normal external control panel:\n```\nup\ndown\npos1\npos2\npos3\nm\n```\n\nSend the command as plain text like `pos1` via MQTT to the command topic (default: `homeassistant/sensor/standingdesk/set`).\n\n## Home Assistant `configuration.xaml`\nThese are my custom sensors I've added to my `configuration.yaml`:\n\n```yaml\n# configuration.xaml\nmqtt:\n    broker: \u003cMQTT Broker\u003e\n    discovery: true\n\nbinary_sensor:\n  - platform: template\n    sensors:\n      standing_at_desk:\n        friendly_name: \"Standing at desk\"\n        value_template: \u003e-\n            {{states('sensor.standingdesk')|float \u003e 100}}\n\nsensor:\n  - platform: history_stats\n    sensors:\n      standing_today:\n        name: Standing today\n        entity_id: binary_sensor.standing_at_desk\n        state: \"on\"\n        type: time\n        start: '{{ now().replace(hour=0, minute=0, second=0) }}'\n        end: '{{ now() }}'\n```\n\nThe binary sensor `standing_at_desk` switches to `on` if the reported height of the desk is higher than 100cm. This is the indicator that I'm standing right now. The sensor `standing_today` counts how long I was standing for today.\n\n## PIN Assignment\nThanks to [stan](https://www.mikrocontroller.net/user/show/stan) from this [topic](https://www.mikrocontroller.net/topic/493524). \n\n| PIN | Color  | Description                                                     |Port on ESP32|\n|-----|--------|-----------------------------------------------------------------|-------------|\n| 1   | brown  | Reset of µC                                                     |             |\n| 2   | white  | SWIN of µC                                                      |             |\n| 3   | purple | unused                                                          |             |\n| 4   | red    | needs to be set to `HIGH` if you want to talk to the controller |D18          |\n| 5   | green  | RX (of remote)                                                  |RX2          |\n| 6   | black  | TX (of remote)                                                  |TX2          |\n| 7   | blue   | GND                                                             |GND          |\n| 8   | yellow | VDD (5V)                                                        |VIN          |\n\n## Protocol\nAgain thanks [stan](https://www.mikrocontroller.net/user/show/stan) and _minifloat_ from this [topic](https://www.mikrocontroller.net/topic/493524). \n\nEach message starts with `0x9b` and ends with `0x9d`. The second byte is the message's length and the third one is the message identifier. The last two bytes before message end `0x9d` is a 16bit Modbus-CRC16 Checksum.\n\n| 0    | 1    | 2    | 3    | 4    | 5    | 6    | 7    | Direction   | Command           |\n|------|------|------|------|------|------|------|------|-------------|-------------------|\n| `9b` | `06` | `02` | `00` | `00` | `6c` | `a1` |      | `Tx`        | no button pressed |\n| `9b` | `06` | `02` | `01` | `00` | `fc` | `a0` |      | `Tx`        | up                |\n| `9b` | `06` | `02` | `02` | `00` | `0c` | `a0` |      | `Tx`        | down              |\n| `9b` | `06` | `02` | `04` | `00` | `ac` | `a3` |      | `Tx`        | Pos. 1            |\n| `9b` | `06` | `02` | `08` | `00` | `ac` | `a6` |      | `Tx`        | Pos. 2            |\n| `9b` | `06` | `02` | `10` | `00` | `ac` | `ac` |      | `Tx`        | Pos. 3            |\n| `9b` | `06` | `02` | `20` | `00` | `ac` | `b8` |      | `Tx`        | M                 |\n| `9b` | `07` | `12` | `xx` | `xx` | `yy` | `yy` | `9b` | `Rx`        | Height            |\ntbc\n\n### Height\nIf you want to query the height you have to send the \"no button pressed\"-command first. After that the controller will transmit the encoded height.\n\nMessage Identifier for the height reported by the controller is `0x12` with three bytes of payload. Every byte represents a digit on the display, every bit of each byte represents one segment of a seven segments display. See method `decode_digit(b)` or following image:\n\n```\n  0 0 0\n5       1\n5       1\n5       1\n  6 6 6\n4       2\n4       2\n4       2\n  3 3 3    77\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrssmnn%2Fha-flexispot-standing-desk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrssmnn%2Fha-flexispot-standing-desk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrssmnn%2Fha-flexispot-standing-desk/lists"}