With an ESP32 that costs a few dollars and a sensor, you can measure the temperature of any room and see it in Home Assistant. The best part: you don’t need to know how to code. ESPHome turns a configuration file of just a few lines into complete firmware, with Wi-Fi, over-the-air updates and automatic setup in your smart home system.
In this guide we build a temperature and humidity sensor step by step, from a blank board to the graph on your dashboard.
In short
- ESPHome generates the ESP32 firmware from a YAML file: you describe what’s connected and it writes the code.
- The first upload is done over USB; the following ones over Wi-Fi (OTA).
- Home Assistant discovers the device on its own and creates its entities.
- To get started you need an ESP32, a DHT22 sensor, three wires and a USB data cable.
- If you want another smart home system or to integrate the sensor into something else, ESPHome also speaks MQTT.
What ESPHome is and why you don’t need to code
ESPHome is an open-source project that’s part of the Home Assistant ecosystem. Instead of writing a C++ program, you describe the device in a text file: which board you’re using, which Wi-Fi network it joins and which sensors are on each pin.
ESPHome translates that file into code, compiles it and uploads it to the board. If tomorrow you want to add a relay or change how often it measures, you edit two lines and install again.
It works with the classic ESP32 and its variants (S3, C3, C6), with the older ESP8266 and with a few other boards. If you’re still unsure which board to buy, check out the ESP32 vs Arduino comparison: for home automation, the ESP32 is the natural choice.
What you need
| Item | What it’s for | Notes |
|---|---|---|
| A working Home Assistant | Receiving and showing the data | If you don’t have it, follow the guide to Home Assistant on Raspberry Pi |
| ESP32 DevKit board | The sensor’s “brain” | Any board with USB will do |
| DHT22 module | Temperature and humidity | Preferably the 3-pin module, which already has the pull-up resistor |
| 3 female-to-female jumper wires | Connecting the sensor | Or a breadboard |
| USB data cable | The first upload | Many cables only charge and won’t work |
Later on you can swap the DHT22 for another sensor. In DHT22 vs DS18B20 we compare the most common ones.
Step 1: install ESPHome in Home Assistant
ESPHome is managed from a web dashboard called ESPHome Device Builder. If you use Home Assistant OS, it installs like any other app:
- Go to Settings > Apps and open the store.
- Search for ESPHome Device Builder and install it.
- Turn on Show in sidebar and start it.
- Open it from the sidebar: you’ll see an empty dashboard with a New device button.
If you run Home Assistant in a container, ESPHome also runs as a separate Docker container. If you already have Docker on the Raspberry Pi, it’s one more line.
Step 2: create the device
- Click New device and give it a short name, lowercase and without spaces, for example
sensor-salon. - Choose the chip type: ESP32 (or whichever variant you have).
- The wizard generates a base configuration with your Wi-Fi and an encryption key for the connection to Home Assistant. Save it: you’ll need it if you’re asked for it when adding the device.
- Connect the board to your computer over USB and click Install.
- Choose the option to install over USB from this browser (Plug into this computer). You need Chrome or Edge, which allow access to the serial port.
If the browser won’t connect over USB (this happens when Home Assistant isn’t opened over HTTPS), choose Manual download, download the firmware and flash it from the official ESPHome Web site with Chrome or Edge.
The first compile takes a few minutes. The following ones are much faster.

Step 3: connect the sensor
Unplug the USB cable before wiring. The DHT22 module has three pins:
| Module pin | ESP32 pin | Wire |
|---|---|---|
| VCC (+) | 3V3 | Red |
| DATA (OUT) | GPIO4 | Yellow |
| GND (−) | GND | Black |
The pin order varies by module manufacturer: go by the silkscreen labels, not the position. If you’re using a “bare” four-pin DHT22, you need to add a 10 kΩ resistor between DATA and VCC. We explain why in the guide to pull-up and pull-down resistors.
GPIO4 is a good choice because it isn’t involved in booting. Avoid pins 0, 2, 12 and 15 on the classic ESP32 for your first builds.

Step 4: describe the sensor in YAML
Go back to the ESPHome dashboard and click Edit on your device. You’ll see the configuration the wizard generated. Add this block at the end:
sensor:
- platform: dht
pin: GPIO4
model: DHT22
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s
The part that was already there looks something like this (your values will be different):
esphome:
name: sensor-salon
esp32:
board: esp32dev
logger:
api:
encryption:
key: "the-key-the-wizard-generated"
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
Three YAML details that trip people up at first:
- Indentation matters: use spaces, never tabs.
!secretreads the value from the secrets.yaml file, so your password doesn’t show up in the configuration.api:is the connection to Home Assistant andota:enables updates over Wi-Fi.
Click Save and Install. This time choose Wirelessly: the board is already on your network and you don’t need the cable. When it finishes, you’ll see lines in the log with the temperature every minute.
Step 5: add it to Home Assistant
In most cases Home Assistant discovers it on its own. You’ll get a New devices discovered notification:
- Go to Settings > Devices & services.
- Under the ESPHome integration, click Configure on your sensor.
- If you’re asked for the encryption key, paste the one from the YAML.
- Assign it an area (Living Room) and you’re done.
You now have two new entities, temperature and humidity, which you can add to the dashboard, view in the history or use in automations.

ESPHome or coding with the Arduino IDE
| ESPHome | Arduino IDE | |
|---|---|---|
| Language | YAML configuration | C++ |
| Home Assistant integration | Automatic | By hand, usually over MQTT |
| Over-the-air updates | Included | You have to code them |
| Flexibility | High within its components | Total |
| Ideal for | Smart home sensors and actuators | Your own projects or anything outside home automation |
If your goal is home automation, ESPHome saves you hours. If you want to understand what’s going on under the hood or send data to another system, learn how MQTT with ESP32 works. And if you’re going to place the sensor far from an outlet, check out how to power an ESP32 from a battery.
Common problems
- The computer doesn’t detect the board: it’s almost always the cable (charge-only) or a missing driver for the USB converter (CP2102 or CH340).
- It gets stuck on “Connecting…” while uploading: hold down the board’s BOOT button as the upload starts.
- The reading shows as NaN or “unavailable”: check the pin in the YAML, the wiring, and that the model is
DHT22and notDHT11. - The temperature reads high: the sensor is too close to the ESP32, which warms up. Move it a few inches away using wires.
- The device shows as offline: make sure it’s on the same network and that the 2.4 GHz Wi-Fi signal reaches it well.
Frequently asked questions
Do I need to know how to code to use ESPHome? No. All you have to do is copy and adapt YAML configuration blocks. The official documentation has an example for almost every sensor.
Can I use ESPHome without Home Assistant? Yes. You can use its built-in web server or enable the MQTT component to send the data to another system. But the simplest experience is with Home Assistant.
Will any ESP32 work? Practically any. When you create the device you choose the variant and, if needed, the exact board model. To get started, a classic DevKit is the most thoroughly tested.
What happens if the Wi-Fi goes down? The sensor keeps measuring and reconnects on its own when the network comes back. If it goes a long time without a connection, it restarts and tries again.
Where do I go after my first sensor? Add a relay, a button or a display to the same YAML. If you’re just getting started with electronics, our Arduino and ESP32 beginner’s guide shows you the way.



