erdose / xiaomi-mi-lywsd03mmc

Xiaomi Mi BLE Temperature & Humidity Sensor
MIT License
26 stars 7 forks source link

Wrong Temperature when minus degrees #16

Closed suschmania closed 1 year ago

suschmania commented 1 year ago

Hi there, i never experienced this mistake as we never had minus degrees until last night. When the temperature drops below 0, then Domoticz displays values at around 6.552 - 6.554 °C. Even some sunlight is available at my balcony, the temperature seems to be "a bit" too high :)

I read out the temperature directly at the sensor via the telink flasher page: there the temperature is correct (but the timestamp is wrong, I don't care about that). Where is the problem? Is this a mistake by Domoticz or via the python script? I am using the ATC1441 format.

Thanks for help

11:06:22: Hardware Revision String: B1.4 11:06:22: Detected custom Firmware 11:06:22: Hardware Version: LYWSD03MMC B1.4, Software Version: 3.8, Sensor: SHTC3 11:06:22: Custom config: [128, 0, 0, 0, 40, 12, 169, 124, 49, 128, 60]

1_correct 1_incorrect

suschmania commented 1 year ago

Update: with the original firmware this bug is not existing. The correct values are transferred and i can see in Domoticz -0,23 °C (as an example).

erdose commented 1 year ago

Sorry, but I can't maintain this repo already I don't use Domoticz. Try to this int conversion: temperature = int(bytes[8] * 256 + bytes[9]) / 10 (line: 42) If it works, create a pull request and I will merge it.

suschmania commented 1 year ago

Update form my side: The behaviour is still the same. I changed the line you mentioned but that changed nothing in Domoticz. + degrees are fine, - degrees turn out to be somewhere at 6.530 degrees (when it should show -18).

erdose commented 1 year ago

What is the temperature value in log file? The logger module saves every data. By default is loginfo.log. It is a good starting point.

suschmania commented 1 year ago

The value in the log file is as the same as in Domoticz. I changed the location into the freezer to compare:

Outside:

2022-12-01 22:55:04 INFO Discovery data from MAC: A4:C1:38:XX:XX:XX 2022-12-01 22:55:04 INFO Temp: 6.9 2022-12-01 22:55:04 INFO Hum: 43 2022-12-01 22:55:04 INFO Comfort type: 1 2022-12-01 22:55:04 INFO Battery level: 40 2022-12-01 22:55:04 INFO Voltage: 2.562

Freezer:

2022-12-01 23:00:04 INFO Discovery data from MAC: A4:C1:38:XX:XX:XX 2022-12-01 23:00:04 INFO Temp: 6549.2 2022-12-01 23:00:04 INFO Hum: 42 2022-12-01 23:00:04 INFO Comfort type: 1 2022-12-01 23:00:04 INFO Battery level: 28 2022-12-01 23:00:04 INFO Voltage: 2.457

THe same behaviour I found when I use a different sensor, a CGDK2: LCD, "Qingping Temp & RH Monitor Lite", also flashed with the latest custom firmware 3.8.

Temperature should be -10 but the log says 6546.8

2022-12-01 23:15:09 INFO Discovery data from MAC: 58:2D:34:XX:XX:XX 2022-12-01 23:15:09 INFO Temp: 6546.8 2022-12-01 23:15:09 INFO Hum: 38 2022-12-01 23:15:09 INFO Comfort type: 2 2022-12-01 23:15:09 INFO Battery level: 66 2022-12-01 23:15:09 INFO Voltage: 2.802

a temperature "Nearly" below 0 degrees has a value of around 6552. Very strange

flosennn commented 1 year ago

Shift temperature by 15 right to check the sign bit ((temperature>>15)&1) and if it is 1, then -(2^16-temperature) is your value.

Before the devision by 10.

suschmania commented 1 year ago

I switched to a different method to receive the data, "MiTemperature2". Can't verify this solution anymore. Thank you for your afford!