
ESPHome is a powerful system that allows you to control ESP8266 and ESP32 microcontrollers directly from Home Assistant without writing complex code. Instead of dealing with Arduino IDE or complex programming, ESPHome uses simple YAML configuration files to create custom firmware for your devices. This guide will walk you through setting up ESPHome and creating your first sensor.
What You’ll Need
Before starting, gather these components:
- A computer with Home Assistant installed (Home Assistant OS, Supervised, or Container)
- An ESP8266 or ESP32 development board (NodeMCU, Wemos D1 Mini, or similar)
- A USB cable to connect your ESP board to your computer
- A basic sensor (we’ll use a DHT22 temperature/humidity sensor for this example)
- Jumper wires and a breadboard
- WiFi network credentials
Step 1: Installing the ESPHome Add-on
First, you need to install ESPHome as a Home Assistant add-on:
- Open your Home Assistant web interface
- Navigate to Settings → Add-ons
- Click the Add-on Store button
- Search for “ESPHome” in the official add-ons
- Click on ESPHome and then Install
- After installation completes, toggle Start on boot and Watchdog
- Click Start to launch the add-on
- Once started, click Open Web UI
The ESPHome dashboard should now open in a new tab. This is where you’ll manage all your ESP devices.
Step 2: Creating Your First Device
Now let’s create your first ESPHome device:
- In the ESPHome dashboard, click the green + NEW DEVICE button
- Click Continue on the welcome screen
- Give your device a name (e.g., “bedroom-sensor”)
- Select your device type:
- Choose ESP8266 if using NodeMCU, Wemos D1 Mini, etc.
- Choose ESP32 if using an ESP32 board
- Enter your WiFi credentials when prompted
- Click Next and then Skip (we’ll add the sensor manually)
ESPHome will generate a basic configuration file for your device.
Step 3: Wiring Your Sensor
For this example, we’ll connect a DHT22 temperature and humidity sensor:
DHT22 to ESP8266/ESP32 connections:
- VCC (power) → 3.3V or 5V pin
- GND (ground) → GND pin
- DATA → GPIO pin (we’ll use D2 on ESP8266 or GPIO4 on ESP32)
Make sure all connections are secure before proceeding.
Step 4: Configuring Your Sensor
Back in the ESPHome dashboard:
- Click Edit on your newly created device
- You’ll see a YAML configuration file. Add the sensor configuration after the existing code:
yaml<code>sensor:
- platform: dht
pin: D2 <em># Use GPIO4 for ESP32</em>
temperature:
name: "Bedroom Temperature"
id: bedroom_temp
humidity:
name: "Bedroom Humidity"
id: bedroom_humidity
update_interval: 60s</code>
The complete configuration should look something like this:
yaml<code>esphome:
name: bedroom-sensor
friendly_name: bedroom-sensor
esp8266: <em># or esp32</em>
board: nodemcuv2 <em># adjust based on your board</em>
<em># Enable logging</em>
logger:
<em># Enable Home Assistant API</em>
api:
encryption:
key: "your-generated-key-here"
ota:
password: "your-ota-password"
wifi:
ssid: "Your-WiFi-Name"
password: "your-wifi-password"
<em># Enable fallback hotspot</em>
ap:
ssid: "Bedroom-Sensor Fallback Hotspot"
password: "fallback-password"
captive_portal:
sensor:
- platform: dht
pin: D2
temperature:
name: "Bedroom Temperature"
id: bedroom_temp
humidity:
name: "Bedroom Humidity"
id: bedroom_humidity
update_interval: 60s</code>
Step 5: Installing the Firmware
Now it’s time to flash this configuration to your ESP device:
- Click Save to save your configuration
- Connect your ESP board to your computer via USB
- Click Install in the ESPHome dashboard
- Choose Plug into the computer running ESPHome Dashboard
- Select the correct COM port for your device
- Click Install
ESPHome will compile the firmware and flash it to your device. This process takes a few minutes the first time.
Step 6: Adding the Device to Home Assistant
Once flashing is complete:
- Your ESP device should restart and connect to WiFi
- In Home Assistant, go to Settings → Devices & Services
- You should see a notification about a new ESPHome device discovered
- Click Configure and then Submit
- Your device will be added to Home Assistant
If the device doesn’t appear automatically:
- Click Add Integration
- Search for and select ESPHome
- Enter the IP address of your ESP device
- Leave the port as 6053 and click Submit
Step 7: Viewing Your Sensor Data
Your sensor data should now be available in Home Assistant:
- Go to Settings → Devices & Services → ESPHome
- Click on your device to see all its entities
- Navigate to Developer Tools → States to see real-time values
- Add the sensors to your dashboard by going to Overview and clicking Edit Dashboard
Understanding the Configuration
Let’s break down what each part of the configuration does:
Basic Device Setup:
esphome:
section defines the device name and friendly nameesp8266:
oresp32:
specifies the microcontroller type and boardwifi:
contains your network credentials and fallback hotspot settings
Communication:
api:
enables communication with Home Assistantota:
allows over-the-air updates after initial setuplogger:
enables serial logging for debugging
Sensor Configuration:
platform: dht
specifies we’re using a DHT sensorpin:
defines which GPIO pin the sensor is connected totemperature:
andhumidity:
create separate entities for each measurementupdate_interval:
sets how often the sensor reads new values
Troubleshooting Common Issues
Device won’t flash:
- Ensure the correct COM port is selected
- Try a different USB cable
- Press and hold the BOOT button on some ESP32 boards during flashing
Device not connecting to WiFi:
- Double-check WiFi credentials in the configuration
- Ensure your WiFi network uses 2.4GHz (ESP devices don’t support 5GHz)
- Check if your network has special characters that need escaping
Sensor readings are incorrect:
- Verify wiring connections
- Ensure adequate power supply (some sensors need 5V instead of 3.3V)
- Check if the sensor requires a pull-up resistor
Device not appearing in Home Assistant:
- Wait a few minutes after flashing
- Check the ESPHome logs for connection errors
- Manually add the device using its IP address
Next Steps
Now that you have your first ESPHome sensor working, you can expand your setup:
Add more sensors: Motion detectors, light sensors, door/window sensors Add outputs: Control LEDs, relays, or servo motors Create automations: Use your sensor data to trigger actions in Home Assistant Update wirelessly: After the initial flash, you can update your device configuration over WiFi
Tips for Success
- Start simple with one sensor before adding complexity
- Keep your YAML indentation consistent (use spaces, not tabs)
- Use the ESPHome logs to debug issues
- Name your devices and sensors clearly for easy identification
- Test your wiring with a multimeter if sensors aren’t working
- Keep your ESPHome configurations backed up
ESPHome opens up endless possibilities for custom sensors and automation devices. With this foundation, you can create a comprehensive smart home system tailored exactly to your needs. The beauty of ESPHome lies in its simplicity – complex functionality through simple configuration files, all integrated seamlessly with Home Assistant.