AI Automation

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

LayerTechnologyRole
DeviceESP32 + sensors (DHT22, PIR…) + relaysRead data, switch loads
FirmwareESPHome (YAML) or Arduino/PlatformIOProgram the device
MessagingMQTT (Mosquitto) / ESPHome native APIPublish/subscribe state
OrchestrationHome AssistantDashboards, automations, schedules
AIAssist + LLM integrationNatural-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: 60s

Safety

  • 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.