ESP32 with DHT22 - Sensor not detected

Hey all,

I’m new to ESPHome and have been trying to get some basic experience under my belt before moving forward with a simple hydroponics setup. My goal with this straightforward initial project has been to connect a DHT22 temperature and humidity sensor to HA using an ESP32 via ESPHome.

Unfortunately, I’ve run into a roadblock, and I’m not sure where to go from here despite scouring resources online. I’ve been using this tutorial guide along with a few others to help work through things.

So far I’ve:

  1. installed ESPHome and created a new node via the web UI
  2. manually downloaded the bin file to install and flashed the ESP32 using esphome flasher
  3. went to Settings > Integrations and added the node manually via its IP address on my network (router doesn’t support mDNS) which allowed HA to detect the device
  4. applied a manual IP to the device via ESPHome to get ESPHome to recognize the device as online
  5. wired the DHT22 to my ESP32 (data pin to GPIO2 and powered via 3v3)

With the steps above I can see my device online in ESPHome, but according to the tutorials it seems as if the sensor should be automatically detected from this point. I don’t see any new sensor in HA and don’t see any sensor measurements via the ESPHome log or the serial logs for the device.

Log for the device is as follows:

INFO Reading configuration /config/esphome/testtemp32.yaml...
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from 192.168.0.28 using esphome API
INFO Successfully connected to 192.168.0.28
[18:33:43][I][app:102]: ESPHome version 2023.3.2 compiled on Apr 16 2023, 18:59:03
[18:33:43][C][wifi:504]: WiFi:
[18:33:43][C][wifi:362]:   Local MAC: E0:5A:1B:A1:24:64
[18:33:43][C][wifi:363]:   SSID: 'Aperture Science'[redacted]
[18:33:43][C][wifi:364]:   IP Address: 192.168.0.28
[18:33:43][C][wifi:366]:   BSSID: 02:83:CC:E0:6A:19[redacted]
[18:33:43][C][wifi:367]:   Hostname: 'testtemp32'
[18:33:43][C][wifi:369]:   Signal strength: -29 dB ▂▄▆█
[18:33:43][C][wifi:373]:   Channel: 11
[18:33:43][C][wifi:374]:   Subnet: 255.255.255.0
[18:33:43][C][wifi:375]:   Gateway: 192.168.0.1
[18:33:43][C][wifi:376]:   DNS1: 0.0.0.0
[18:33:43][C][wifi:377]:   DNS2: 0.0.0.0
[18:33:43][C][logger:293]: Logger:
[18:33:43][C][logger:294]:   Level: DEBUG
[18:33:43][C][logger:295]:   Log Baud Rate: 115200
[18:33:43][C][logger:296]:   Hardware UART: UART0
[18:33:43][C][captive_portal:088]: Captive Portal:
[18:33:43][C][mdns:108]: mDNS:
[18:33:43][C][mdns:109]:   Hostname: testtemp32
[18:33:43][C][ota:093]: Over-The-Air Updates:
[18:33:43][C][ota:094]:   Address: 192.168.0.28:3232
[18:33:43][C][ota:097]:   Using Password.
[18:33:43][C][api:138]: API Server:
[18:33:43][C][api:139]:   Address: 192.168.0.28:6053
[18:33:43][C][api:141]:   Using noise encryption: YES
[18:33:51][D][api:102]: Accepted 192.168.0.8
[18:33:51][W][api.connection:071]: 192.168.0.8: Socket operation failed: CONNECTION_CLOSED errno=128
[18:34:51][D][api:102]: Accepted 192.168.0.8
[18:34:51][W][api.connection:071]: 192.168.0.8: Socket operation failed: CONNECTION_CLOSED errno=128
[18:35:51][D][api:102]: Accepted 192.168.0.8
[18:35:51][W][api.connection:071]: 192.168.0.8: Socket operation failed: CONNECTION_CLOSED errno=128
[18:36:51][D][api:102]: Accepted 192.168.0.8
[18:36:51][W][api.connection:071]: 192.168.0.8: Socket operation failed: CONNECTION_CLOSED errno=128

My config entry for the device is as follows:

esphome:
  name: testtemp32
  friendly_name: testtemp32

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xyz"
ota:
  password: "xyz"

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

  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.28
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Testtemp32 Fallback Hotspot"
    password: "xyz"

sensor:
  - platform: dht
    pin: GPIO2
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 30s
    model: DHT22

captive_portal:

A picture of the wiring setup:

I notice a repeating error in my log, but haven’t been able to figure out how to troubleshoot it, though I can’t even be sure it’s relevant to the sensor not being detected.

I didn’t expect to hit a wall with how simple this intro project looked from reading instructions online, but I’m genuinely really excited to keep moving forward! Any thoughts from the community on how best to proceed?

This how my DHT22 is setup in the ESPHome config. I am using a Wemos D1 Mini so pin assignment will be different. D3 on my board translates to GPIO0. May also change your pin to D4.

All my sensor data is after captive_portal:

captive_portal:
    
sensor:
  - platform: dht
    model: DHT22_TYPE2
    pin: D3
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: 60s


No luck unfortunately.

I tried using both “DHT22” and “DHT22_TYPE2” as models with no change. I also moved it up in the order (does it matter?) to right after the platform line with no change. Moving the code down below captive_portal also had no effect.

Interestingly, I get an error when I try to use D4 as the pin designation which is why I had switched to using the GPIO format initially:

INFO Reading configuration /config/esphome/testtemp32.yaml...
Failed config

sensor.dht: [source /config/esphome/testtemp32.yaml:43]
  platform: dht
  model: DHT22_TYPE2
  
  Cannot resolve pin name 'D4' for board esp32dev.
  pin: D4
  temperature: 
    name: Living Room Temperature
  humidity: 
    name: Living Room Humidity
  update_interval: 30s

Not sure where that difference comes from either as the tutorials also use the D format. Thanks for your reply though!

D4 is not a valid Pin name for that board type.

Use GPIOn instead (where n is the GPIO number).

And no, the order does not matter. Only the indentation. Except for filters. Filters are applied in order they are listed.

Also if that DHT board does not include a data pin pull-up resistor you have to add one. + to out, any value between 4.7KΩ to 10KΩ should do.

Thanks for the clarification regarding the ordering of those lines!

I also did confirm that this DHT board has a pull-up resistor included!