dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 498 forks source link

Config/offset not working for some Tuya TRV #5484

Closed Smanar closed 2 years ago

Smanar commented 2 years ago

Describe the bug

Some Tuya TRV like

Display a bad temperature. They have an offset setting but not/bad working

Steps to reproduce the behavior

Just use the device

Expected behavior

Screenshots

Environment

Additional context

Smanar commented 2 years ago

To test code, you have the procedure here https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Compiling-the-REST-plugin-for-device-specific-testing So for you, after having installed deconz :

sudo apt install deconz-dev
git clone --branch tuya_offset https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

If you have a small raspberry, it can freeze during compilation, my pi 3 do, so remove "-j2"

Value need to be *100, so for an offset of 2 °C use 200. If it don't work can you try to set the value manualy (if the device support it) and give deconz logs (with "info" and "info_L2") during the manipulation.

Or at least logs when doing the request, to see how the device react to it.

And I don't know what do the command on the device, if it add an offset to the temperature displayed, or add a value beetwen the temperature displayed and the temperature used for reglulation (if you still have the documentation ?)

cwm77 commented 2 years ago

Ok, I now loaded the compiled plugin and tried to set the offset. In the display, I could see that the current temperature increased by 1 degree Celsius, although I set -400. Other values did not lead to any further adjustment in the display. Even a value of 0 did not. Attached is the log file. Device has "uniqueid":"50:32:5f:ff:fe

Another problem with this thermostat seems to be that it cannot be switched to On, Off and Auto modes via the Deconz Stick using Zigbee. But this is another issue.

Cheers, mcw

50:32:5f:ff:fe-1.txt

Smanar commented 2 years ago

For the "auto" mode there is a PR, idk if it concern your device https://github.com/dresden-elektronik/deconz-rest-plugin/pull/5471

For the device {"_TZE200_aoclfnxz", "TS0601", "Moes", "Tuya_THD BTH-002 Thermostat"},

From the actual code, the "preset" support "auto" and "program" and for "mode" only "off" and "heat". This device haven't the mode set in the code, from my memory the "mode" is only used to enable/disable the display.

13:13:31:470 Send Tuya request 0x50325FFFFE289F7F : Dp_type: 0x02, Dp_identifier 0x1B, data: 00000000

Something is bad in the code, data are always 00000000 even you are using -450 and - 430.

Edit: Ok have found the issue, all offsets was broken. IDK if it will work, but this time, you will have other value than 00000

To update the code

cd deconz-rest-plugin
git pull
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
cwm77 commented 2 years ago

Looks good, thanks. It seems to work now. It is now possible to adjust the LCD on the thermostat regarding current temperature through offset. Interesting is that instead of value 100 = 1 degree Celsius now value 10 = 1 degree Celsius has to be taken. Increments of 0.5 degrees Celsius are not taken over, only full degrees. By the way, you cannot set the settings in ioBroker. These are not accepted there and acknowledged with red numbers, but in my case this works only via Homebridge with the iOS app Home+. In this app, however, after some time, for example, for an offset of -4 degrees C -0.4 degrees C is displayed, although the desired offset of 4 degrees remains on the thermostat.

Regarding On, Off and Auto modes, I looked at #5471. {"_TZE200_aoclfnxz", "TS0601", "Moes", "Tuya_THD BTH-002 Thermostat"}, does not seem to be included. Again for understanding. You can only adjust the heatsetpoint for thermostat via ioBroker. All other values cannot be adjusted there. In the above Home+ app, you can now adjust the offset. Otherwise, the heatsetpoint and locking (screenlock) and switching off. Turning on and Auto Mode does not work. Can I open the corresponding PR for the other problems mentioned?

By looking for more Information, I found the following hint. The thermostat seems to have a bug, which causes it to send messages multiple times while it is updating.

If I can help in any way, please tell. I will be happy to do so.

Smanar commented 2 years ago

Interesting is that instead of value 100 = 1 degree Celsius now value 10 = 1 degree Celsius has to be taken

It mean you are using config/offset = 10 to add 1 °C ? If yes I m wrong in my convertion, need to keep the same convertion for all value (need to use 100 for 1°C)

Increments of 0.5 degrees Celsius are not taken over

Yep, but it's from the device.

for an offset of -4 degrees C -0.4 degrees C is displayed, although the desired offset of 4 degrees remains on the thermostat. You mean 4 °C on the TRV but 0.4 on the application ? (probably because my convertion error ?)

