LoctekMotion_IoT icon indicating copy to clipboard operation
LoctekMotion_IoT copied to clipboard

[Testers wanted] New ESPHome configuration and documentation improvements

Open iMicknl opened this issue 1 year ago • 67 comments

I am working on improving this repository. The main goal is to make it easier to get started, by providing only two configurations and a more updated README + configuration. In order to achieve this, all feedback and contributions are welcome.

Main goal:

  • [ ] Only provide 2 options and pin-outs (LoctekMotion Desk and LoctekMotion Desk with pass through)
  • [ ] Advise to use ESP32 due to 5V tolerance and hardware UART, add note about ESP8266 with voltage shifter (5V -> 3.3V).
  • [ ] Simplify the README and installation instructions (add a version for non technical people, 'plug and play')
  • [ ] Add system diagrams explaining the wiring
  • [x] Modernize YAML config with cover, buttons and number entity
  • [x] Remove the need for desk_height_sensor.h (load from custom component)
  • [ ] Simplify and improve docs (e.g. add https://esphome.io/guides/getting_started_hassio.html)

Long term:

  • [ ] Use ESPWebtools (https://esphome.github.io/esp-web-tools/) to make it easier to get started

Changes

  • Switch will turn off automatically when min or max height is reached
  • New cover entity
  • New number entity (still buggy)
  • Presets are exposed as button entities
  • Experimental buttons for alarm / alarm off
image image

Pin-out

In the past we have discussed multiple pin-outs, but it seems that multiple pin-outs can be supported by the same desk.

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

You can change the ESP32 pin-out mapping, but don't forget to change the pin number in the YAML.

esp32-flexispot My setup, no soldering required.

Configuration

office-desk-esp32.yaml

The following secrets should be part of your ESPHome config: encryption_key, wifi_ssid and wifi_password.

Feedback

Any feedback and contributions are welcome! For example the work above adopted for pass through configurations.

iMicknl avatar Oct 01 '23 19:10 iMicknl

Hey @iMicknl,

thanks for providing this updated version of the code. The improvements look really good. First observations:

  • You have mixed up preset 3 and 4 in the comments. On my device this is Button 4: https://github.com/iMicknl/LoctekMotion_IoT/blob/6303fa7d10fc1cc102740a4a41e9dff448cd5c42/packages/office-desk.yaml#L158
  • On my specific device the wake screen command and the PIN20 method do not work, however, "child lock" (which seems not supported) wakes up the device (and produces the current desk height) - so thank you!
  • update_interval: 0ms # update in every loop() iteration in number "Desk Height" does what you intended, but is that really necessary?
  • You've used the name "Desk Height" twice. Yes not a technical issue, more of an intuitive ick
  • First testing results: All combinations of Up/Down, Cover and Button commands seem to work and I couldn't get them to collide. Very big improvement to before!
  • A preset button will send the desk on its way. This can be stopped by e.g. shortly pressing the Up or Down button. Could you add a "Stop" button?
  • A binary_sensor that indicates that the desk is currently moving would be great

General comment: It seems like more and more devices will be potentially supported by your project, and each will have their own caveats. My HCB223A-1 seems to be a good example. Should we capture those differences in a table of sorts?

ThomDietrich avatar Oct 06 '23 22:10 ThomDietrich

Thanks a lot for your extensive feedback, @ThomDietrich!

On my specific device the wake screen command and the PIN20 method do not work, however, "child lock" (which seems not supported) wakes up the device (and produces the current desk height) - so thank you!

The wake command does not work here as well. What do you mean with PIN20 doesn't work? PIN20 is set to ALWAYS_ON (high) to allow the ESP32 to control the desk.

update_interval: 0ms # update in every loop() iteration in number "Desk Height" does what you intended, but is that really necessary?

This floods the log indeed, and I need to have a better look here. It needs to be at least 0.5s, in order for the number template to be updated with the height of the desk height sensor.

A preset button will send the desk on its way. This can be stopped by e.g. shortly pressing the Up or Down button. Could you add a "Stop" button?

Good one! Perhaps we could make the cover.stop button behave like this. I am not sure how often you want to cancel a preset command?

A binary_sensor that indicates that the desk is currently moving would be great

In theory the cover entity should have such a status already. We need to have a look if this is currently missing and if so, if this could be added.

You've used the name "Desk Height" twice. Yes not a technical issue, more of an intuitive ick

Do you have any suggestions for a better name / structure? The issue here is that one is a sensor and the other one is a number entity (that is still a bit buggy).

iMicknl avatar Oct 08 '23 14:10 iMicknl

PIN20 is set to ALWAYS_ON (high) to allow the ESP32 to control the desk.

Oh! I didn't know that. Compare here: https://github.com/iMicknl/LoctekMotion_IoT#execute-a-command Maybe you want to add a description to the README? I wouldn't know because on my device the pin does not have a purpose, i.e., ALWAYS_OFF does not change any behavior.

It needs to be at least 0.5s, in order for the number template to be updated with the height of the desk height sensor.

I get that. My first thought was a delta/throttle filter but glad I tested it: Filters are only supported by sensors. One option i can think of is to disable direct updates and do the following:

      id: "desk_height"
      on_value:
        then:
          - component.update: set_desk_height

I've tested the solution and it works as expected.

I am not sure how often you want to cancel a preset command?

Probably very seldom but to me it feels like this action is missing from the options offered in HA. I would expect the Stop button to stop all movements, be it preset or cover actions. Yes the cover has this function but I generally like to offer slightly redundant but purposeful options. Makes integration in e.g. automations or a Lovelace dashboard a lot easier.

In theory the cover entity should have such a status already. We need to have a look if this is currently missing and if so, if this could be added.

I thought so as well but doesn't seem like it 🧐 Apparently this can be achieved via - cover.template.publish: > id: desk_cover > current_operation: OPENING but it didn't make a difference in a quick test.Anyhow, for the same reasons as above, I'd vote for a dedicated binary_sensor (ideally in addition to the cover publishing "opening")

Do you have any suggestions for a better name / structure?

Good challenge. Nope can't think of one. Let's leave as is.

Not really a bug but this triggers my internal perfectionist. Any idea how to sync those two? Simple rounding didn't work for me.

[10:52:06][D][sensor:094]: 'Desk Height': Sending state 67.80000 cm with 1 decimals of accuracy
[10:52:06][D][number:012]: 'Desk Height': Sending state 67.800003
[10:52:06][D][sensor:094]: 'Desk Height': Sending state 67.70000 cm with 1 decimals of accuracy
[10:52:06][D][number:012]: 'Desk Height': Sending state 67.699997

ThomDietrich avatar Oct 09 '23 08:10 ThomDietrich

BTW, ESP8266 GPIO pins are also tolerant to 5V inputs. e.g. https://www.tablix.org/~avian/blog/archives/2022/05/a_footnote_about_esp8266_5v_tolerance/

jamesmyatt avatar Oct 09 '23 10:10 jamesmyatt

Oh! I didn't know that. Compare here: https://github.com/iMicknl/LoctekMotion_IoT#execute-a-command Maybe you want to add a description to the README? I wouldn't know because on my device the pin does not have a purpose, i.e., ALWAYS_OFF does not change any behavior.

Interesting. So in your case you don't have PIN20 connected to your ESP + no PIN20 in your config?

Thanks for your other improvements, I will give it a try and update the startpost when I am done.

BTW, ESP8266 GPIO pins are also tolerant to 5V inputs. e.g. https://www.tablix.org/~avian/blog/archives/2022/05/a_footnote_about_esp8266_5v_tolerance/

Thanks, @jamesmyatt! Not sure why I had so many stability issues when using the ESP8266 with the same config. Perhaps the combination of 5V + no hardware UART causes these stability issues. Multiple users reported similar behavior with ESP8266, but I wasn't able to pin point the issue.

iMicknl avatar Oct 09 '23 11:10 iMicknl

Interesting. So in your case you don't have PIN20 connected to your ESP + no PIN20 in your config?

Historically motivated I have it connected and configured as internal switch as per your default config. However I can confirm that the switch does not have any effect, i.e. neither ALWAYS_OFF and ALWAYS_ON, as well as switching during runtime will interrupt normal operation.

Imho, let's state that PIN20 shall be connected and configure it as ALWAYS_ON as a simplified default. We can still leave a comment "not needed by all controllers" as a comment. I'd suggest a different name other than "Virtual Screen", which at least I can't relate to. How about "Remote Control Pull-up"?

ThomDietrich avatar Oct 09 '23 14:10 ThomDietrich

Minor additional comment: In your code some name and id settings are quoted, not all. None of them need quotes.

Slightly tangent but maybe relevant for docs? As I am using an ESP32-C3 my setup uses GPIO21 as TX, GPIO20 as RX. Some dev boards also don't offer all pins. I suggest to add a remark that users should check the pinout of their specific board.

Suggest renames:

  • switch_alarm -> switch_alarm_off
  • button_alarm -> button_alarm_set
  • button_alarm: entity_category: config

ThomDietrich avatar Oct 10 '23 11:10 ThomDietrich

Thanks @ThomDietrich, I will make the changes. And actually hope to soon have a beta branch where everyone can easily contribute.

iMicknl avatar Oct 10 '23 11:10 iMicknl

Thanks @iMicknl for the rework! With the new code, ESP Home runs very stable on an ESP32 chip! So far I haven't noticed any more crashes. Good work!

I still observed three features that don't quite match the expected behaviour.

  1. If the height is selected via HA using the slider, the desk always moves a little too far, i.e. to slightly too high positions when going up and to slightly too low positions when going down.

  2. If the 4 seat positions are selected via HA (Preset 1, Preset 2, Sit, Stand), the desk height is not updated. This can only be done manually if a) I press the button "Wake Screen" while the display is still on. b) when the display is off, one presses the "Memory" button.

  3. update_interval: 0ms seemed a bit brutal to me - this spammed my log until the ESP Home frontend (within homeassistant) crashed. Is it possible to increase this value to 250 - 500 ms?

