DHT Temperature+Humidity Sensor

The DHT Temperature+Humidity sensor allows you to use your

sensors with ESPHome.

Image
DHT22 Temperature & Humidity Sensor.

The DHT22 and DHT11 require external pull up resistors on the data line. To do this, solder a resistor with about 4.7kΩ (anything in the range from 1kΩ to 10kΩ probably works fine, but if you’re having issues try the 4.7kΩ recommended by the manufacturer) between DATA and 3.3V.

Image
# Example configuration entry
sensor:
  - platform: dht
    pin: D2
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 60s

Configuration variables

  • pin (Required, Pin): The pin where the DHT bus is connected.

  • temperature (Required): The information for the temperature sensor.

  • humidity (Required): The information for the humidity sensor

  • model (Optional, int): Manually specify the DHT model, can be one of AUTO_DETECT, DHT11, DHT22, DHT22_TYPE2, AM2302, RHT03, SI7021, AM2120 and helps with some connection issues. Defaults to AUTO_DETECT. Auto detection doesn’t work for the SI7021 chip.

  • update_interval (Optional, Time): The interval to check the sensor. Defaults to 60s.

Sensor halting

A possible solution is to use a GPIO port as power supply and restart the sensor on error.

switch:
  - platform: gpio
    pin: GPIO12
    id: pwrsensor
    name: "Power for sensor"
    restore_mode: ALWAYS_ON

sensor:
  - platform: dht
    pin: GPIO14
    temperature:
      name: "Temperature"
      id: current_temperature
      on_value:
        then:
          - if:
              condition:
                - lambda: "return isnan(x);"
              then:
                - switch.turn_off: pwrsensor
                - delay: 5s
                - switch.turn_on: pwrsensor
    humidity:
      name: "Humidity"
      id: current_humidity
    update_interval: 30s
    model: AM2302

Note

The default accuracy_decimals value of the humidity levels is 0, as the DHT11 for which this was originally written does not have a higher resolution. All other DHT sensors have a higher resolution, it’s worth to configure them with accuracy_decimals: 1.

If you’re seeing lots of invalid temperature/humidity warnings in the logs, try manually setting the DHT model with the model: configuration variable. Other problems could be wrong pull-up resistor values on the DATA pin or too long cables.

If you’re using a DHT module with an external pull-up resistor and seeing invalid temperature/humidity warnings in the logs, set pullup: false under your pin configuration.

See Also