ESPHome with DHT22 and 128x32 OLED Display

Did you try other pins for the DHT22?

lamda because of correction on sensor results.
I’ve an infrared Thermo with correct data and the 0 will be changed to the difference of the messurement.
In result: lambda: return x -+ defference value
So I get correct values.

An example of my other sensor (BME280)
- lambda: return x - 4.5;

I must use D1 and D2 (SCL & SDA) for i2c bus and the display.
So I need another pin to receive results of the DHT22, I find D4 like here in the forum.

Now I disconncet the display and thy normal with D2, same results, always NAN.

Hi nickrout,

here is a sample log from the sensor
compiling and run. The display is actually not plugged in (error down in log).

Log shows error because no answer from DHT22…
Wiring is OK
Pin1 = 5V
PIN2 = DATA (4,7kOhm against +5V Pin1) to D4 / GPIO2
PIN3 = nothing
Pin4 = Ground
tried out 3 different DHT22 same result (same error message)
tried out another D1 mini same result

USB Power consumption ~ 80mA @ 5.1V from Desktop
Same on USB-Power-Plug with 2.4A ~80mA @5,09V
Power is OK

INFO ESPHome 2023.5.5
INFO Reading configuration /config/esphome/law-sensor-th03.yaml...
INFO Detected timezone 'Europe/Berlin'
INFO Generating C++ source...
INFO Compiling app...
Processing law-sensor-th03 (board: d1_mini; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- ESPAsyncTCP-esphome @ 1.2.3
|   |-- Hash @ 1.0
|   |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
|-- Wire @ 1.0
Compiling /data/law-sensor-th03/.pioenvs/law-sensor-th03/src/esphome/components/api/api_connection.cpp.o
..........
Compiling /data/law-sensor-th03/.pioenvs/law-sensor-th03/FrameworkArduino/umm_malloc/umm_malloc.cpp.o
Compiling /data/law-sensor-th03/.pioenvs/law-sensor-th03/FrameworkArduino/umm_malloc/umm_poison.c.o
Archiving /data/law-sensor-th03/.pioenvs/law-sensor-th03/libFrameworkArduino.a
Linking /data/law-sensor-th03/.pioenvs/law-sensor-th03/firmware.elf
RAM:   [======    ]  59.7% (used 48936 bytes from 81920 bytes)
Flash: [=====     ]  53.1% (used 554209 bytes from 1044464 bytes)
Building /data/law-sensor-th03/.pioenvs/law-sensor-th03/firmware.bin
esp8266_copy_factory_bin(["/data/law-sensor-th03/.pioenvs/law-sensor-th03/firmware.bin"], ["/data/law-sensor-th03/.pioenvs/law-sensor-th03/firmware.elf"])
======================== [SUCCESS] Took 207.70 seconds ========================
INFO Successfully compiled program.
INFO Connecting to 192.168.168.246
INFO Uploading /data/law-sensor-th03/.pioenvs/law-sensor-th03/firmware.bin (558368 bytes)
INFO Compressed to 383600 bytes
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.168.246 using esphome API
INFO Successfully connected to 192.168.168.246
[14:46:44][I][app:102]: ESPHome version 2023.5.5 compiled on Jun 19 2023, 14:44:16
[14:46:44][C][wifi:505]: WiFi:
[14:46:44][C][wifi:363]:   Local MAC: E8:68:E7:6D:CA:FE
[14:46:44][C][wifi:364]:   SSID: 'LAWHOME'[redacted]
[14:46:44][C][wifi:365]:   IP Address: 192.168.168.246
[14:46:44][C][wifi:366]:   BSSID: 5C:49:79:F2:ED:D3[redacted]
[14:46:44][C][wifi:368]:   Hostname: 'law-sensor-th03'
[14:46:44][C][wifi:370]:   Signal strength: -47 dB ▂▄▆█
[14:46:44][C][wifi:374]:   Channel: 11
[14:46:44][C][wifi:375]:   Subnet: 255.255.255.0
[14:46:44][C][wifi:376]:   Gateway: 192.168.168.1
[14:46:44][C][wifi:377]:   DNS1: 0.0.0.0
[14:46:44][C][wifi:378]:   DNS2: 0.0.0.0
[14:46:44][C][logger:301]: Logger:
[14:46:44][C][logger:302]:   Level: VERY_VERBOSE
[14:46:44][C][logger:303]:   Log Baud Rate: 115200
[14:46:44][C][logger:305]:   Hardware UART: UART0
[14:46:44][C][i2c.arduino:053]: I2C Bus:
[14:46:44][C][i2c.arduino:054]:   SDA Pin: GPIO5
[14:46:44][C][i2c.arduino:055]:   SCL Pin: GPIO4
[14:46:44][C][i2c.arduino:056]:   Frequency: 50000 Hz
[14:46:44][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[14:46:44][I][i2c.arduino:069]: Results from i2c bus scan:
[14:46:44][I][i2c.arduino:071]: Found no i2c devices!
[14:46:44][C][homeassistant.time:010]: Home Assistant Time:
[14:46:44][C][homeassistant.time:011]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[14:46:44][C][dht:017]: DHT:
[14:46:44][C][dht:018]:   Pin: GPIO2
[14:46:44][C][dht:024]:   Model: DHT22 (or equivalent)
[14:46:44][C][dht:027]:   Update Interval: 10.0s
[14:46:44][C][dht:029]:   Temperature 'LAW sensor TH03 Temperature'
[14:46:44][C][dht:029]:     Device Class: 'temperature'
[14:46:44][C][dht:029]:     State Class: 'measurement'
[14:46:44][C][dht:029]:     Unit of Measurement: '°C'
[14:46:44][C][dht:029]:     Accuracy Decimals: 1
[14:46:44][C][dht:030]:   Humidity 'LAW sensor TH03 Humidity'
[14:46:44][C][dht:030]:     Device Class: 'humidity'
[14:46:44][C][dht:030]:     State Class: 'measurement'
[14:46:44][C][dht:030]:     Unit of Measurement: '%'
[14:46:44][C][dht:030]:     Accuracy Decimals: 1
[14:46:44][C][ssd1306_i2c:023]: I2C SSD1306
[14:46:44][C][ssd1306_i2c:023]:   Rotations: 0 °
[14:46:44][C][ssd1306_i2c:023]:   Dimensions: 128px x 64px
[14:46:44][C][ssd1306_i2c:024]:   Address: 0x3C
[14:46:44][C][ssd1306_i2c:025]:   Model: SH1106 128x64
[14:46:44][C][ssd1306_i2c:026]:   Reset Pin: GPIO16
[14:46:44][C][ssd1306_i2c:027]:   External VCC: NO
[14:46:44][C][ssd1306_i2c:028]:   Flip X: YES
[14:46:44][C][ssd1306_i2c:029]:   Flip Y: YES
[14:46:44][C][ssd1306_i2c:030]:   Offset X: 0
[14:46:44][C][ssd1306_i2c:031]:   Offset Y: 0
[14:46:44][C][ssd1306_i2c:032]:   Inverted Color: NO
[14:46:45][C][ssd1306_i2c:033]:   Update Interval: 1.0s
[14:46:45][E][ssd1306_i2c:036]: Communication with SSD1306 failed!
[14:46:45][C][captive_portal:088]: Captive Portal:
[14:46:45][C][mdns:108]: mDNS:
[14:46:45][C][mdns:109]:   Hostname: law-sensor-th03
[14:46:45][V][mdns:110]:   Services:
[14:46:45][V][mdns:112]:   - _esphomelib, _tcp, 6053
[14:46:45][V][mdns:114]:     TXT: friendly_name = law-sensor-th03
[14:46:45][V][mdns:114]:     TXT: version = 2023.5.5
[14:46:45][V][mdns:114]:     TXT: mac = e868e76dcafe
[14:46:45][V][mdns:114]:     TXT: platform = ESP8266
[14:46:45][V][mdns:114]:     TXT: board = d1_mini
[14:46:45][V][mdns:114]:     TXT: network = wifi
[14:46:45][C][ota:093]: Over-The-Air Updates:
[14:46:45][C][ota:094]:   Address: 192.168.168.246:8266
[14:46:45][C][ota:097]:   Using Password.
[14:46:45][C][api:138]: API Server:
[14:46:45][C][api:139]:   Address: 192.168.168.246:6053
[14:46:45][C][api:141]:   Using noise encryption: YES
[14:46:45][C][sntp:053]: SNTP Time:
[14:46:45][C][sntp:054]:   Server 1: '0.pool.ntp.org'
[14:46:45][C][sntp:055]:   Server 2: '1.pool.ntp.org'
[14:46:45][C][sntp:056]:   Server 3: '2.pool.ntp.org'
[14:46:45][C][sntp:057]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[14:46:45][VV][scheduler:225]: Running interval 'update' with interval=10000 last_execution=7993 (now=17993)
[14:46:45][W][dht:169]: Requesting data from DHT failed!
[14:46:45][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[14:46:45][V][sensor:043]: 'LAW sensor TH03 Temperature': Received new state nan
[14:46:45][VV][sensor.filter:014]: Filter(0x3fff4c44)::input(nan)
[14:46:45][VV][sensor.filter:282]: LambdaFilter(0x3fff4c44)::new_value(nan) -> nan
[14:46:45][VV][sensor.filter:021]: Filter(0x3fff4c44)::output(nan) -> SENSOR
[14:46:45][D][sensor:093]: 'LAW sensor TH03 Temperature': Sending state nan °C with 1 decimals of accuracy
[14:46:45][V][sensor:043]: 'LAW sensor TH03 Humidity': Received new state nan
[14:46:45][VV][sensor.filter:014]: Filter(0x3fff50f4)::input(nan)
[14:46:45][VV][sensor.filter:282]: LambdaFilter(0x3fff50f4)::new_value(nan) -> nan
[14:46:45][VV][sensor.filter:021]: Filter(0x3fff50f4)::output(nan) -> SENSOR
[14:46:45][D][sensor:093]: 'LAW sensor TH03 Humidity': Sending state nan % with 1 decimals of accuracy
[14:46:45][V][component:204]: Component dht.sensor took a long time for an operation (0.08 s).
[14:46:45][V][component:205]: Components should block for at most 20-30ms.
[14:46:45][D][api:102]: Accepted 192.168.168.13
[14:46:45][VV][api.socket:696]: 192.168.168.13: Handshake complete!
[14:46:45][V][component:204]: Component api took a long time for an operation (0.29 s).
[14:46:45][V][component:205]: Components should block for at most 20-30ms.
[14:46:45][VV][api.service:476]: on_hello_request: HelloRequest {
  client_info: 'Home Assistant 2023.6.2'
  api_version_major: 1
  api_version_minor: 7
}
[14:46:45][V][api.connection:940]: Hello from client: 'Home Assistant 2023.6.2 (192.168.168.13)' | API Version 1.7
[14:46:45][VV][api.service:013]: send_hello_response: HelloResponse {
  api_version_major: 1
  api_version_minor: 8
  server_info: 'law-sensor-th03 (esphome v2023.5.5)'
  name: 'law-sensor-th03'
}
[14:46:45][VV][api.service:485]: on_connect_request: ConnectRequest {
  password: ''
}
[14:46:45][D][api.connection:959]: Home Assistant 2023.6.2 (192.168.168.13): Connected successfully
[14:46:45][VV][api.service:197]: send_get_time_request: GetTimeRequest {}
[14:46:45][VV][api.service:019]: send_connect_response: ConnectResponse {
  invalid_password: NO
}
[14:46:45][VV][api.service:628]: on_get_time_response: GetTimeResponse {
  epoch_seconds: 1687178805
}
[14:46:45][VV][time:027]: Got epoch 1687178805
[14:46:45][D][time:044]: Synchronized time: 2023-06-19 14:46:45
[14:46:45][VV][api.service:530]: on_device_info_request: DeviceInfoRequest {}
[14:46:45][VV][api.service:049]: send_device_info_response: DeviceInfoResponse {
  uses_password: NO
  name: 'law-sensor-th03'
  mac_address: 'E8:68:E7:6D:CA:FE'
  esphome_version: '2023.5.5'
  compilation_time: 'Jun 19 2023, 14:44:16'
  model: 'd1_mini'
  has_deep_sleep: NO
  project_name: ''
  project_version: ''
  webserver_port: 0
  bluetooth_proxy_version: 0
  manufacturer: 'Espressif'
  friendly_name: 'law-sensor-th03'
  voice_assistant_version: 0
}
[14:46:46][VV][api.service:539]: on_list_entities_request: ListEntitiesRequest {}
[14:46:46][VV][api.service:132]: send_list_entities_sensor_response: ListEntitiesSensorResponse {
  object_id: 'law_sensor_th03_temperature'
  key: 2381800359
  name: 'LAW sensor TH03 Temperature'
  unique_id: 'law-sensor-th03sensorlaw_sensor_th03_temperature'
  icon: ''
  unit_of_measurement: '°C'
  accuracy_decimals: 1
  force_update: NO
  device_class: 'temperature'
  state_class: STATE_CLASS_MEASUREMENT
  legacy_last_reset_type: LAST_RESET_NONE
  disabled_by_default
[14:46:46][VV][api.service:132]: send_list_entities_sensor_response: ListEntitiesSensorResponse {
  object_id: 'law_sensor_th03_humidity'
  key: 2534451248
  name: 'LAW sensor TH03 Humidity'
  unique_id: 'law-sensor-th03sensorlaw_sensor_th03_humidity'
  icon: ''
  unit_of_measurement: '%'
  accuracy_decimals: 1
  force_update: NO
  device_class: 'humidity'
  state_class: STATE_CLASS_MEASUREMENT
  legacy_last_reset_type: LAST_RESET_NONE
  disabled_by_default: NO
  entity_
[14:46:46][VV][api.service:055]: send_list_entities_done_response: ListEntitiesDoneResponse {}
[14:46:46][VV][api.service:548]: on_subscribe_states_request: SubscribeStatesRequest {}
[14:46:46][VV][api.service:610]: on_subscribe_homeassistant_services_request: SubscribeHomeassistantServicesRequest {}
[14:46:46][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2381800359
  state: nan
  missing_state: NO
}
[14:46:46][VV][api.service:637]: on_subscribe_home_assistant_states_request: SubscribeHomeAssistantStatesRequest {}
[14:46:46][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2534451248
  state: nan
  missing_state: NO
}
[14:46:55][VV][scheduler:225]: Running interval 'update' with interval=10000 last_execution=17993 (now=27993)
[14:46:55][W][dht:169]: Requesting data from DHT failed!
[14:46:55][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[14:46:55][V][sensor:043]: 'LAW sensor TH03 Temperature': Received new state nan
[14:46:55][VV][sensor.filter:014]: Filter(0x3fff4c44)::input(nan)
[14:46:55][VV][sensor.filter:282]: LambdaFilter(0x3fff4c44)::new_value(nan) -> nan
[14:46:55][VV][sensor.filter:021]: Filter(0x3fff4c44)::output(nan) -> SENSOR
[14:46:55][D][sensor:093]: 'LAW sensor TH03 Temperature': Sending state nan °C with 1 decimals of accuracy
[14:46:55][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2381800359
  state: nan
  missing_state: NO
}
[14:46:55][V][sensor:043]: 'LAW sensor TH03 Humidity': Received new state nan
[14:46:55][VV][sensor.filter:014]: Filter(0x3fff50f4)::input(nan)
[14:46:55][VV][sensor.filter:282]: LambdaFilter(0x3fff50f4)::new_value(nan) -> nan
[14:46:55][VV][sensor.filter:021]: Filter(0x3fff50f4)::output(nan) -> SENSOR
[14:46:55][D][sensor:093]: 'LAW sensor TH03 Humidity': Sending state nan % with 1 decimals of accuracy
[14:46:55][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2534451248
  state: nan
  missing_state: NO
}
[14:46:55][V][component:204]: Component dht.sensor took a long time for an operation (0.11 s).
[14:46:55][V][component:205]: Components should block for at most 20-30ms.
[14:47:04][VV][api.service:512]: on_ping_request: PingRequest {}
[14:47:04][VV][api.service:043]: send_ping_response: PingResponse {}
[14:47:05][VV][scheduler:225]: Running interval 'update' with interval=10000 last_execution=27993 (now=37993)
[14:47:05][W][dht:169]: Requesting data from DHT failed!
[14:47:05][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[14:47:05][V][sensor:043]: 'LAW sensor TH03 Temperature': Received new state nan
[14:47:05][VV][sensor.filter:014]: Filter(0x3fff4c44)::input(nan)
[14:47:05][VV][sensor.filter:282]: LambdaFilter(0x3fff4c44)::new_value(nan) -> nan
[14:47:05][VV][sensor.filter:021]: Filter(0x3fff4c44)::output(nan) -> SENSOR
[14:47:05][D][sensor:093]: 'LAW sensor TH03 Temperature': Sending state nan °C with 1 decimals of accuracy
[14:47:05][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2381800359
  state: nan
  missing_state: NO
}
[14:47:05][V][sensor:043]: 'LAW sensor TH03 Humidity': Received new state nan
[14:47:05][VV][sensor.filter:014]: Filter(0x3fff50f4)::input(nan)
[14:47:05][VV][sensor.filter:282]: LambdaFilter(0x3fff50f4)::new_value(nan) -> nan
[14:47:05][VV][sensor.filter:021]: Filter(0x3fff50f4)::output(nan) -> SENSOR
[14:47:05][D][sensor:093]: 'LAW sensor TH03 Humidity': Sending state nan % with 1 decimals of accuracy
[14:47:05][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2534451248
  state: nan
  missing_state: NO
}
[14:47:05][V][component:204]: Component dht.sensor took a long time for an operation (0.11 s).
[14:47:05][V][component:205]: Components should block for at most 20-30ms.
[14:47:05][VV][api.service:512]: on_ping_request: PingRequest {}
[14:47:05][VV][api.service:043]: send_ping_response: PingResponse {}