ESP32 + MQTT + Home Assistant: DIY smart home, then let AI control it by voice
TL;DR
The ESP32 (built-in Wi-Fi) reads sensors and drives relays; ESPHome configures it in YAML without C++; data flows via MQTT or the native API into Home Assistant; automations run locally. The AI layer (Assist + an LLM) should only control explicitly exposed devices — never let AI decide on locks or gas.
System layers
| Layer | Technology | Role |
|---|---|---|
| Device | ESP32 + sensors (DHT22, PIR…) + relays | Read data, switch loads |
| Firmware | ESPHome (YAML) or Arduino/PlatformIO | Program the device |
| Messaging | MQTT (Mosquitto) / ESPHome native API | Publish/subscribe state |
| Orchestration | Home Assistant | Dashboards, automations, schedules |
| AI | Assist + LLM integration | Natural-language commands and queries |
ESPHome example
esphome:
name: living-room
esp32:
board: esp32dev
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
sensor:
- platform: dht
pin: GPIO4
temperature: { name: "Living room temperature" }
humidity: { name: "Living room humidity" }
update_interval: 60sSafety
- Mains relays: use isolated modules in enclosed boxes; if unsure, hire an electrician.
- Critical automations run locally in Home Assistant, independent of AI/cloud.
- Expose only safe devices to AI (lights, fans); locks, stoves and gas need manual confirmation.
- Password-protect MQTT and never expose the broker to the Internet.
Docs: ESPHome · Home Assistant MQTT · Home Assistant Assist