Table of Contents
ESPHome is a system that lets you program ESP8266 and ESP32 microcontrollers using simple YAML configuration files. No C++ required. No complex IDEs. Just write a config file describing what your device should do, and ESPHome compiles and flashes the firmware automatically.
The result integrates natively with Home Assistant via an encrypted local API. Your custom sensor appears in HA just like any commercial device — but you built it yourself, it works exactly how you want, and it costs a fraction of off-the-shelf alternatives.
What Is ESPHome?
ESPHome bridges the gap between DIY electronics and professional smart home automation. Here's what makes it special:
- YAML configuration: Define your device's behaviour in a simple config file — no programming knowledge needed
- Native HA integration: Devices auto-discover in Home Assistant with no MQTT setup required
- OTA updates: Push firmware updates wirelessly after initial flash
- Huge component library: Hundreds of sensors, displays, LED strips, and peripherals supported out of the box
- Completely local: No cloud, no accounts, communication stays on your network
Hardware You Need
Microcontrollers
- ESP8266 (D1 Mini, NodeMCU): Cheap, WiFi-only, great for simple sensors. Around $3-5 each.
- ESP32: More powerful, has Bluetooth too, better for complex projects. Around $5-10.
- ESP32-S2/S3: Newer variants with USB native support — easiest for first-time flashing.
Common Sensors
- DHT22 / BME280: Temperature and humidity
- BH1750 / TSL2561: Light/lux sensor
- PIR HC-SR501: Motion detection
- DS18B20: Waterproof temperature probe
- CO2 sensors (SCD40, MH-Z19): Air quality monitoring
Other Essentials
- USB-to-serial adapter (CP2102 or CH340) for initial flashing
- Breadboard and jumper wires for prototyping
- 5V USB power supply
Installing ESPHome
The easiest way to use ESPHome if you already have Home Assistant OS or Supervised is via the ESPHome add-on.
ESPHome Add-on
- In Home Assistant, go to Settings → Add-ons → Add-on Store
- Search for "ESPHome" and install it
- Start the add-on and open the web interface
ESPHome Dashboard
The ESPHome dashboard is where you create and manage your device configs. It shows all your ESPHome devices and their online status, and lets you compile/flash firmware directly from the browser.
Your First Device
Let's create a simple temperature and humidity sensor using a D1 Mini and DHT22.
Step 1: Create New Device
In the ESPHome dashboard, click "New Device". Enter a name (e.g., "bedroom-sensor") and select your board type (D1 Mini). ESPHome generates a basic config with WiFi credentials.
Step 2: Add the DHT22 Sensor
Edit the generated config and add:
sensor:
- platform: dht
pin: D4
model: DHT22
temperature:
name: "Bedroom Temperature"
humidity:
name: "Bedroom Humidity"
update_interval: 60s
Step 3: First Flash (Wired)
The first flash must be done via USB. Connect your D1 Mini to your computer or HA server via USB. In the ESPHome dashboard, click "Install" → "Plug into this computer". ESPHome will compile the firmware and flash it.
Step 4: OTA Updates Forever After
After the initial wired flash, all future updates happen wirelessly (OTA). Just edit the YAML and click "Install" — no cables needed.
Adding Sensors
Here's a quick reference for adding common sensors:
BME280 (Temperature, Humidity, Pressure) via I2C
i2c:
sda: D2
scl: D1
sensor:
- platform: bme280_i2c
temperature:
name: "Temperature"
pressure:
name: "Pressure"
humidity:
name: "Humidity"
PIR Motion Sensor
binary_sensor:
- platform: gpio
pin: D3
name: "Motion"
device_class: motion
Home Assistant Integration
Once your ESPHome device is online, Home Assistant detects it automatically on the local network. You'll see a notification: "ESPHome device discovered". Click to add it — no configuration needed on the HA side.
Your sensor entities appear immediately: sensor.bedroom_temperature, sensor.bedroom_humidity, etc. You can use these in any HA automation, dashboard, or notification.
5 Beginner Projects
1. Whole-Home Temperature Map
Place D1 Mini + DHT22 sensors in every room. Track temperature differences, identify cold spots, and automate heating/cooling based on actual room temperatures.
2. Mailbox Notifier
Use an ESP32 with a reed switch on your mailbox. When the lid opens, HA sends a push notification: "You've got mail!" Use deep sleep mode to run for months on a small battery.
3. Plant Soil Monitor
Add a capacitive soil moisture sensor to an ESP32. Get HA notifications when your plants need water, or automate a small pump relay.
4. Garage Door Monitor
Mount a D1 Mini with a magnetic reed switch on your garage door. Know instantly if you left it open, and trigger an HA automation to notify you after 10 minutes.
5. CO2 Air Quality Monitor
Pair an ESP32 with an SCD40 CO2 sensor. Monitor air quality in your home office, and automate a fan or send alerts when CO2 levels rise above 1000 ppm.
Bottom Line
ESPHome is the best tool available for custom Home Assistant sensors. The YAML-based approach makes it accessible to non-programmers, the HA integration is seamless, and the hardware costs are tiny. Even a single DIY sensor project will save you money compared to commercial alternatives — and you'll learn something along the way.
SmartWired participates in the Amazon Associates Programme. We may earn a commission from qualifying purchases at no extra cost to you.