I’ve wanted to build a low-cost whole-house temperature and humidity monitoring system, and I happened to have a few ESP32 development boards on hand. After spending a weekend on this project, I finally got it working. Here’s the complete process.

Final Result:

  • Reports temperature and humidity data every 30 seconds
  • Real-time display in Home Assistant with historical charts
  • Automatically triggers notifications when temperature exceeds 28°C

Parts List

ComponentQuantityApproximate Price
ESP32 Development Board (ESP-WROOM-32)1¥18
DHT22 Temperature & Humidity Sensor1¥12
Dupont WiresSeveral¥3
Micro USB Cable1Already have

Total cost is approximately ¥33, much cheaper than buying ready-made sensors, and more fun to build.


Wiring

DHT22 wiring is very simple:

DHT22 Pin    ESP32 Pin
VCC      →    3.3V
GND      →    GND
DATA     →    GPIO 4 (customizable)

A 10kΩ pull-up resistor is needed between the DATA pin and VCC. Without it, data is unstable and readings will frequently fail.


Firmware Development (ESPHome)

No need to write C code yourself. ESPHome configuration files drive the firmware, and it can be done with just a few dozen lines of YAML.

Install ESPHome (requires Python):

pip install esphome

Create the configuration file bedroom-sensor.yaml:

esphome:
  name: bedroom-sensor
  friendly_name: Bedroom Sensor

esp32:
  board: esp32dev
  framework:
    type: arduino

# WiFi Configuration
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:  # Hotspot when WiFi fails to connect
    ssid: "Sensor Fallback"
    password: "12345678"

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_encryption_key

# OTA Updates
ota:
  password: !secret ota_password

# MQTT (optional, use MQTT if not using HA native API)
mqtt:
  broker: 192.168.1.100  # IP where HA is running
  username: !secret mqtt_username
  password: !secret mqtt_password

# DHT22 Sensor
sensor:
  - platform: dht
    pin: GPIO4
    model: DHT22
    temperature:
      name: "Bedroom Temperature"
      accuracy_decimals: 1
    humidity:
      name: "Bedroom Humidity"
      accuracy_decimals: 1
    update_interval: 30s  # Update every 30 seconds

Put sensitive information in secrets.yaml:

wifi_ssid: "Your WiFi Name"
wifi_password: "Your WiFi Password"
api_encryption_key: "Generate a 32-character random string"
ota_password: "ota password"
mqtt_username: "mqtt username"
mqtt_password: "mqtt password"

Compile and flash:

esphome run bedroom-sensor.yaml

The first time requires USB connection for flashing. After that, OTA wireless updates are possible.


Home Assistant Configuration

If the ESPHome addon is installed in HA, the device will be automatically discovered. Just click “Add” in the HA interface to complete. Entity names and icons will be automatically configured.

Method 2: Manual MQTT Configuration

Add to configuration.yaml:

mqtt:
  sensor:
    - name: "Bedroom Temperature"
      state_topic: "bedroom-sensor/sensor/bedroom_temperature/state"
      unit_of_measurement: "°C"
      device_class: temperature
    - name: "Bedroom Humidity"
      state_topic: "bedroom-sensor/sensor/bedroom_humidity/state"
      unit_of_measurement: "%"
      device_class: humidity

Automation: Temperature Threshold Notification

Create in HA’s automation editor:

alias: Bedroom High Temperature Notification
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_temperature
    above: 28
    for:
      minutes: 5  # Trigger after 5 minutes to avoid false positives
action:
  - service: notify.mobile_app
    data:
      title: "Temperature Alert"
      message: "Bedroom temperature is {{ states('sensor.bedroom_temperature') }}°C, consider ventilation"

Troubleshooting

Issue 1: Data Read Failure / All NaN

Cause: No pull-up resistor on the DATA pin. Added 10kΩ resistor and resolved immediately.

Issue 2: WiFi Connection Unstable, Frequent Disconnects

Cause: Insufficient power supply current. When powered via USB charger, ESP32 WiFi transmission consumes significant power, and low-quality chargers can’t handle it. Switched to an original phone charger and it became stable.

Issue 3: ESPHome Compilation is Slow

First compilation requires downloading dependencies and may take 10-15 minutes. Subsequent incremental compilations are fast. You can also compile directly in HA’s ESPHome addon without installing Python locally.

Issue 4: OTA Update Failed

Ensure the device and computer are on the same LAN segment, and firewall is not blocking UDP port 3232.


Future Plans

  • Add an OLED screen for local temperature/humidity display
  • Integrate CO₂ sensor (SCD40)
  • Deploy in multiple rooms, unified display on HA Dashboard

Low cost and high playability, great for getting started with IoT. ESP32 has abundant documentation, and most problems can be found in ESPHome docs or HA community.