Noisy temperature readings from ESP32 & ESP8266

Some of my temperature sensors have started returning very noisy results.

This is my config file

esphome:
  name: switch_standing_desk_studio
  platform: ESP32
  board: esp32cam

<<: !include wifi.yaml

captive_portal:

logger:

api:

ota:

sensor:
  - platform: dht
    model: DHT22
    pin: GPIO14
    temperature:
      name: "Studio temperature"
    humidity:
      name: "Studio humidity"
    update_interval: 60s

switch:
  - platform: gpio
    pin: GPIO25
    id: standing
  - platform: template
    name: "Raise standing desk"
    icon: "mdi:human"
    turn_on_action:
    - switch.turn_on: standing
    - delay: 12000ms
    - switch.turn_off: standing
  - platform: gpio
    pin: GPIO26
    id: sitting
  - platform: template
    name: "Lower standing desk"
    icon: "mdi:table-chair"
    turn_on_action:
    - switch.turn_on: sitting
    - delay: 12000ms
    - switch.turn_off: sitting


<<: !include mqtt.yaml

I am unable to use the filter median option with this particular sensor

  [filters] is an invalid option for [sensor.dht]. Please check the indentation.
  filters:  [source Switch standing desk studio.yaml:50]
    - median: 
        window_size: 5
        send_every: 5
        send_first_at: 1

What troubleshooting options do I have? This is a new problem but could it be a faulty dht sensor? Would reducing the update frequency help? Can I solve this within Home Assistant or would that be an anti-pattern?

I’m following this thread b/c I see the same spiky pattern from my sensors sometimes.
For me, it’s whenever I change WiFi access points (turn on a second one, turn off the first, so all the stations have to reconnect to the second one). So maybe it has something to do with WiFi reconnects.
It just doesn’t make sense how something like that would manufacture wacky data.

You have to put the filters under each of the temperature and humidity sections, like this:

sensor:
  - platform: dht
    pin: D5
    model: DHT22  ### <--- also note this
    update_interval: 15s
    temperature:
      name: "Dining Room Temperature"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15
    humidity:
      name: "Dining Room Humidity"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15

Also it may be worthwhile setting the model option. Auto detection can be flakey.

How long is the cabling to the DHT?

Also do you have a 4K7 pullup resistor between Vcc and the Data pin?

2 Likes

This can very well be RF interference. The WiFi signals can induce currents in the electronics of the sensor. Try to get the sensor further away from the ESP. Even if the sensor is on a PCB shield, do NOT plug it directly onto the ESP. Try to shield it with aluminum foil. Change its orientation, i.e. turn it so that it shows minimal surface when seen from the ESP.

2 Likes

That might explain what I’m seeing, too. Thanks! I’ll do some RF isolation and see.

You might also try a better power supply. I’m amazed at how many issues are caused by this.

It is true that ESPs often suffer from short voltage drops in their power supply. But my experience is that this usually results in brown outs of the MCU itself. I never had noisy sensor readings as a result.

Brown outs usually happen when the power consumption of the ESP spikes. This in turn is often the result of WiFi transmission bursts.
My recommendation is to buffer the 3.3V side of the D1 mini with a 47uF Tantalum capacitor. Larger capacitors are not really relevant but using a Tantalum type is (they can deliver much faster). Out of painful experience I do not operate any ESP without such a capacitor anymore.

But as said: If the ESP is generally stable I don’t think that the observed behavior is the result of a weak power supply.

Thank you, I have added the filter in the correct place :man_facepalming:
To answer your other questions, short distance from DHT sensor to ESP board and yes to pullup resistor

Thank you for the RF interference explanation, that wasn’t something I had considered and would explain the issue. Cheers team!

I got similar noise when powered D1 mini via 3.3v pin but not when used 5v pin. Try different power supply even.

Or at least install capacitor at sensor side: anywhere from 50-100uF(or above) will do for testing. And maybe parallel to it additional 100nF.

Is the 2 in parallel to reduce the resistance and inductance of the capacitor, as I would assume adding 100nF to 50uF really doesn’t make much difference to capacitance, or does these 2 different values give different frequency filtering? See what you describe in datasheets and haven’t been able to find out why.

Electrolytic capacitor has large capacitance, but also high impedance (=HF resistance), so it’s capable of filtering out only short voltage drops (flattens the voltage curve). That’s why you add a smaller, different technology capacitor, which has reversed specs: small capacitance, but also small HF resistance. So 100nF is filtering HF noise spikes.

2 Likes

This is a good explanation: https://youtu.be/BcJ6UdDx1vg

3 Likes