Skip to content

Temperature Sensor with ESP32

Easy 30 min $10

ESP32 Temperature Sensor

A temperature/humidity sensor is a good place to start: three wires, a handful of YAML lines, and you have live readings from the room in Home Assistant. The parts cost around $10.

Before you start:

PartDescriptionApprox. price
ESP32 DevKitWiFi microcontroller$5
DHT22 sensorTemperature + humidity$3
Jumper wires3x male-female$2
Total~$10

DHT22 to ESP32 wiring diagram

  1. Red wire (VCC/+) → ESP32 3.3V pin

  2. Yellow/white wire (DATA/OUT) → ESP32 GPIO4 pin

  3. Black wire (GND/-) → ESP32 GND pin

Open your device in ESPHome and add this sensor configuration:

living-room-sensor.yaml
esphome:
name: living-room-sensor
friendly_name: Living Room Sensor
esp32:
board: esp32dev
logger:
api:
encryption:
key: "your-key-here"
ota:
platform: esphome
# DHT22 Sensor
sensor:
- platform: dht
pin: GPIO4
model: DHT22
temperature:
name: "Living Room Temperature"
filters:
- offset: 0.0 # Adjust if needed
humidity:
name: "Living Room Humidity"
update_interval: 60s
wifi:
ssid: "your-wifi"
password: "your-password"

For outdoor or in-liquid measurements, a waterproof DS18B20 is a better choice than the DHT22. It uses 1-wire and needs a 4.7 kΩ pull-up resistor between DATA and 3.3V:

DS18B20 instead of DHT22
one_wire:
- platform: gpio
pin: GPIO4
sensor:
- platform: dallas_temp
name: "Living Room Temperature"
update_interval: 60s

With only one sensor on the bus you can leave out address. Note that the DS18B20 only measures temperature, not humidity.

  1. Click INSTALL in ESPHome
  2. Choose Wirelessly
  3. Wait ~1 minute
  1. Go to SettingsDevices & Services

  2. Find your ESP32 device and click it

  3. You should see two new sensors:

    • sensor.living_room_temperature
    • sensor.living_room_humidity
  4. Click a sensor to see its graph over time

Lovelace card
type: sensor
entity: sensor.living_room_temperature
name: Living room
icon: mdi:thermometer
graph: line
hours_to_show: 24
Lovelace card
type: glance
entities:
- entity: sensor.living_room_temperature
name: Temperature
- entity: sensor.living_room_humidity
name: Humidity
title: Living Room Climate
TipExplanation
PlacementAvoid direct sunlight, radiators, and windows
HeightMount at ~1.5 m for room temperature
AirflowNot in corners or behind furniture
Update interval60s is fine, the DHT22 can be read at most every 2 seconds
Example: warn on high humidity
automation:
- alias: "High humidity alert"
trigger:
- platform: numeric_state
entity_id: sensor.living_room_humidity
above: 70
for: "00:30:00"
action:
- service: notify.mobile_app_your_phone # replace with your own device's notify service
data:
title: "⚠️ High humidity"
message: "Humidity in the living room is {{ states('sensor.living_room_humidity') }}%"

Replace notify.mobile_app_your_phone with the name of your own phone’s notify service - you can find it under Developer ToolsActions.


Comments