For the missing "auto" I think it s normal for this device, on the z2m they are doing same than us, they use only "off" and "heat" https://www.zigbee2mqtt.io/devices/BHT-002-GCLZB.html RConfigModeValuesTuya2 = { { {QLatin1String("off"), {0x00}}, {QLatin1String("heat"), {0x01}} } };

You can only adjust the heatsetpoint for thermostat via ioBroker

So it mean it work or not ? ioBroker use the API too ? I have checked the code again and for exemple the locking need to work too, you have some logs when making the request ?

cwm77 commented 2 years ago

First, yes, currently the offset setting works, but only with tens values, e.g. -40 for -4 degrees Celsius. But I can only do this via the Api directly, e.g. with Insomnia or with the iOS app Home+ via Hombridge Hue. ioBroker does not work for this yet.

Here are two logfiles. The first one I took when I adjusted the offset values, and they were taken over.

uniqueid_50325ffffe289fb3-01-0201_Thermostat_Büro_1.txt

The second one I recorded when I tried to adjust the offset with ioBroker, and it didn't work.

uniqueid_50325ffffe289fb3-01-0201_Thermostat_Büro_2.txt

Normally, I can adjust and switch values with ioBroker. For example, the temperature an locking can be adjusted without any problems.

Smanar commented 2 years ago

First log, but you have used 400 not 40 ? (in the API I mean, as it was the value updated in the websocket return)

