theengs / decoder

Efficient, portable and lightweight library for Internet of Things payload decoding.
https://decoder.theengs.io
GNU General Public License v3.0
119 stars 38 forks source link

Incorrect humidity value for Govee H5072/75 when temperature below 0 degree celsius #454

Closed radioyear closed 9 months ago

radioyear commented 9 months ago

Hi,

I noticed that the reading for the humidity value for a Govee H5075 jumps to a wrong value when temperature falls below 0 degree celsius. The humidity value in the Govee app meanwhile remains correct.

I think this happens because in case of negative temperature values you have to substract 8388608 (0x800000) from the basenumber to get the right temperature value. The humidity value then also has to be derived from this corrected basenumber. But in H5072_json.h the original basenumber is used for humidity and we get a wrong value.

With this change in H5072_json.h I get correct humidity readings:

const char* _H5072_json = [...], \"hum\":{\"condition\":[\"manufacturerdata\",6,\"bit\",3,0],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",6,6,false,false],\"post_proc\":[\"%\",1000,\"/\",10]},\"_hum\":{\"condition\":[\"manufacturerdata\",6,\"bit\",3,1],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",6,6,false,false],\"post_proc\":[\"-\",8388608,\"%\",1000,\"/\",10]},....

  "hum":{
     "condition":["manufacturerdata", 6, "bit", 3, 0],
     "decoder":["value_from_hex_data", "manufacturerdata", 6, 6, false, false],
     "post_proc":["%", 1000, "/", 10]
  },
  "_hum":{
     "condition":["manufacturerdata", 6, "bit", 3, 1],
     "decoder":["value_from_hex_data", "manufacturerdata", 6, 6, false, false],
     "post_proc":["-", 8388608, "%", 1000, "/", 10]
  },

But maybe there is a more elegant way to fix this.

Harald

DigiH commented 9 months ago

Hi @radioyear

Thanks for this info. I'm only on my phone until tomorrow evening, but could you try the following for the single existing humidity property

"hum":{
     "decoder":["value_from_hex_data", "manufacturerdata", 6, 6, false, false],
     "post_proc":["&", 8388607, "%", 1000, "/", 10]
  }, 

Which should mask the highest bit of the first byte to allow for the correct humidity with positive and negative temperatures.

Note to myself: The same fix needs to be applied to H5102

radioyear commented 9 months ago

Hi @DigiH,

I tried your solution and it's working. Humidity values are correct now with positiv and negative temperatures. Nice, thank you :)

Harald

DigiH commented 9 months ago

Thanks for the confirmation @radioyear !

I'll merge the fix(es) tomorrow night.

DigiH commented 9 months ago

Closing as the fix has been merged into development.

https://github.com/theengs/decoder/commit/0284e91bb8be4968cf3055810a055e76b9406de2