j5lien / esphome-idasen-desk-controller

ESPHome component for Ikea Idasen desk control
MIT License
187 stars 36 forks source link

DPG1C woes: cannot move using Cover and wrong sensor height #63

Open p4block opened 1 year ago

p4block commented 1 year ago

I have a desk made with Linak actuators and a DPG1C32 controller, not from IKEA. The controller seems to be 99% compatible with what this project expects, except for a few quirks.

I actually found a workaround the moving issue by browsing some other threads, but I'm posting it here for future people with the same problem.

It seems that the Linak app sets something in the controller that makes it not work with this integration, I suspect it's the "allow desk to be moved automatically without holding a button" toggle in settings, but now that I have it working I don't want to break it to confirm the suspicion :grin: In any case, factory resetting the DPG1C by holding the "star" button for 8 seconds allowed movement to work just fine! Seems that broke after a while.

This could probably be added to the README instructions as a possible troubleshooting step.

As for the wrong height, I seem to be in similar place as #61, they are dividing by a magic value to get close to the real height. It seems that the DPG1C registers contain something different than the expected by the lambda.

uint16_t raw_height = ((uint16_t)x[1] << 8) | x[0];

Height shown by the sensor seems to be slightly over 1/3 of the real one. Sadly this is not an easy order of magnitude or power of two explained by binary shift shenanigans. I will try to dump the registers and see if I can figure out the true height from whatever this thing has internally later.

I did a thing

At max height (133cm for my model):

x[0]:   01100100
x[1]:   00011001
Concat: 0001100101100100
Float: 6500.0
Cm: 65.0

At min height (68cm for my model)

x[0]:   00000000
x[1]:   00000000
Concat: 0000000000000000
Float: 0.0
Cm: 0.0

So yeah, on this model those two registers seems to contain a weird glorified percentage. True height must be stored somewhere else, or processed somehow before being shown in screen&app. :thinking:

I'm now converting that range that to the true values

    lambda: |-
      uint16_t raw_height = ((uint16_t)x[1] << 8) | x[0];

      float actual_height = 68.0 + (raw_height / 6500.0) * (133.0 - 68.0);

      ESP_LOGW("x[0]", "0x%X", x[0]);
      ESP_LOGW("x[1]", "0x%X", x[1]);
      ESP_LOGW("Height", "%f", actual_height);

      return actual_height;

EDIT: now it's back to not working no matter what I do for some reason :thinking: EDIT2: back to working by pairing it briefly with the official app and back to the ESP. The official app seems to be doing something. Subsequent cold boots of the DPG1C seem to break the ability to control via ESPHome unless it talked to the app first.

thexperiments commented 1 year ago

Similar issues here. So to me the height issue looks just like a offset so you can leave the lambda but just add jour minimum height to it. The lambda does no magic but just puts together two 8 bit numbers to make a 16 bit number.

Regarding moving tho it was working at some point in time but definitely keeps failing. I'm wondering if the Linak controller simply has a bug if a Bluetooth session stays active to long as normally a phone would be only connected for some short duration for control.