How to Build a Wi-Fi Sensor with ESPHome (A £5 Board, No Code, Straight into Home Assistant)

Build your own smart device: An ESP32, a sensor and ten lines of YAML. No code, no cloud.

An ESP32 is a £5 Wi-Fi microcontroller. Wire a temperature sensor to it, and with ESPHome you describe the device in a few lines of YAML, flash it from your browser, and it shows up in Home Assistant (tutorial 41) as a proper device — no Arduino code, no cloud, updates over the air. Greenhouse temperature, a door sensor, a relay for the pond pump, a presence sensor for the hallway: all the same recipe.

Quick reference

TaskWhat
Dashboardghcr.io/esphome/esphome in Docker, http://server-ip:6052
Hardwareany ESP32 dev board (ESP32-DevKit, ESP32-C3, Wemos D1) + a sensor
First flashby USB from the browser (ESP Web Tools), after that over Wi-Fi
Configone YAML file per device in ./config
Home AssistantESPHome integration discovers it; or the native API key
Secrets./config/secrets.yaml for Wi-Fi password and keys

1. The dashboard

mkdir -p ~/docker/esphome/config && cd ~/docker/esphome
nano compose.yaml

services:
esphome:
image: ghcr.io/esphome/esphome:latest
container_name: esphome
network_mode: host
environment:
TZ: Europe/London
ESPHOME_DASHBOARD_USE_PING: "true"
volumes:
- ./config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped

Host networking lets it find devices on the LAN for over-the-air updates.

docker compose up -d

Open http://192.168.1.50:6052. Put the Wi-Fi details in config/secrets.yaml:

wifi_ssid: "YourNetwork"
wifi_password: "YourPassword"
api_key: "generate-with-the-dashboard"
ota_password: "something-long"

2. A first device: temperature and humidity

Wire a DHT22 (or better, a BME280 on I²C) to the ESP32: 3.3V, GND, and the data pin to GPIO4. Then in the dashboard, + New device → Continue → name it greenhouse → ESP32, and edit the YAML it creates:

esphome:
name: greenhouse
friendly_name: Greenhouse

esp32:
board: esp32dev

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Greenhouse Fallback"

api:
encryption:
key: !secret api_key

ota:
- platform: esphome
password: !secret ota_password

logger:

sensor:
- platform: dht
pin: GPIO4
model: DHT22
temperature:
name: "Temperature"
humidity:
name: "Humidity"
update_interval: 60s

3. Flash it

Plug the ESP32 into your laptop's USB (the browser does the flashing). In the dashboard: Install → Plug into this computer → choose the serial port → it compiles on the server (a minute or two the first time) and flashes through the browser. Afterwards, every change is Install → Wirelessly.

The logs stream in the dashboard: Wi-Fi connected, temperature readings every minute.

4. Home Assistant

Settings → Devices → Discovered: ESPHome greenhouse → Configure, paste the API key. Two sensor entities appear. Graph them, alert when the greenhouse drops below 5 °C, done.

5. More recipes

A relay (switch anything mains-rated through a relay module):

switch:
- platform: gpio
pin: GPIO16
name: "Pond pump"

A door sensor (reed switch to GPIO):

binary_sensor:
- platform: gpio
pin:
number: GPIO5
mode: INPUT_PULLUP
inverted: true
name: "Shed door"
device_class: door

A presence sensor (LD2410 mmWave, far better than PIR), an air quality sensor (SCD40), a power monitor (PZEM) — all are a few lines; the ESPHome site lists hundreds of components with copy-paste examples. Commercial devices built on ESP chips (many Sonoff and Athom products, Shelly 1) can also be re-flashed with ESPHome to free them from their clouds.

Troubleshooting

Compile fails with a pin error. Boards differ; check the board's pinout and the board: value (esp32-c3-devkitm-1, esp32dev, d1_mini).

Device never joins Wi-Fi. 2.4 GHz only — ESP boards don't do 5 GHz. Check the secrets file, and the fallback AP appears if it gave up.

Dashboard can't flash by USB. The browser needs Web Serial (Chrome/Edge), and the board's USB driver on the laptop (CP210x / CH340).

OTA update fails at 0%. Firewall on the server blocking the device, or the device is on a different subnet. Reflash by USB once; check the network.

Wrapping up

A £5 board, a sensor, ten lines of YAML, one flash from the browser. The device appears in Home Assistant with no app and no account, and every later change is a wireless update. Once you've made one, the second takes ten minutes.

Call us