zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[Tuya ZWT198/ZWT100-BH] Thermostat's local temperature calibration value out of range after some time

Open majkers opened this issue 10 months ago • 9 comments

What happened?

I have local temperature calibration value set to -0.1 and after some undisclosed time this value changes by itself to 6553.5 and I get an error in logs:

Invalid value for number.termostat_local_temperature_calibration: 6553.5 (range -9.9 - 9.9)

What did you expect to happen?

Value of calibration should stay as set

How to reproduce it (minimal and precise)

No response

Zigbee2MQTT version

2.0.0-2

Adapter firmware version

20230507

Adapter

zStack3x0 Sonoff dongle P

Setup

Hass OS on PI 4

Debug log

Invalid value for number.termostat_local_temperature_calibration: 6553.5 (range -9.9 - 9.9)

majkers avatar Feb 03 '25 15:02 majkers

Looks like I am no the only one having this issue https://github.com/Koenkk/zigbee2mqtt/issues/24943 and https://github.com/Koenkk/zigbee2mqtt/issues/24758. I open new one cause old ones are stale or closed...

majkers avatar Feb 03 '25 17:02 majkers

Just like it was mentioned in https://github.com/Koenkk/zigbee2mqtt/issues/24758#issuecomment-2477275989 wrong code is in https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/tuya.ts and https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/lib/tuya.ts

IMHO There is a mistake in this code:

   localTempCalibration3: {
        from: (v: number) => {
            if (v > 0x7fffffff) v -= 0x100000000;
            return v / 10;
        },
        to: (v: number) => {
            if (v > 0) return v * 10;
            if (v < 0) return v * 10 + 0x100000000; 
            return v;
        },
    },

What is working for me is just:

return v * 10; in to method....

or simply use other converter ie. tuya.valueConverter.divideBy10

majkers avatar Feb 05 '25 15:02 majkers

@alexsotoaguilera can You check it out?

majkers avatar Feb 05 '25 15:02 majkers

@alexsotoaguilera can You check it out?

is the change?

localTempCalibration3: { from: (v: number) => { if (v > 0x7fffffff) v -= 0x100000000; return v / 10; }, to: (v: number) => { if (v > 0) return v * 10; if (v < 0) return v * 10 + 0x100000000; return v; }, },

for this?

localTempCalibration3: { return v * 10; },

....

in order not to break anything, you could create a new converter that returns ‘return v * 10;’ with a new index ‘localTempCalibration4’.

alexsotoaguilera avatar Feb 05 '25 15:02 alexsotoaguilera

Like I said. IMHO there is one: tuya.valueConverter.divideBy10

majkers avatar Feb 06 '25 07:02 majkers

UPDATE. I think I know how those converters should work....more or less like that I guess:

output = from(to(input)) and for input -0.1 output is -0.1 in my app written is typeScript and angular. TO be more precise. to generates value 4294967295 and from(4294967295) is -0.1 So I don't know what the problem is :(

majkers avatar Feb 06 '25 12:02 majkers

I have exactly the same problem. The value is first set correctly but after a random time it transforms to this big invalid number.

OpaApo avatar Feb 19 '25 14:02 OpaApo

Same problem here

agak79 avatar Feb 21 '25 06:02 agak79

Is there anyway to solve this issue?

agak79 avatar Mar 18 '25 07:03 agak79

still happening, don't stale

agak79 avatar Apr 23 '25 07:04 agak79

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jun 23 '25 00:06 github-actions[bot]

still exists

majkers avatar Jun 23 '25 07:06 majkers

Same problem on another Tuya Device : _TZE204_xnbkhhdr

Nopraz avatar Jul 16 '25 11:07 Nopraz

