Home Assistant hub on a Raspberry Pi
Build it step by step
0 of 7 doneFlash Home Assistant OS
With Raspberry Pi Imager.
Boot and create the account
Wait up to 20 minutes.
Install the ESPHome add-on
From the store.
Write secrets.yaml
Your own values.
Flash the ESP32
First time over USB.
Add the sensors to a dashboard
Check the readings.
Add the automation
Test with a low limit.
How do you build a home Assistant hub on a Raspberry Pi?
Install Home Assistant OS on a Pi and connect your ESP32 sensors and switches to one dashboard with automations. You need Raspberry Pi 4 Model B (4 GB), Raspberry Pi 15 W USB-C power supply, SanDisk microSD card 32 GB (A1, Class 10), Ethernet cable Cat6 (3 m), ESP32 DevKit V1 and DHT22 Sensor. It takes 7 steps and about 240 minutes.
- Level
- Intermediate
- Time
- About 240 min
- Parts
- 6
Parts list
- Single Board ComputersBuy
- SBC AccessoriesBuy
- SBC AccessoriesBuy
- Cables & WiresBuy
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuyDHT22 Sensor × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Pi 4 | Ethernet cable to your router, USB-C power supply, SD card | The Home Assistant server (wired network is steadier) |
| DHT22 data | ESP32 GPIO4, with 10 k to 3V3 if your module has no resistor | Sensor signal |
| DHT22 VCC and GND | ESP32 3V3 and GND | Power |
| ESP32 | USB power while testing | ESPHome device |
Code
Home Assistant is free software that gathers your devices on one dashboard and runs automations between them. On the Pi, flash Home Assistant OS with Raspberry Pi Imager (it is under Other specific-purpose OS), connect the Ethernet cable, power on, and after ten to twenty minutes open http://homeassistant.local:8123 to create your account; choose a strong password and do not share it. Install the ESPHome add-on from the add-on store, create a secrets file with your own Wi-Fi name and password, an API key and an OTA password, flash the ESP32 over USB the first time, and Home Assistant will offer to add the new device. Put the two sensors on a dashboard card, then create the automation in the second file, replacing YOUR_PHONE with the name of your phone in the Home Assistant app. Do not open port 8123 to the internet: use the Home Assistant app on your phone with a VPN, or Nabu Casa remote access, for remote use. Take a backup from Settings, System, Backups before changes, and copy it off the SD card. Raspberry Pi OS (Bookworm or newer) with Python 3.
# ===== File 1: room-sensor.yaml, the ESPHome config for the ESP32 (put the real values in secrets.yaml) =====
esphome:
name: room-sensor
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Room Sensor Fallback"
password: !secret fallback_password
captive_portal:
sensor:
- platform: dht
pin: GPIO4
model: DHT22
update_interval: 30s
temperature:
name: "Room temperature"
humidity:
name: "Room humidity"
# ===== File 2: a Home Assistant automation (Settings, Automations, Edit in YAML) =====
alias: Room too warm
trigger:
- platform: numeric_state
entity_id: sensor.room_temperature
above: 32
for: "00:10:00"
action:
- service: notify.mobile_app_YOUR_PHONE
data:
message: "The room has been above 32 C for 10 minutes"Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Open the web page | Dashboard loads |
| ESP32 online | Appears as a new device |
| Breathe on the DHT22 | Humidity rises on the card |
| Automation with a low limit | Phone alert arrives |
If it does not work
homeassistant.local not found
Use the Pi's address from your router.
ESP32 not discovered
Check both are on the same network and the API key matches.
DHT22 reads unknown
Check the data pin and its pull-up.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the home Assistant hub on a Raspberry Pi?
Raspberry Pi 4 Model B (4 GB), Raspberry Pi 15 W USB-C power supply, SanDisk microSD card 32 GB (A1, Class 10), Ethernet cable Cat6 (3 m), ESP32 DevKit V1 and DHT22 Sensor.
How long does the home Assistant hub on a Raspberry Pi take to build?
About 240 minutes for a intermediate maker, in 7 steps.
How do I know the home Assistant hub on a Raspberry Pi works?
Open the web page: Dashboard loads. ESP32 online: Appears as a new device. Breathe on the DHT22: Humidity rises on the card.
homeassistant.local not found: what should I check?
Use the Pi's address from your router.
ESP32 not discovered: what should I check?
Check both are on the same network and the API key matches.
DHT22 reads unknown: what should I check?
Check the data pin and its pull-up.