j3mu5 avatar Oct 15 '23 13:10 j3mu5

Thanks for the feedback, @j3mu5! Great to hear that this runs stable on your ESP32.

  1. This is a known issue indeed, and won't be too easy to solve. Other implementations keep retrying (so going up and down) until they reach the requested height. I see this feature more as a gimmick anyways, since most desks have 4 presets.
  2. Which desk do you have? For me, the height updates as well when I set a preset.
  3. This will probably be changed to a 'push' mechanism as suggested by @ThomDietrich.

iMicknl avatar Oct 15 '23 14:10 iMicknl

Dear @iMicknl , it is an honour for me to contribute by testing and giving feedback! :)

  1. I also don't find it essential that the table hits the exact height when set by the slider. As you say, this works perfectly with the presets. I don't find repeated adjustment with up and down (like other implementations) an improvement. I have one further idea: How about subtracting (upwards movement) or adding (downwards movement) a certain, user selectable offset (1-2 cm) from the target size. This would at least compensate for the error somewhat. The difference between the target and the actual value is unfortunately variable; between 1 and 2 cm in my case.

  2. It is the Flexispot E7 with a Wemos D1 mini 32. I have connected the cables as follows: GND White-Brown +5V (VDD) Brown GPIO17 Green GPIO16 White-Blue GPIO23 Blue

  3. Cool, thanks @ThomDietrich