Model [ZWT198/ZWT100-BH] (https://www.zigbee2mqtt.io/devices/ZWT198_ZWT100-BH.html#tuya-zwt198%252Fzwt100-bh)

Zigbee2MQTT 2.6.0

Logger: homeassistant.components.mqtt.number Source: components/mqtt/number.py:184 Integration: MQTT (documentation, issues) First seen: 1 Aug 2025 at 20:32:26 (34155 occurrences) Last logged in: 00:27:55

Invalid value for number.termostat_local_temperature_calibration: 6553.2 (range -9.9 - 9.9)

Palec avatar Aug 05 '25 22:08 Palec

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Oct 05 '25 00:10 github-actions[bot]

Do not stale, please. Not relatives lresolved yet

agak79 avatar Oct 10 '25 13:10 agak79

I replace with this code and it works for me

localTempCalibration4: {
    from: (v) => {
        if (v > 0x7fff)
            v-= 0x10000;
        return v / 10;
    },
    to: (v) => {
        if (v > 0)
            return v * 10;
        if (v < 0)
            return v * 10 + 0x100000000;
        return v;
    },

chay150 avatar Oct 29 '25 14:10 chay150

@chay150 can You open PR with this change?

alexsotoaguilera avatar Oct 29 '25 14:10 alexsotoaguilera

@chay150 can You open PR with this change?

Sorry, I have no knowledge on git, I don't know how to do it. I modified the code directly on my running zigbee2mqtt in two tuya.js files.

chay150 avatar Oct 29 '25 15:10 chay150

You add localTempCalibration4, but in the original file there are 1,2 and 3, so it makes no sense for the device to use 4.

Are you sure you haven't overwritten an existing one?

{code} selfTestResult: valueConverterBasic.lookup({checking: 0, success: 1, failure: 2, others: 3}), lockUnlock: valueConverterBasic.lookup({LOCK: true, UNLOCK: false}), localTempCalibration1: { from: (v: number) => { // biome-ignore lint/style/noParameterAssign: ignored using --suppress if (v > 55) v -= 0x100000000; return v / 10; }, to: (v: number) => { if (v > 0) return v * 10; if (v < 0) return v * 10 + 0x100000000; return v; }, }, localTempCalibration2: { from: (v: number) => v, to: (v: number) => { if (v < 0) return v + 0x100000000; return v; }, }, localTempCalibration3: { from: (v: number) => { // biome-ignore lint/style/noParameterAssign: ignored using --suppress if (v > 0x7fffffff) v -= 0x100000000; return v / 10; }, to: (v: number) => { if (v > 0) return v * 10; if (v < 0) return v * 10 + 0x100000000; return v; }, }, {code}

El mié, 29 oct 2025 a las 16:57, chay150 @.***>) escribió:

chay150 left a comment (Koenkk/zigbee2mqtt#26157) https://github.com/Koenkk/zigbee2mqtt/issues/26157#issuecomment-3462424263

@chay150 https://github.com/chay150 can You open PR with this change?

Sorry, I have no knowledge on git, I don't know how to do it. I modified the code directly on my running zigbee2mqtt in two tuya.js files.

— Reply to this email directly, view it on GitHub https://github.com/Koenkk/zigbee2mqtt/issues/26157#issuecomment-3462424263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGHGWXFUUSHGPBDDNOCGPV332DPXDAVCNFSM6AAAAABWML3L3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINRSGQZDIMRWGM . You are receiving this because you were mentioned.Message ID: @.***>

alexsotoaguilera avatar Oct 29 '25 16:10 alexsotoaguilera

from what I've found the device sent this data in an 16 bits integer so for -1 you get 65535, -2 65534 and so on and the existing function #3 test on an 32 bits integer

Zigbee2mqtt version 2.6.1 commit: d44463a3 zigbee-herdsman-converters version 25.14.0 zigbee-herdsman version 6.0.4

there are 2 tuya.js files :

./node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman-converters/dist/lib/tuya.js
./node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman-converters/dist/devices/tuya.js

I added localTempCalibration4 in dist/lib

node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman-converters/dist/lib# diff tuya.js tuya.save
768,782d767
<     localTempCalibration4: {
<         from: (v) => {
<             // biome-ignore lint/style/noParameterAssign: ignored using `--suppress`
< 	    if (v > 0x7fff) 
< 	    	v-= 0x10000;
<             return v / 10;
<         },
<         to: (v) => {
<             if (v > 0) 
<                 return v * 10;
<             if (v < 0) 
<                 return v * 10 + 0x100000000;
<             return v;
<         },
<     },
2533c2518
< //# sourceMappingURL=tuya.js.map
---
> //# sourceMappingURL=tuya.js.map
\ No newline at end of file

and modified the one in dist/devices to call localTempCalibration4

node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman-converters/dist/devices# diff tuya.js tuya.save
8513,8514c8513
<                 //[19, "local_temperature_calibration", tuya.valueConverter.localTempCalibration3],
<                 [19, "local_temperature_calibration", tuya.valueConverter.localTempCalibration4],
---
>                 [19, "local_temperature_calibration", tuya.valueConverter.localTempCalibration3],
18501c18500
< //# sourceMappingURL=tuya.js.map
---
> //# sourceMappingURL=tuya.js.map
\ No newline at end of file

chay150 avatar Oct 29 '25 17:10 chay150