ESPHome and Home Assistant Beginner Guide: Build Your First WiFi Sensor
ESPHome turns an ESP32 into a smart home sensor or controller with almost no code. Combined with Home Assistant, it is the most powerful DIY home automation setup available.
What You Will Build
A WiFi temperature and humidity sensor that reports every 30 seconds to Home Assistant, appears automatically in your dashboard, and survives reboots. Total hardware cost: under $10.
Hardware Needed
- ESP32 DevKit (~$5)
- BME280 temperature/humidity/pressure sensor (~$4) — recommended over DHT22 for accuracy
- USB cable, jumper wires
Wire the BME280 (I2C)
| BME280 Pin | ESP32 Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO 21 |
| SCL | GPIO 22 |
Install ESPHome
In Home Assistant: Settings → Add-ons → Add-on Store → search ESPHome → Install → Start.
Create Your Device
ESPHome dashboard → New Device → name it → Edit. Paste this configuration:
esphome:
name: workshop-sensor
friendly_name: Workshop Sensor
esp32:
board: esp32dev
logger:
api:
encryption:
key: !secret api_key
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Fallback Hotspot"
password: "fallback123"
i2c:
sda: GPIO21
scl: GPIO22
sensor:
- platform: bme280_i2c
temperature:
name: "Temperature"
pressure:
name: "Pressure"
humidity:
name: "Humidity"
address: 0x76
update_interval: 30s
Flash Your ESP32
ESPHome dashboard → Install → Plug into this computer → select USB port → Install.
First flash takes 2–3 minutes to compile. Future updates are wireless (OTA).
Connect to Home Assistant
HA will auto-discover the device. Settings → Devices & Services → Configure. Your sensors are now available for automations and dashboards.
What to Build Next
ESPHome supports nearly any hardware with simple YAML additions:
- Motion sensor (PIR) — trigger automations on presence
- Door/window sensor (reed switch) — detect open/close
- RGB LED controller — control strips from HA
- Smart relay switch — control lights or appliances
- CO2 monitor (MH-Z19B) — air quality
- Water leak detector — under-sink protection
- Energy monitor (PZEM-004T) — whole-home power monitoring
Each takes 10–30 lines of YAML and works exactly like the temperature sensor.
ESPHome vs Tasmota
Both flash open-source firmware to ESP devices. ESPHome is YAML-configured and tightly integrated with Home Assistant. Tasmota works with more platforms but is more complex. If you use HA, ESPHome wins.