j3mu5 avatar Oct 15 '23 16:10 j3mu5

My Flexispot E7 also don't update height when clicking presets

brumouta avatar Oct 15 '23 16:10 brumouta

@brumouta do you use the pin-out and config from above?

iMicknl avatar Oct 15 '23 16:10 iMicknl

Im using an esp8266 (lolin nodemcu), with the pins from the main branch but this new yaml.

On Sun Oct 15, 2023, 04:31 PM GMT, Mick Vleeshouwer @.***> wrote:

@brumouta https://github.com/brumouta do you use the pin-out and config from above? — Reply to this email directly, view it on GitHub https://github.com/iMicknl/LoctekMotion_IoT/issues/67#issuecomment-1763440726, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJNJG6BX7QWZGHP5YXGLCTX7QFVTAVCNFSM6AAAAAA5OQUES2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRTGQ2DANZSGY. You are receiving this because you were mentioned.Message ID: @.***>

brumouta avatar Oct 15 '23 16:10 brumouta

@brumouta if you would be able to use the pin-out from this branch (if it isn't the same), would be great. It should work for your device as well.

iMicknl avatar Oct 15 '23 16:10 iMicknl

It should be moving the rx and tx to gpio13 and gpio 15 and leaving pin20 where it is? image

brumouta avatar Oct 15 '23 16:10 brumouta

I meant the pin-out on the side of your desk mainly, doesn't matter much how you link it to your ESP. The original approach has multiple options for pin outs on the desk side.

iMicknl avatar Oct 15 '23 17:10 iMicknl

Hey @iMicknl

thanks for the updated version of the code, it made it so much easier for me to implement the project at my desk.

As I'm a total newbie with ESPs and HA I could assist in improving the documentation if needed, just let me know if I can help with that, by the way the reference to the ESPWebtools made the implementation a lot easier for me.

The issue with the desk height not being updated when using the presets as @j3mu5 mentioned I can confirm, this also occurs on my E8 (HS13B-1) with ESP32 Dev.

JannikSchmuck avatar Oct 15 '23 18:10 JannikSchmuck

@iMicknl yeah, i'm using the same pins that @j3mu5 is using. I can try tomorrow the new config, and the number from 1 to 8 is basically following the image from main branch right? Or it's just inverted here, because it's basically the same thing from the opposite side.

brumouta avatar Oct 15 '23 22:10 brumouta

@iMicknl what's stopping the merge of v2 branch into main? Seems like it already is a big improvement, even if further improvements can come through individual discussions as we had them here

ThomDietrich avatar Oct 16 '23 07:10 ThomDietrich

@ThomDietrich time to finish the instructions and polish everything! 😁.

& I would like to add passthrough configurations as well.

iMicknl avatar Oct 16 '23 21:10 iMicknl

@iMicknl yeah, i'm using the same pins that @j3mu5 is using. I can try tomorrow the new config, and the number from 1 to 8 is basically following the image from main branch right? Or it's just inverted here, because it's basically the same thing from the opposite side.

@brumouta, it is the same as https://github.com/iMicknl/LoctekMotion_IoT?tab=readme-ov-file#hs01b-1 from the main branch. The main branch has different pinouts, and it seems this specific pin-out works on all devices.

iMicknl avatar Oct 16 '23 21:10 iMicknl

This version of esphome config works much better than the ones fro repo. I modified to add keypad passthrough and it seems to work really well. I used .h file and sensor snippets from repo - probably not the best way of implementing it, but works nonetheless. My desk was bought from elzap.eu with HS13B-1 controller.

https://gist.github.com/l7ssha/c6d989396a560f895ee3c770815a650a

l7ssha avatar Oct 19 '23 19:10 l7ssha

@iMicknl yeah, i'm using the same pins that @j3mu5 is using. I can try tomorrow the new config, and the number from 1 to 8 is basically following the image from main branch right? Or it's just inverted here, because it's basically the same thing from the opposite side.

@brumouta, it is the same as https://github.com/iMicknl/LoctekMotion_IoT?tab=readme-ov-file#hs01b-1 from the main branch. The main branch has different pinouts, and it seems this specific pin-out works on all devices.

Wait, this is one is the same as the other one based on RJ45 colours, but the pins order are inverted, now I'm more confused

brumouta avatar Oct 20 '23 09:10 brumouta

Works good (also with pass-through). One thing i noticed is that ESP is showing height logs each loop cycle. Hopefully it doesn't try to update sensor in HA with this frequency, but only on change.

formatBCE avatar Oct 24 '23 21:10 formatBCE

@formatBCE this is something that I still need to change, currently it spams the log.

iMicknl avatar Oct 24 '23 21:10 iMicknl

This version of esphome config works much better than the ones fro repo. I modified to add keypad passthrough and it seems to work really well. I used .h file and sensor snippets from repo - probably not the best way of implementing it, but works nonetheless. My desk was bought from elzap.eu with HS13B-1 controller.

https://gist.github.com/l7ssha/c6d989396a560f895ee3c770815a650a

@l7ssha

can you share your wiring? i have CB28M1B-1 + HS01B-1 but cant get it to work with passtrough

tobit6795 avatar Oct 28 '23 10:10 tobit6795

This version of esphome config works much better than the ones fro repo. I modified to add keypad passthrough and it seems to work really well. I used .h file and sensor snippets from repo - probably not the best way of implementing it, but works nonetheless. My desk was bought from elzap.eu with HS13B-1 controller.

https://gist.github.com/l7ssha/c6d989396a560f895ee3c770815a650a

@l7ssha

can you share your wiring? i have CB28M1B-1 + HS01B-1 but cant get it to work with passtrough

WDYM, code in that gist works.

formatBCE avatar Oct 28 '23 16:10 formatBCE

@formatBCE my initial post here only explains the wiring for non pass through. I think that @tobit6795 is looking for an example of the wiring when you use pass through.

iMicknl avatar Oct 28 '23 21:10 iMicknl

Hi, sorry to bust into this issue like this.

I started out with the flexispot_ek5.yaml example, modified it to work with my Flexispot E7 and am now adopting the changes from your code. So far, I have run into some issues and had some questions:

In the current readme-file there seems to be an error concerning the pin map of the Flexispot E7. It looks like the pin map is inverted, like @brumouta already mentioned. See here for more information: #58 @iMicknl Is this expected when using a RJ45 breakout board? Additionally I think it would be a lot better to list the pin number of the RJ45 instead of the color of the wires as they aren't really useful when using a breakout board and can also be different from cable to cable. Furthermore, I think adding another collum with the labels of the motor controller (not the control panel) would make sense and prevent mixing up of TX and RX pins.

In other words, I would change this (Pins mirrored on E7):

ESP8266 Loctek Motion (HS13B-1) Loctek Motion Cable Color (HS13B-1) Ethernet cable color (T568B)
GND GND Blue White-Brown
D6 RX Green White-Blue
D5 TX Black Green
D2 PIN 20 Red Blue

Into this (pins corrected for E7):

Motor controller CB38M2J(IB)-1 Control panel HS13B-1 Loctek Motion Cable Color (HS13B-1) Ethernet cable number ESP32
GND GND Blue 7 GND
TX RX Green 5 GPIO 16 (RX)
RX TX Black 6 GPIO 17 (TX)
Pin 20 PIN 20 Red 4 GPIO 23
+5V +5V ? 8 Voltage regulator (if available)

Note: I don't know if the colors from the Loctek Motion Cable are also inverted for the E7

Another thing that has already been mentioned is the usage of a logic level shifter. While the EPS32 apparently can handle a 5V input, I doubt it's going to be healthy. So a logic level shifter would definitely make sense. The problem is, which one? It would be nice if we could make a table or something like that, listing the experiences of people who already used them. For example, is a I2C logic level shifter able to convert the signals fast enough?

Additionally, do we actually know that the motor controller uses 5V for UART? My multimeter isn't capable of verifying that, as it constantly shows 2V between TX and GND on the controller. Can somebody verify that it's actually using 5V. Possibly someone with an oscilloscope? I'd rather not fry the controller of the desk than the ESP32...

CoderTobi avatar Oct 31 '23 21:10 CoderTobi