DHTNew: Problem: wrong values at negative temperatures an ESP8266 and DHT22
I use the DHT22 in combination with an ESP8266 and this lib. When having negative temperatures, the resulting value of getTemperature() is -3278.6 at -0.1°C To fix negatives values a recalculation is nessecary:
#include <stdint.h>
if(temperature < 0)
{
temperature = (temperature = (INT16_MAX - temperature*-10)*-0.1; - temperature*-10)*-0.1;
}
This was tested with Arduino IDE against lib version 0.4.3, installed via Arduino library manager.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (15 by maintainers)
This is a magic of C++, real transform equivalent:
temperature = -temperature - 3276.7
It because AM2301 has inside not DHT22(1) but AHT10.
Home assistant correction:
value_template: “{% if value_json.temp_c <3000 %}{{ (-value_json.temp_c - 3276.7) | round(1)}}{% else %}{{ value_json.temp_c | round(1)}}{% endif %}”