ESP32, DHT-11 and DHT-22 Unknown Values reported

I have and ESP32 with DHT sensors attached and all the sensors more often than not report unknow readings. I’ve tried different sensors, checked wiring and connections.
Sensors I have have a pull up resistor on them. Attaching another made no difference.

Log shows.

[16:59:26][D][dht:048]: Got Temperature=-25.1°C Humidity=33.7%
[16:59:26][D][sensor:094]: 'Garage Refrigerator Freezer Temperature': Sending state -23.48712 °C with 1 decimals of accuracy
[16:59:26][D][sensor:094]: 'Garage Refrigerator Freezer Humidity': Sending state 33.70000 % with 0 decimals of accuracy
[16:59:32][W][dht:163]: Waiting for DHT communication to clear failed!
[16:59:32][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[16:59:32][D][sensor:094]: 'Garage Refrigerator Refrigerator Temperature': Sending state nan °C with 0 decimals of accuracy
[16:59:32][D][sensor:094]: 'Garage Refrigerator Refrigerator Humidity': Sending state nan % with 0 decimals of accuracy
[16:59:32][W][component:214]: Component dht.sensor took a long time for an operation (0.05 s).
[16:59:32][W][component:215]: Components should block for at most 20-30ms.
[16:59:38][D][dht:048]: Got Temperature=-13.6°C Humidity=37.9%
[16:59:38][D][sensor:094]: 'Garage Refrigerator Deep Freezer Temperature': Sending state -13.60000 °C with 1 decimals of accuracy
[16:59:38][D][sensor:094]: 'Garage Refrigerator Deep Freezer Humidity': Sending state 37.90000 % with 0 decimals of accuracy
[16:59:46][D][text_sensor:064]: 'Garage Refrigerator Uptime': Sending state '2d 20h 55m 53s'
[16:59:46][D][sensor:094]: 'Garage Refrigerator Uptime': Sending state 248153.45312 s with 0 decimals of accuracy
[16:59:51][D][sensor:094]: 'Garage Refrigerator WiFi Strength': Sending state -39.00000 dBm with 0 decimals of accuracy
[17:00:26][W][dht:169]: Requesting data from DHT failed!
[17:00:26][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[17:00:26][D][sensor:094]: 'Garage Refrigerator Freezer Temperature': Sending state nan °C with 1 decimals of accuracy
[17:00:26][D][sensor:094]: 'Garage Refrigerator Freezer Humidity': Sending state nan % with 0 decimals of accuracy
[17:00:32][W][dht:163]: Waiting for DHT communication to clear failed!
[17:00:32][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[17:00:32][D][sensor:094]: 'Garage Refrigerator Refrigerator Temperature': Sending state nan °C with 0 decimals of accuracy
[17:00:32][D][sensor:094]: 'Garage Refrigerator Refrigerator Humidity': Sending state nan % with 0 decimals of accuracy
[17:00:32][W][component:214]: Component dht.sensor took a long time for an operation (0.06 s).
[17:00:32][W][component:215]: Components should block for at most 20-30ms.

Code for ESP32 is

substitutions:
  v_friendly_name: Garage Refrigerator

esphome:
  name: esphome-web-a8c23c
  friendly_name: ${v_friendly_name}

# Throttle writing parameters to the internal flash memory to reduce ESP memory wear / degradation
preferences:
  flash_write_interval: 15min


esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXXXXXX"

ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "XXXXXXXXX"
    password: "XXXXXXX"

text_sensor:

  # Send IP Address
  - platform: wifi_info
    ip_address:
      name: ${v_friendly_name} IP Address

  # Send Uptime in raw seconds
  - platform: template
    name: ${v_friendly_name} Uptime
    id: uptime_human
    icon: mdi:clock-start

captive_portal:
sensor:
  # Send WiFi signal strength & uptime to HA
  - platform: wifi_signal
    name: ${v_friendly_name} WiFi Strength
    update_interval: 60s

  # This is a bit of overkill. It sends a human readable 
  # uptime string 1h 41m 32s instead of 6092 seconds
  - platform: uptime
    name: ${v_friendly_name} Uptime
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            # Custom C++ code to generate the result
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

  # GET TEMP/HUMIDITY FROM DHT11
  - platform: dht
    pin: GPIO4
    model: DHT11
    temperature:
      name: "${v_friendly_name} Refrigerator Temperature"
      id: garage_refrigerator_temperature
      accuracy_decimals: 0

      filters:
         - exponential_moving_average:  
             alpha: 0.1
             send_every: 1

    humidity:
      name: "${v_friendly_name} Refrigerator Humidity"
      id: garage_refrigerator_humidity

    # the DHT11 can only be read every 1s. Use 1.3s to be safe.
    update_interval: 60s

  # GET TEMP/HUMIDITY FROM DHT22
  - platform: dht
    pin: GPIO16
    model: DHT22
    temperature:
      name: "${v_friendly_name} Freezer Temperature"
      id: garage_freezer_temperature
      accuracy_decimals: 1

      filters:
         - exponential_moving_average:  
             alpha: 0.1
             send_every: 1

    humidity:
      name: "${v_friendly_name} Freezer Humidity"
      id: garage_freezer_humidity

    # the DHT11 can only be read every 1s. Use 1.3s to be safe.
    update_interval: 60s

  # GET TEMP/HUMIDITY FROM DHT22
  - platform: dht
    pin: GPIO17
    model: DHT22
    temperature:
      name: "${v_friendly_name} Deep Freezer Temperature"
      id: garage_deep_freezer_temperature
      accuracy_decimals: 1

    humidity:
      name: "${v_friendly_name} Deep Freezer Humidity"
      id: garage_deep_freezer_humidity

    # the DHT11 can only be read every 1s. Use 1.3s to be safe.
    update_interval: 60s

switch:
  # Expose an ESP32 restart button to HA
  - platform: restart
    name: ${v_friendly_name} ESP32 Restart
    id: server_cabinet_fan_restart

web_server:
  port: 80

@hossman12
Did you figure this out?
I have the same issue that just started. Sometimes when I reboot the temp comes back but eventually starts reporting this message again. Might be a bad sensor but looking at other potential issues too since I can’t easily replace it.

Main thing I figured out as these were not the correct type of sensor to use for my application. I switched to using the Dallas One-Wire sensor for inside the fridge and freezer. so far they are working great after calibration. I did keep one dht-11 as an ambient sensor for the room and it is also working as expected