DHT22 random fake temperature

Hi friend. I have a DHT22 sensor temperature (wired to raspberry with hassio).
The sensor is OK but occasionally (1 time every 2/3 hours) it get a fake relevation (temperature -9.9 C) and in a few seconds it returns OK.
Probably I have to buy another DHT22.
The problem is that when it fails, the “climate switch” (i configured climate.generic and gpio switch wired to relay) start my heating system and after few seconds, when the temperature detection return to normal, it stop.
Any idea to avoid the problem? Do I have to buy another sensor?

I had mine read 0 on first read after it had been powered down. As a quick and dirty fix you could put in a condition that makes sure the temperature is within expected range.

I.e. I had mine not trigger is the temperature was below 5, as I’m sure that my bedroom would never get tho low.

Yeah the DHT implementation on the HA raspi is quite prone to false readings, even with very short leads.

Here are a couple of options:

I ) use an ESP board to talk to your DHT sensor and report that via mqtt to hassio. Esphomelib can be easily configured with yaml files to do this: https://esphomelib.com/esphomeyaml/guides/getting_started_hassio.html


II) use an outlier filter on your current sensor. https://www.home-assistant.io/components/sensor.filter/

1 Like

Great!!! Filter (outlier) is the way!!!
Very very thanks!!!

I’ve had a dh22 sensor along with a NodMCU and if I’m correct readings much be x-seconds apart and can fluctuate even between those. So what I did (and it’s write this out from memory right now) is read it each 6 seconds 10 times and then averaging out those values and discarding some really odd ones in there (let’s say -10 or +10 difference from the previous) and that avarage was always really accurate with my old home thermostat and another digital temp meter I bought to check up on it. most of the times by 0.5 (they where all sometimes 0.5 off from each other which seems to be ‘normal’)

This will also prevent systems from triggering from something simple as a draft because the front door was open or something :slight_smile:

(now I just bought a NEST because I had some extra earnings on my 3d printing hobby which offers more then ‘on/off’ along with a great looking fancy device)

Hey guys,
Please see print screen attached.

I have the same issues - DHT22 temperature dropping -9 degrees C about 50% of all reading. So filter would not help here because average would be HIGH 18 / LOW 9 / AVERAGE / 14 or something.

Could this be cabling /long distance/ issue, or just something with the python code.

Thanks to all.
Today It seems that with outlier filter the issue get off.
My fake read was more sporadic, one every 2/3 hours. In the next days I will confirm if I’m OK

How long are your cables?

Are you using a ~4K7 pull-up resistor on the data line?

Yes 4.7k. My cable is short: less than 50cm

That was a reply to @Ivan_Petrov. Not you @corrobor.

You may need to make your filter radius smaller if you are still seeing sporadic false readings.

I set 3 minutes and radius 3. What do you think?

That should be ok.

There is one problem with this filter though. If the first reading HA makes after a restart is the false reading it will start using that as the mean value to check from and not ever update the correct value as they are all rejected by the filter. The only way to fix this is restart HA and hope you get the correct value on restart.

This annoyed me so much with multiple DHT sensors that I ended up using the ESP method I mentioned above. This has been working perfectly.

Ok thank for this precisation.

Cable is 11 meters Cat5e, 4.7K between data and 5V.
white green -> data
green -> GND
orange -> 5V
Temperature readings after one night:

The high is the real temperature, the droppings are fake.
Probably it’s the RPI or something issue, I could try some Home Assistant filter, but I am not sure if that will be accurate?.. I have NodeMCU with esp8266 board waiting on my desk so I guess I will have to go with DHT22 -> nodemcu -> wifi -> MQTT -> HASS too.

Do this. It works amazingly well compared to the HA component.

Esphomelib addon makes it very easy. You configure everything in YAML.

There’s a wifi signal strenght monitoring component ans well as auto discovery support for HA.

Here’s one of my configuration files as an example:

  name: roof_dht
  platform: ESP8266
  board: d1_mini

  ssid: 'YOUR_SSID'
  password: !secret wifi_pwd
    static_ip: # you dont have to do this but it helps.

  discovery: true
  discovery_prefix: homeassistant
  broker: ''
  username: !secret mqtt_usr
  password: !secret mqtt_pwd

  level: WARN # comment this out until you are sure it all works then re-uplaod with it not commented out to reduce network traffic.

  password: !secret esp_pwd   # over the air update support!

  - platform: status
    name: "Roof Space DHT Status"

  - platform: wifi_signal
    name: "Roof Space DHT WiFi Signal"
    update_interval: 15s
  - platform: dht
    pin: D5
    model: DHT22
      name: "Roof Space Temperature"
      name: "Roof Space Humidity"
    update_interval: 15s

Thanks, I will start testing it.
Meanwhile I will try measuring if 5V is 5v after 10 meters ftp, probably I could adjust it with external power supply and common ground … could try other resistors too 4.7 - 10K… although this might only be wasted time. But its just because I prefer hardwire than wifi.

In this way I can plug more temperature sensor without wire? I would like to put 2 DHT22 in another rooms but is impossible to wired it…
What I have to buy?

I use one of these per room.

You will also need a 5V power supply (1 Amp will be more than enough) and some sort of vented case.

Perfect. And this is connected to DHT22 by wire and to raspberry / hassio by wifi?

Correct. MQTT over wifi to HA.