Now winter is coming, my outside tuya temp. sensor (Model: "TS0601-temphumi") is giving errors on negative temperatures.
It seems that the temp coming from the sensor is a signed value, for example -18 .8 C is logged as 0xffffff44, but in domoticz an error is logged:
2023-11-30 14:04:42 .726 Error: zigbee: Aberrant Temp: 429496710 .8 (below -50 or above 100) for device: df8d
4294967108 is unsigned 0xffffff44.
Ep:
01:
0000:
0004: "_TZE200_yjjdcqsq"
0000: 3
0001: 72
0005: "TS0601"
0007: 3
fffe: 0
ffe2: 56
ffe4: 0
ffdf: "N,iN,iN,iN,iU,iU,iU,iU,i\,i\,i\,i\,i"
0004: Object {}
0005: Object {}
0019: Object {}
Type: "Temp/Humi"
ClusterType:
2081: "Temp"
2082: "Humi"
0402:
0000: 429496710 .8
0405:
0000: 8 .9
Tuya:
Temp: "ffffff44"
Humi: 8 .9
dp:3-dt:4: "02"
dp:9-dt:4: "00"
TUYA_MCU_VERSION_RSP: "40"
Tuya temp sensor not able to parse negavtive temperatures
Moderator: leecollings
-
- Posts: 5
- Joined: Thursday 10 November 2016 16:57
- Target OS: Linux
- Domoticz version:
- Contact:
-
- Posts: 1977
- Joined: Monday 02 April 2018 20:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: France
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
I guess you are referring to the Zigbee for Domoticz plugin.
Negative temperature are normaly correctly handle.
What is the version of the plugin you are using ?
What is the device Model Name ? It should be TS0601-temphumi .
Negative temperature are normaly correctly handle.
What is the version of the plugin you are using ?
What is the device Model Name ? It should be TS0601-temphumi .
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
-
- Posts: 5
- Joined: Thursday 10 November 2016 16:57
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
I am indeed referring to the Zigbee for Domoticz plugin
The version is Plugin: 7 .1 .005 [2 .148]
Model: "TS0601-temphumi"
I'm not an python expert, but currently looking at (int(data, 16) in tuya .py line 1271 and 1272. Is this code handling signed values correctly in python ?
The version is Plugin: 7 .1 .005 [2 .148]
Model: "TS0601-temphumi"
I'm not an python expert, but currently looking at (int(data, 16) in tuya .py line 1271 and 1272. Is this code handling signed values correctly in python ?
-
- Posts: 1977
- Joined: Monday 02 April 2018 20:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: France
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
I’ll check that evening. It has been fixed for some but probably not all:-(
Envoyé de mon iPhone en utilisant Tapatalk
Envoyé de mon iPhone en utilisant Tapatalk
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
-
- Posts: 5
- Joined: Thursday 10 November 2016 16:57
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
With the following change i've made it working, (in tuya.py) (introduced a helper function hex_to_signed)
Don't know if this is the correct place.
def hex_to_signed(source):
"""Convert a string hex value to a signed hexidecimal value.
This assumes that source is the proper length, and the sign bit
is the first bit in the first byte of the correct length.
hex_to_signed("F") should return -1.
hex_to_signed("0F") should return 15.
"""
if not isinstance(source, str):
raise ValueError("string type required")
if 0 == len(source):
raise valueError("string is empty")
sign_bit_mask = 1 << (len(source)*4-1)
other_bits_mask = sign_bit_mask - 1
value = int(source, 16)
return -(value & sign_bit_mask) | (value & other_bits_mask)
def tuya_temphumi_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID, dstNWKID, dstEP, dp, datatype, data):
self.log.logging("Tuya", "Log", "tuya_temphumi_response - %s %s %s %s %s" % (NwkId, srcEp, dp, datatype, data), NwkId)
if dp == 0x01: # Temperature,
store_tuya_attribute(self, NwkId, "Temp", data)
MajDomoDevice(self, Devices, NwkId, srcEp, "0402", (hex_to_signed(data) / 10))
checkAndStoreAttributeValue(self, NwkId, "01", "0402", "0000", (hex_to_signed(data) / 10))
Don't know if this is the correct place.
def hex_to_signed(source):
"""Convert a string hex value to a signed hexidecimal value.
This assumes that source is the proper length, and the sign bit
is the first bit in the first byte of the correct length.
hex_to_signed("F") should return -1.
hex_to_signed("0F") should return 15.
"""
if not isinstance(source, str):
raise ValueError("string type required")
if 0 == len(source):
raise valueError("string is empty")
sign_bit_mask = 1 << (len(source)*4-1)
other_bits_mask = sign_bit_mask - 1
value = int(source, 16)
return -(value & sign_bit_mask) | (value & other_bits_mask)
def tuya_temphumi_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID, dstNWKID, dstEP, dp, datatype, data):
self.log.logging("Tuya", "Log", "tuya_temphumi_response - %s %s %s %s %s" % (NwkId, srcEp, dp, datatype, data), NwkId)
if dp == 0x01: # Temperature,
store_tuya_attribute(self, NwkId, "Temp", data)
MajDomoDevice(self, Devices, NwkId, srcEp, "0402", (hex_to_signed(data) / 10))
checkAndStoreAttributeValue(self, NwkId, "01", "0402", "0000", (hex_to_signed(data) / 10))
-
- Posts: 1977
- Joined: Monday 02 April 2018 20:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: France
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
There is such code I guess it is in the tuyaTS0601.py
Envoyé de mon iPhone en utilisant Tapatalk
Envoyé de mon iPhone en utilisant Tapatalk
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
-
- Posts: 1977
- Joined: Monday 02 April 2018 20:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: France
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
I will push the fix with the December release, but to do it properly the right code should be
Code: Select all
if dp == 0x01: # Temperature,
unsigned_value = int( data,16)
signed_value = struct.unpack('>i', struct.pack('>I', unsigned_value))[0]
store_tuya_attribute(self, NwkId, "Temp", signed_value)
MajDomoDevice(self, Devices, NwkId, srcEp, "0402", (signed_value / 10))
checkAndStoreAttributeValue(self, NwkId, "01", "0402", "0000", (signed_value/ 10))
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
-
- Posts: 5
- Joined: Thursday 10 November 2016 16:57
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
I have copied the code example and can confirm that it works correctly. Thx.
-
- Posts: 1977
- Joined: Monday 02 April 2018 20:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: France
- Contact:
Re: Tuya temp sensor not able to parse negavtive temperatures
thanks for sharing .
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
If the plugin provides you value, you can support me with a donation Paypal.
Wiki is available here.
Zigbee for Domoticz FAQ
Who is online
Users browsing this forum: No registered users and 1 guest