13:21:27:133 Send Tuya request 0x50325FFFFE289FB3 : Dp_type: 0x02, Dp_identifier 0x1B, data: 00000004
13:21:27:155 Websocket 192.168.4.118:58996 send message: {"config":{"heatsetpoint":2100,"locked":false,"mode":"heat","offset":400

But later

13:21:28:395 Tuya debug 4 : Address 0x50325FFFFE289FB3 Payload 009e1b02000400000004
13:21:28:396 Tuya debug 5 : Status: 0 Transid: 158 Dp: 539 (0x02,0x1B) Fn: 0 Data 4
13:21:28:426 Websocket 192.168.4.118:58996 send message: {"config":{"heatsetpoint":2100,"locked":false,"mode":"heat","offset":40

So the return need to be 10, But on the code I m doing `temp = temp 100;` How 4 *100 can be 40 .... You are sure you are using the last version ?

                    case 0x021B : // temperature calibration (offset in degree) for Moes
                    {
                        qint16 temp = static_cast<qint16>(data & 0xFFFF);

                        if (temp > 2048)
                        {
                            temp = temp - 4096;
                        }

                        temp = temp * 100;

                        ResourceItem *item = sensorNode->item(RConfigOffset);

                        if (item && item->toNumber() != temp)
                        {
                            item->setValue(temp);
                            Event e(RSensors, RConfigOffset, sensorNode->id(), item);
                            enqueueEvent(e);
                        }
                    }

On the Second log, you never make the zigbee request, so the API have probably send an error.

cwm77 commented 2 years ago

I have now made a screen video showing what I am testing. Along the way, the log file was created.

https://user-images.githubusercontent.com/9320205/142074578-6c005234-1309-44b8-bebb-8d6da9768541.mp4

50:32:5f:ff:fe:28:9f:b3-01-0201.txt

So the return need to be 10, But on the code I m doing `temp = temp 100;` How 4 *100 can be 40 .... You are sure you are using the last version?

I think so. I have the version of https://github.com/Smanar/deconz-rest-plugin.git from 14.11. Is this the latest?

Smanar commented 2 years ago

Lol, first time someone make a video to debug ^^.

I m not guilty for all your issues, I think some of them are from the application, like the locked command, if you can't intercept the http request, you can see it in deconz if you enable the flag "http" but take care this flag is realy talkative. Sometime the value is written in red, it s don't mean there was an error ?

For the offset issue it s still a mystery, can you make atry with the last version (just to have log), I have added some more debug line.

The variable temp is a quint, so can't be a decimal value, and *100, I realy don't see how i can have a value < 100.

cwm77 commented 2 years ago

I have now tried it with the latest version. The log file contains the information about what I did with the thermostat with ID 50:32:5f:ff:fe:28:9f:b3-01-0201 in terms of changing the offset values. I hope this helps to find the needle in the haystack.

50325ffffe289fb3-01-0201.txt

Smanar commented 2 years ago

Ok I give up, have made a *1000 without understand, hopping it work now. You have found why it don't work using your third app ?

lackhove commented 2 years ago

I just tested with df391951aa6c8e3f9e2f754170718507a512ebed and a _TZE200_ckud7u2l and can confirm the offset works as expected. curl -X PUT -i http://xxx:8082/api/yyy/sensors/15 --data '{ "config": { "offset": 100 } }' increases the temperature by 1°C (Displayed in the phoscon API Information and home assistant).

cwm77 commented 2 years ago

I have applied the changes and tested them. First with an offset of 0 then with -300. From my perspective, nothing has changed. It is still possible to set an offset, and it is taken over by the thermostats. Enclosed the log file for tested Thermostat 50:32:5f:ff:fe:28:9f:b3-01-0201.

50:32:5f:ff:fe:28:9f:b3-01-0201.txt

Regarding the third party app ioBroker I still have to look. In the log of ioBroker the following messages appear when the offset is changed. I haven't had time to investigate this further yet. Maybe someone reading this knows this kind of error though?

warn {"address":"/sensors/389/config/offset", "description": "invalid value, -300, for parameter offset", "type":7}

Smanar commented 2 years ago

Find it ^^ Was because the missing "break" so th code execute the 0x021B part AND the 0x022c one.

This error message can be produced if ioBroker use "-300" instead of 300

cwm77 commented 2 years ago

Hey, great. Can the problem be solved, or does the error originate from the hardware, i.e., the firmware would have to be adapted?

However, I may not have understood something correctly.

Smanar commented 2 years ago

For the error in ioBroker ? Try to ask to their devs (If it's not stupid as answer ? I realy don't know what is it). But they make a bad request, malformed one.

But if it work on deconz side, I can make the PR ? Even it s not tested for all devices.

cwm77 commented 2 years ago

Ok, I'll ask the ioBroker devs about this when I find time. Thanks for everything and yes, from my standpoint a PR is a good next step.

Smanar commented 2 years ago

The PR is done, if someone still have not working device that support offset ...

embeddeddev commented 2 years ago

I can confirm this bug of not remotely applied offset in the Hama TRV aka "_TZE200_yw7cahqs", too. Is this even included?

The device was integrated w/ this device request (detailed infos if required): https://github.com/dresden-elektronik/deconz-rest-plugin/issues/4841

Smanar commented 2 years ago

I have just modified something for your device. Can you make a try with the new code ?

If it s still not working, can you share logs when making the command ?

embeddeddev commented 2 years ago

Thanks so far for the quick response and adaption! In my previous comment I'd mistakenly used the original plugin in my docker image, so I deleted it directly.

Need to spend more time on building a fresh docker image tomorrow, which doesn't seem to be so easy.

embeddeddev commented 2 years ago

Finally got it. Started w/ a rejoined thermostat as it was reporting only null/NaN values before for current_temperature. In my setup I'm using Home Assistant as frontend for viewing device state and issuing REST commands.

  1. Set offset to 100 --> value kept persistent in device attributues --> but no reaction/change of current_temperature
  2. Set offset to 50 --> value kept for a few moments but was resetted to 0 after a few moments and vanished from device atttributes (since 0) --> no reaction on current_temperature

Here the log sequence grepped by device MAC + Tuya keyword. I hope it's OK so, because my network is very noisy. tuya_offset_hama.log

Smanar commented 2 years ago

It seem it have worked for 100

00:07:02:832 Send Tuya request 0xCC86ECFFFEA0FDD2 : Dp_type: 0x02, Dp_identifier 0x1B, data: 00000001 00:07:07:766 Tuya debug 4 : Address 0xCC86ECFFFEA0FDD2 Payload 006e1b02000400000001 00:07:07:767 Tuya debug 5 : Status: 0 Transid: 110 Dp: 539 (0x02,0x1B) Fn: 0 Data 1 00:07:53:046 Websocket 172.16.0.8:56452 send message: {"config":{"heatsetpoint":1600,"locked":true,"mode":"off","offset":100

But idk the influence it have on display, you haven't the manual ? try with 500 to see if it s more visible.

The offset 50 can't work, you need full value, 50 = 0.5°C.

embeddeddev commented 2 years ago

You're right. I tried about an hour to detect, that the device communication was really broken and TRV didn't report any changes until I repaired it a few times and resetted it in deCONZ GUI finally. Thanks!

Smanar commented 2 years ago

And offset is working ?

embeddeddev commented 2 years ago

Offset was working w/ your branch after resetting the Hama TRV node.

Smanar commented 2 years ago

@cwm77, if you have some time, can you try the actual code with positive and negative values pls ?

cwm77 commented 2 years ago

Hi, I'm trying to compile the new plugin, but I get the following errors.

de_web_plugin.h:16:10: fatal error: deconz.h: file or directory not found #include

alarm_system.cpp:13:10: fatal error: deconz/timeref.h: file or directory not found #include <deconz/timeref.h>

To be on the safe side, I not only did a git pull, but also cloned everything again. However, the errors remain.

Smanar commented 2 years ago

Perhaps sudo apt install deconz-dev

cwm77 commented 2 years ago

Thanks, that's it. I don't do it that often. Meanwhile, I have already cleaned everything up ;-).

Now, I have once set the offset with 400 and then with -400, and it works perfectly. In iobroker I see now also no more the 10s, but the 100 values (Instead of 40 now 400 ...).

Here is the logfile.

50325ffffe289fb3-01-0201.txt

Smanar commented 2 years ago
13:00:53:017 Send Tuya request 0x50325FFFFE289FB3 : Dp_type: 0x02, Dp_identifier 0x1B, data: 00000004
3:00:53:044 Websocket 192.168.4.118:36178 send message: {"config":{"heatsetpoint":1800,"locked":false,"mode":"heat","offset":400
13:00:53:601 Tuya debug 4 : Address 0x50325FFFFE289FB3 Payload 00c21b02000400000004
13:00:53:605 Tuya debug 5 : Status: 0 Transid: 194 Dp: 539 (0x02,0x1B) Fn: 0 Data 4
13:01:01:944 Send Tuya request 0x50325FFFFE289FB3 : Dp_type: 0x02, Dp_identifier 0x1B, data: 00000ffc
13:01:01:976 Websocket 192.168.4.118:36178 send message: {"config":{"heatsetpoint":1800,"locked":false,"mode":"heat","offset":-400,
13:01:02:931 Tuya debug 4 : Address 0x50325FFFFE289FB3 Payload 00c91b02000400000ffc
13:01:02:937 Tuya debug 5 : Status: 0 Transid: 201 Dp: 539 (0x02,0x1B) Fn: 0 Data 4092

Ok so from code it's working, on the device too ? I m asking because something was not working previously. For positive value you send exactly the value (data is 4), but for negative one the value is changed (data is 4092).

iobroker devs have changed their code ?

cwm77 commented 2 years ago

Yes, it also works directly on the thermostat. The indication of the current temperature is adjusted accordingly on the display.

Because of the problem that the offset cannot be set in ioBroker I have not yet had time to report this to the devs. I hope to get to it in the next few days.

fi-sch commented 2 years ago

Guys, do you plan to release this fix anytime soon? This is a pretty big issue for many depending on Moes TRV in our homes. It seems to be broken for a long time, also the fix is in a "limbo" for nearly a month now...

Mimiix commented 2 years ago

It's in the latest beta.

fi-sch commented 2 years ago

It's in the latest beta.

Awesome. I am asking about non-beta release, however. Something that I can safely run on my production server as a DE client, not beta tester.

MrMarkus42 commented 2 years ago

I hope you don't mind if I ask a question: I've got the same problem with my new Hama TRV aka "_TZE200_yw7cahqs" devices. I wan't to set an offset via REST-API to 40 (0.4 degrees). I only can set values to multiples of 100 (100/200/300...). Why can't I set values to 40/50/60?

If I set for example 40 the offset is changed back to 0.

Smanar commented 2 years ago

Are you sure the device is able to support a decimal value ? I m reading the code, and deconz:

so using the 400 value mean deconz send the value 4 (and it's the minimum value, there is no decimal in request)

MrMarkus42 commented 2 years ago

Mh. That's what I'm doing:

Looking in Phoscon API Help:

"12:16:22:381": { "e": "changed", "id": "107", "r": "sensors", "state": { "lastupdated": "2022-05-01T10:16:21.724", "lowbattery": false, "on": false, "temperature": 2020, "valve": 0 }, "t": "event", "uniqueid": "cc:86:ec:ff:fe:c2:00:7c-01-0201" },

Smanar commented 2 years ago

The reaction is strange, it's like when you set the offset it use "tuya rule", but for the return it use the "classic rules"

Are you using the GUI ? Can you share some logs with "info" and "info_l2" for this device, heat the device to trigger a temperature notification.

I m checking more information on other zigbee project, on z2m it's called local_temperature_calibration, but it seemm they are usng integer value too.

steljwagh commented 10 months ago

If you want an offset for humidity and or temperature sensors in deconz, it's easy to do so through the API. To get a API key login on Phoscon, go to /help/API information and get a existing key from the whitelist (search for whitelist and you'll find the keys)

Filter on sensors to find the right ID for your sensor.

Then open a command/terminal box and construct the following command to your needs.

curl -X PUT -d "{\"config\": {\"offset\": 100 } }" http://ipaddress:port/api/key/sensors/10

offset examples:

-80 = minus 0,8 degrees 100 = plus 1 degree