Absolutely. Below is a complete project design + implementation document for an AI-Powered Smart Home Automation System using ESP32, Voice Recognition, Face Recognition, n8n, AI Agent, Telegram Voice Alerts, Google Sheets, ThingSpeak, and an IoT Web Dashboard.
The design intentionally separates real-time safety/control from cloud AI automation: the ESP32 can continue controlling essential devices even if the Internet or n8n is unavailable.
AI-Powered Smart Home Automation Using Voice & Face Recognition
1. Project Title
AI-Powered Agentic Smart Home Automation Using ESP32, Voice Recognition, Face Recognition, n8n Automation, AI Agent, Telegram Voice Alerts, Google Sheets and ThingSpeak Cloud Dashboard
2. Abstract
This project develops an intelligent IoT-based home automation system in which an ESP32 acts as the primary edge controller and communicates with sensors, appliances, a camera/face-recognition subsystem, and cloud services.
The system combines:
- ESP32-based IoT control
- Voice commands
- Face recognition
- Motion detection
- Environmental sensing
- Relay-based appliance control
- AI Agent decision making
- n8n workflow automation
- Telegram notifications and voice alerts
- Google Sheets data logging
- ThingSpeak cloud monitoring
- Web-based IoT dashboard
- Remote control
- Event and security logging
The main idea is:
Sense → Identify → Understand → Decide → Act → Log → Notify → Learn/Analyze
For example, when a person enters the house, the camera can identify the person. The ESP32 reports the event to the automation server. n8n can then process the event, ask an AI Agent to interpret the situation, switch on selected appliances, write the event to Google Sheets, update ThingSpeak, and send a Telegram notification.
For a security event, the system can generate a Telegram alert such as:
Security Alert: Unknown person detected at the main entrance at 10:32 PM.
The n8n Telegram integration supports sending messages and audio/files, making it suitable for notification workflows.
3. Main Objectives
The project has the following objectives:
- Automate household appliances using ESP32.
- Control appliances through voice commands.
- Identify authorized users using face recognition.
- Detect unauthorized/unknown persons.
- Monitor temperature, humidity, light, motion and other sensors.
- Send IoT data to a cloud dashboard.
- Use n8n as the central automation/orchestration platform.
- Use an AI Agent to interpret natural-language commands and sensor events.
- Send Telegram text and voice notifications.
- Store historical events in Google Sheets.
- Visualize sensor data using ThingSpeak.
- Provide a web-based dashboard.
- Provide remote control through the Internet.
- Maintain event logs for debugging and security.
- Allow the system to continue performing essential local automation when the cloud connection fails.
4. Proposed System Architecture
The project can be divided into five layers.
Layer 1 — Physical/IoT Layer
- ESP32
- ESP32-CAM or separate camera
- PIR sensor
- DHT22/DHT11
- LDR
- MQ-series sensor if required
- Door magnetic sensor
- Relay module
- LEDs
- Fan
- Light
- Buzzer
- Manual switches
Layer 2 — Edge Intelligence
The ESP32 performs:
- Sensor reading
- Appliance control
- Wi-Fi communication
- Local rules
- Device status management
- Safety logic
- Command execution
Layer 3 — Automation/AI
n8n performs:
- Webhook/API processing
- Event routing
- AI Agent interaction
- Command interpretation
- Decision logic
- Notifications
- Google Sheets logging
- Cloud integration
Layer 4 — Cloud
Possible services:
- ThingSpeak
- Google Sheets
- Telegram
- AI model/API
- n8n server/cloud instance
Layer 5 — User Interface
- Web dashboard
- Telegram bot
- Voice commands
- Mobile phone
- Computer
5. Overall Block Diagram
┌───────────────────────┐
│ USER │
│ Phone / PC / Voice │
└───────────┬───────────┘
│
Voice / Web / Telegram
│
▼
┌───────────────────────┐
│ n8n SERVER │
│ │
│ Webhooks │
│ Automation │
│ AI Agent │
│ Logic │
└───────┬───────┬───────┘
│ │
┌──────────────┘ └───────────────┐
▼ ▼
┌───────────────┐ ┌────────────────┐
│ AI MODEL │ │ Telegram │
│ AI Agent │ │ Bot │
└───────────────┘ └────────────────┘
│
│
▼
┌─────────────────┐
│ ESP32 │
│ Edge Controller │
└───────┬─────────┘
│
┌──────────┼──────────────┐
│ │ │
▼ ▼ ▼
Sensors Camera Relays
│ │ │
│ ▼ ▼
│ Face Recognition Appliances
│
├── Temperature
├── Humidity
├── Motion
├── Light
└── Door
│
▼
┌──────────────────────┐
│ Cloud Data Services │
├──────────────────────┤
│ Google Sheets │
│ ThingSpeak │
│ Web Dashboard │
└──────────────────────┘
6. Recommended Hardware
| Component | Purpose |
|---|---|
| ESP32 DevKit | Main controller |
| ESP32-CAM | Camera/face recognition |
| Relay module | Appliance switching |
| DHT22 | Temperature/humidity |
| PIR | Human motion detection |
| LDR | Light measurement |
| Reed switch | Door monitoring |
| Buzzer | Local security alarm |
| OLED/LCD | Local status display |
| Push buttons | Manual control |
| 5V power supply | Electronics |
| AC/DC relay-rated hardware | Appliance control |
| Router/Wi-Fi | Internet connectivity |
For a prototype, use low-voltage lamps/fans first. Mains AC wiring should be handled with appropriate isolation, enclosure, fusing, earthing and qualified electrical work.
7. ESP32 Pin Assignment
A possible ESP32 configuration is:
ESP32 GPIO
GPIO 4 → PIR sensor
GPIO 5 → Relay 1 - Light
GPIO 18 → Relay 2 - Fan
GPIO 19 → Relay 3 - Appliance
GPIO 21 → I2C SDA
GPIO 22 → I2C SCL
GPIO 23 → Buzzer
GPIO 25 → Door sensor
GPIO 34 → LDR/analog sensor
DHT22:
DATA → GPIO 27
OLED:
SDA → GPIO 21
SCL → GPIO 22
The exact GPIO assignments can be changed according to the selected ESP32 board.
8. Electrical Concept
ESP32
│
┌──────────────┼───────────────┐
│ │ │
▼ ▼ ▼
Sensors Camera Relay
│ │ │
│ │ ▼
│ │ ┌───────────┐
│ │ │ Appliance │
│ │ └───────────┘
│
▼
Sensor data
For relay control:
ESP32 GPIO
│
▼
Relay Driver
│
▼
Relay
│
▼
Electrical Load
Important: Never connect a mains appliance directly to an ESP32 GPIO.
9. Software Architecture
Recommended software stack:
ESP32
│
├── Arduino IDE / PlatformIO
├── Wi-Fi
├── HTTP REST
└── JSON
│
▼
n8n
│
├── Webhook
├── Switch/IF
├── AI Agent
├── HTTP Request
├── Telegram
├── Google Sheets
└── ThingSpeak
│
├── Telegram
├── Google Sheets
└── ThingSpeak
n8n's Telegram node supports message and file/audio-related operations, so it can be used for the notification side of the project.
10. Why n8n?
n8n becomes the automation brain/orchestrator.
Instead of programming every cloud integration into the ESP32, the ESP32 only needs to communicate with a simple API.
For example:
ESP32
|
| POST sensor data
▼
n8n Webhook
|
├── Save Google Sheets
├── Update ThingSpeak
├── Check threshold
├── AI Agent
└── Telegram
This makes the system easier to modify.
For example, you could change:
IF temperature > 30°C
→ turn fan ON
to:
IF temperature > 30°C
AND person is present
AND time is between 18:00 and 23:00
→ turn fan ON
without changing the ESP32 firmware.
11. AI Agent Architecture
The AI Agent should not directly have unrestricted control over appliances.
Instead:
User
│
▼
Natural Language
│
▼
AI Agent
│
├── Understand intent
├── Identify device
├── Determine action
├── Check permissions
└── Produce structured command
│
▼
Safety Validator
│
▼
n8n
│
▼
ESP32
Example:
User says:
"I'm feeling hot, turn on the bedroom fan."
The AI Agent converts this into something similar to:
{
"device": "bedroom_fan",
"action": "ON",
"reason": "user_request"
}
n8n validates the command and sends it to the ESP32.
12. Agentic IoT Concept
The project can be described as Agentic IoT because the AI is not simply displaying sensor values.
It can:
- Observe the environment.
- Understand an event.
- Select an appropriate action.
- Call an IoT tool/API.
- Verify the result.
- Notify the user.
Example:
Temperature = 32°C
│
▼
AI Agent observes
│
▼
"Room is hot"
│
▼
Check fan status
│
▼
Fan OFF
│
▼
Turn fan ON
│
▼
Verify ESP32 response
│
▼
Log event
│
▼
Telegram notification
13. Voice-Control Flow
There are two practical voice-control approaches.
Method A — Phone → Telegram → n8n
User speaks
│
▼
Telegram voice message
│
▼
Telegram Bot
│
▼
n8n
│
▼
Speech-to-text
│
▼
AI Agent
│
▼
Command
│
▼
ESP32
Example:
"Turn off the living room light."
AI:
{
"device": "living_room_light",
"action": "OFF"
}
ESP32 executes the command.
14. Face Recognition Flow
Person approaches entrance
│
▼
PIR detects
│
▼
Camera captures
│
▼
Face detection
│
▼
Face matching
/ \
/ \
Authorized Unknown
│ │
▼ ▼
Normal action Security event
│ │
▼ ▼
Unlock/lighting Telegram alert
│ │
└────────┬────────┘
▼
Google Sheets
│
▼
Dashboard
15. Important Face Recognition Design
For a robust implementation, I recommend putting the computationally expensive face-recognition operation on a camera-capable edge computer or dedicated vision system, rather than relying on the basic ESP32 for all recognition tasks.
Possible architecture:
ESP32-CAM
│
│ image
▼
Vision Processor
│
├── Face detection
├── Face embedding
└── Face matching
│
▼
ESP32 / n8n
The ESP32 remains responsible for actual device control.
This gives better separation between:
- vision
- control
- automation
- AI
- cloud services
16. n8n Workflow 1 — Sensor Monitoring
Basic workflow:
[Webhook]
│
▼
[Parse JSON]
│
├───────────────┐
▼ ▼
[Google Sheets] [ThingSpeak]
│
▼
[Threshold Check]
│
▼
[IF]
/ \
YES NO
| |
▼ ▼
Telegram End
Alert
17. ESP32 → n8n JSON
The ESP32 can send:
{
"device_id": "home_esp32_01",
"temperature": 28.6,
"humidity": 63.2,
"motion": true,
"door": false,
"light": 720,
"light_state": "ON",
"fan_state": "OFF",
"timestamp": "2026-08-22T22:30:00"
}
This is much easier for n8n to process than a custom binary protocol.
18. ESP32 HTTP Sensor Code
Example Arduino code:
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "DHT.h"
#define DHTPIN 27
#define DHTTYPE DHT22
#define PIR_PIN 4
#define DOOR_PIN 25
#define LDR_PIN 34
#define RELAY_LIGHT 5
#define RELAY_FAN 18
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";
const char* N8N_URL =
"https://YOUR-N8N-DOMAIN/webhook/iot/sensor";
DHT dht(DHTPIN, DHTTYPE);
bool lightState = false;
bool fanState = false;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(DOOR_PIN, INPUT_PULLUP);
pinMode(RELAY_LIGHT, OUTPUT);
pinMode(RELAY_FAN, OUTPUT);
digitalWrite(RELAY_LIGHT, LOW);
digitalWrite(RELAY_FAN, LOW);
dht.begin();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
}
void sendSensorData() {
if (WiFi.status() != WL_CONNECTED) {
return;
}
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int lightLevel = analogRead(LDR_PIN);
bool motion = digitalRead(PIR_PIN);
bool doorOpen = !digitalRead(DOOR_PIN);
StaticJsonDocument<512> doc;
doc["device_id"] = "home_esp32_01";
doc["temperature"] = temperature;
doc["humidity"] = humidity;
doc["light"] = lightLevel;
doc["motion"] = motion;
doc["door"] = doorOpen;
doc["light_state"] = lightState ? "ON" : "OFF";
doc["fan_state"] = fanState ? "ON" : "OFF";
String payload;
serializeJson(doc, payload);
HTTPClient http;
http.begin(N8N_URL);
http.addHeader("Content-Type", "application/json");
int response = http.POST(payload);
Serial.print("n8n response: ");
Serial.println(response);
http.end();
}
void loop() {
sendSensorData();
delay(30000);
}
The sample sends data every 30 seconds. You should adapt the interval to your ThingSpeak/service limits and desired telemetry rate.
ThingSpeak channels support up to eight data fields, and API keys are used for writing and reading channel data.
19. ESP32 Command Endpoint
The ESP32 can also periodically check n8n for commands.
Example:
ESP32
|
| GET /api/device/commands
▼
n8n
|
▼
Pending command
|
▼
ESP32
Example response:
{
"command_id": "CMD123",
"device": "fan",
"action": "ON"
}
The ESP32 executes it:
void executeCommand(String device, String action) {
if (device == "fan") {
if (action == "ON") {
digitalWrite(RELAY_FAN, HIGH);
fanState = true;
}
if (action == "OFF") {
digitalWrite(RELAY_FAN, LOW);
fanState = false;
}
}
if (device == "light") {
if (action == "ON") {
digitalWrite(RELAY_LIGHT, HIGH);
lightState = true;
}
if (action == "OFF") {
digitalWrite(RELAY_LIGHT, LOW);
lightState = false;
}
}
}
20. Better Command Architecture
For a production-style system, use a command API:
POST /webhook/iot/command
{
"device_id": "home_esp32_01",
"device": "fan",
"action": "ON",
"source": "telegram",
"user": "authorized_user"
}
The n8n workflow can then:
Command received
│
▼
Authentication
│
▼
Permission check
│
▼
AI interpretation
│
▼
Safety validation
│
▼
ESP32
│
▼
Execution result
│
▼
Logging
│
▼
Telegram
21. n8n Workflow 2 — Voice Command
Recommended workflow:
┌──────────────────┐
│ Telegram Trigger │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Get Voice File │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Speech-to-Text │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ AI Agent │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Validate Command │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ HTTP Request │
│ → ESP32 │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Google Sheets │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Telegram Reply │
└──────────────────┘
n8n's Telegram integration includes a Telegram trigger and message/file operations.
22. AI Agent Prompt
A useful system prompt is:
You are the AI controller for a smart home.
Your job is to interpret user commands and convert them
into safe structured IoT commands.
Available devices:
- living_room_light
- bedroom_light
- kitchen_light
- living_room_fan
- bedroom_fan
- main_door
- security_alarm
Allowed actions:
- ON
- OFF
- STATUS
Never invent a device.
Never execute an unsafe command.
Return JSON only.
Example:
{
"intent": "device_control",
"device": "bedroom_fan",
"action": "ON",
"confidence": 0.98
}
23. AI Agent Examples
User
Turn on the bedroom fan.
AI
{
"intent": "device_control",
"device": "bedroom_fan",
"action": "ON",
"confidence": 0.99
}
User
Switch off all lights.
AI:
{
"intent": "scene",
"device": "all_lights",
"action": "OFF",
"confidence": 0.98
}
User
What is the temperature?
AI:
{
"intent": "sensor_query",
"sensor": "temperature"
}
n8n can then retrieve the latest ESP32 data.
24. n8n AI Decision Workflow
User
│
▼
Voice/Text command
│
▼
AI Agent
│
┌────────┴────────┐
▼ ▼
Device command Information
│ │
▼ ▼
Validation Sensor DB
│
▼
ESP32 API
│
▼
Device action
│
▼
Confirmation
│
▼
Telegram
25. Telegram Alert System
Telegram should be used for:
- Intrusion alerts
- Unknown face alerts
- Door-open alerts
- High-temperature alerts
- Smoke/gas alerts
- Device failure
- ESP32 offline
- Power restoration
- AI-generated notifications
Example:
🚨 SMART HOME SECURITY ALERT
Unknown person detected.
Location: Main Entrance
Time: 22:41
Camera: Entrance Camera
Status: Unauthorized
Please check the security dashboard.
26. Telegram Voice Notification
The notification flow can be:
Security Event
│
▼
n8n
│
▼
Generate message
│
▼
Text-to-Speech
│
▼
Audio file
│
▼
Telegram Bot
│
▼
User's Phone
Example voice message:
"Security alert. An unknown person was detected at the main entrance."
This is especially useful when the user is away from the dashboard.
27. Google Sheets Logging
Create a spreadsheet:
Smart Home IoT Logs
Columns:
Timestamp
Device ID
Event Type
Device
Action
Temperature
Humidity
Motion
Door
Face
User
AI Decision
Status
Example:
| Timestamp | Event | Device | Action | Temperature | Face | Status |
|---|---|---|---|---|---|---|
| 22:31 | Voice | Fan | ON | 28.4 | User1 | Success |
| 22:33 | Motion | Light | ON | 28.7 | User1 | Success |
| 22:41 | Security | Door | ALERT | 27.9 | Unknown | Alert |
This gives you a complete audit trail.
28. ThingSpeak Data Model
Create a ThingSpeak channel with fields such as:
Field 1 → Temperature
Field 2 → Humidity
Field 3 → Light Level
Field 4 → Motion
Field 5 → Door
Field 6 → Fan State
Field 7 → Light State
Field 8 → Security Status
ThingSpeak channels can contain up to eight fields for streams of sensor data.
Example:
ThingSpeak
│
├── Temperature
├── Humidity
├── Light
├── Motion
├── Door
├── Fan
├── Light
└── Security
29. ThingSpeak Flow
ESP32
│
▼
n8n
│
├───────────────► Google Sheets
│
└───────────────► ThingSpeak
│
▼
Cloud Chart
│
▼
Web Dashboard
ThingSpeak provides channel APIs and API keys for data access.
30. ThingSpeak HTTP Request
A typical REST update concept is:
https://api.thingspeak.com/update
api_key=YOUR_WRITE_API_KEY
field1=28.6
field2=63.2
field3=720
field4=1
field5=0
field6=0
field7=1
field8=0
Do not expose the ThingSpeak write API key in a public GitHub repository or frontend JavaScript.
A better architecture is:
ESP32
│
▼
n8n
│
▼
ThingSpeak
so cloud credentials are kept on the server rather than embedded in the public web application.
31. IoT Web Dashboard
The dashboard can contain:
╔══════════════════════════════════════════════╗
║ AI SMART HOME DASHBOARD ║
╠══════════════════════════════════════════════╣
║ ║
║ Temperature 28.6 °C 🟢 NORMAL ║
║ Humidity 63 % 🟢 NORMAL ║
║ Motion DETECTED ║
║ Door CLOSED ║
║ ║
╠══════════════════════════════════════════════╣
║ LIGHTS ║
║ ║
║ Living Room [ ON ] ║
║ Bedroom [ OFF ] ║
║ Kitchen [ OFF ] ║
║ ║
╠══════════════════════════════════════════════╣
║ FANS ║
║ ║
║ Living Room [ OFF ] ║
║ Bedroom [ ON ] ║
║ ║
╠══════════════════════════════════════════════╣
║ SECURITY ║
║ ║
║ Face: Authorized ║
║ Door: Closed ║
║ Alarm: OFF ║
╚══════════════════════════════════════════════╝
32. Dashboard Technology
A simple implementation can use:
Frontend:
HTML
CSS
JavaScript
Backend:
n8n Webhook
Data:
ThingSpeak / n8n / Google Sheets
A more advanced version can use:
React
Node.js
WebSocket
REST API
Chart.js
33. Simple Web Dashboard
Example HTML:
<!DOCTYPE html>
<html>
<head>
<title>AI Smart Home</title>
<style>
body {
font-family: Arial;
background: #101820;
color: white;
margin: 0;
padding: 20px;
}
.dashboard {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(220px, 1fr));
gap: 20px;
}
.card {
background: #1c2935;
padding: 20px;
border-radius: 15px;
}
button {
padding: 10px 20px;
border: none;
border-radius: 8px;
cursor: pointer;
}
.on {
background: #00c853;
color: white;
}
.off {
background: #d50000;
color: white;
}
</style>
</head>
<body>
<h1>🏠 AI Smart Home</h1>
<div class="dashboard">
<div class="card">
<h2>Temperature</h2>
<h1 id="temperature">-- °C</h1>
</div>
<div class="card">
<h2>Humidity</h2>
<h1 id="humidity">-- %</h1>
</div>
<div class="card">
<h2>Living Room Light</h2>
<button class="on"
onclick="controlDevice('living_room_light','ON')">
ON
</button>
<button class="off"
onclick="controlDevice('living_room_light','OFF')">
OFF
</button>
</div>
<div class="card">
<h2>Bedroom Fan</h2>
<button class="on"
onclick="controlDevice('bedroom_fan','ON')">
ON
</button>
<button class="off"
onclick="controlDevice('bedroom_fan','OFF')">
OFF
</button>
</div>
</div>
<script>
const API =
"https://YOUR-N8N-DOMAIN/webhook/iot/command";
async function controlDevice(device, action) {
const response = await fetch(API, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
device: device,
action: action
})
});
const result = await response.json();
console.log(result);
}
</script>
</body>
</html>
For a real deployment, add authentication and authorization before exposing control endpoints to the Internet.
34. Complete Automation Flow
The overall system becomes:
┌───────────────┐
│ USER │
└───────┬───────┘
│
┌───────────────┼──────────────┐
│ │ │
▼ ▼ ▼
Voice Web Telegram
│ │ │
└───────────────┼──────────────┘
▼
┌───────────┐
│ n8n │
└─────┬─────┘
│
┌──────────┴──────────┐
▼ ▼
AI Agent Automation
│ │
└──────────┬──────────┘
▼
┌───────────┐
│ ESP32 │
└─────┬─────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
Sensors Camera Relays
│ │ │
│ ▼ ▼
│ Face Recognition Appliances
│ │
└─────────────────┼─────────────────┐
▼ │
n8n Cloud │
│ │
┌─────────────────┼──────────────┐ │
▼ ▼ ▼ │
Google Sheets ThingSpeak Telegram
│ │ │
└─────────────────┼──────────────┘
▼
Web Dashboard
35. Security Event Flow
Unknown person
│
▼
PIR detects movement
│
▼
Camera captures face
│
▼
Face recognition
│
▼
Unknown
│
▼
ESP32/n8n event
│
▼
Security workflow
│
├──────────────► Google Sheets
│
├──────────────► ThingSpeak
│
├──────────────► Telegram text
│
└──────────────► Telegram voice
│
▼
User
36. Authorized Person Flow
Person detected
│
▼
Face recognition
│
▼
Authorized?
│
YES
│
▼
Identify user
│
▼
Apply user profile
│
├── Turn on entrance light
├── Update dashboard
├── Log entry
└── Optional Telegram notification
37. Unknown Person Flow
Person detected
│
▼
Face recognition
│
▼
No matching face
│
▼
Security state = ALERT
│
├── Buzzer
├── Camera snapshot/event
├── Telegram alert
├── Voice alert
├── Google Sheets
└── Dashboard
For privacy and security, face images and biometric data should be handled carefully, stored only when necessary, and protected from unauthorized access.
38. Smart Automation Example
Suppose:
Temperature = 31°C
Motion = TRUE
Time = 20:00
Bedroom fan = OFF
n8n receives:
{
"temperature": 31,
"motion": true,
"fan": "OFF"
}
Workflow:
Temperature > 30?
│
YES
│
Motion detected?
│
YES
│
Fan OFF?
│
YES
│
Turn Fan ON
│
▼
Log event
│
▼
Telegram
Notification:
🤖 AI Smart Home
Bedroom temperature is 31°C.
Motion is detected and the bedroom fan
was automatically switched ON.
39. Intelligent Scene Automation
The project can support scenes.
Good Morning
7:00 AM
│
├── Bedroom light ON
├── Curtains OPEN
├── Fan OFF
└── Telegram summary
Away Mode
User leaves
│
▼
Away Mode
│
├── Lights OFF
├── Fans OFF
├── Security ON
└── Door monitoring ON
Night Mode
Night
│
├── Main lights OFF
├── Security ON
├── Entrance light LOW
└── Door monitoring ON
40. n8n Workflow Structure
A practical n8n project can contain several workflows.
Workflow A — ESP32 Sensor Receiver
Webhook
→ Validate JSON
→ Store data
→ ThingSpeak
→ Google Sheets
→ Threshold detection
Workflow B — Telegram Command
Telegram Trigger
→ Extract message
→ AI Agent
→ Validate
→ ESP32
→ Telegram response
Workflow C — Voice Command
Telegram Trigger
→ Download audio
→ Speech-to-text
→ AI Agent
→ Validate
→ ESP32
→ Telegram confirmation
Workflow D — Security
Webhook
→ Face event
→ Authorized?
→ IF
├── Authorized → log
└── Unknown → alert
Workflow E — Device Health
Schedule
→ Check ESP32
→ Is device online?
→ IF
├── YES → log
└── NO → Telegram alert
41. Device Health Monitoring
A very useful feature is heartbeat monitoring.
ESP32 sends:
{
"device_id": "home_esp32_01",
"event": "heartbeat",
"uptime": 54231
}
n8n stores the last heartbeat.
If:
Last heartbeat > 5 minutes
then:
ESP32 OFFLINE
Telegram:
⚠️ IoT Device Offline
Device: home_esp32_01
Last heartbeat: 6 minutes ago
Please check the power supply or Wi-Fi.
42. Local Fail-Safe Automation
Do not make basic home safety depend entirely on AI.
The ESP32 should retain local rules such as:
if (temperature > 40) {
digitalWrite(RELAY_FAN, HIGH);
}
and:
if (smokeDetected) {
digitalWrite(BUZZER, HIGH);
}
The cloud AI can provide higher-level intelligence, but safety-critical behavior should have a deterministic local fallback.
43. Communication Protocol
Use JSON over HTTPS where practical.
Example:
ESP32
│
│ HTTPS POST
▼
n8n Webhook
Sensor message:
{
"device_id": "ESP32_01",
"type": "sensor",
"data": {
"temperature": 28.5,
"humidity": 62,
"motion": true
}
}
Command:
{
"device_id": "ESP32_01",
"type": "command",
"device": "fan",
"action": "ON"
}
44. API Endpoints
Recommended endpoints:
POST /webhook/iot/sensor
POST /webhook/iot/event
POST /webhook/iot/command
GET /webhook/iot/status
POST /webhook/iot/face
POST /webhook/iot/heartbeat
Example:
POST /webhook/iot/sensor
receives sensor telemetry.
POST /webhook/iot/event
receives events such as:
{
"event": "unknown_face",
"location": "main_entrance"
}
45. Database/Data Flow
For a larger implementation, Google Sheets should be treated mainly as a convenient reporting/logging layer rather than the primary transactional database.
Recommended architecture:
ESP32
│
▼
n8n
│
├── Database
│
├── Google Sheets
│
├── ThingSpeak
│
└── Telegram
Google Sheets is excellent for:
- project demonstrations
- reports
- event history
- simple analytics
- academic projects
For a larger production deployment, use a proper database such as PostgreSQL.
46. Suggested Google Sheets Structure
Create these sheets:
1. SensorData
2. DeviceEvents
3. SecurityLogs
4. Commands
5. Users
6. DeviceStatus
SensorData
Timestamp
Device
Temperature
Humidity
Light
Motion
Door
Fan
Light
SecurityLogs
Timestamp
Camera
Person
Confidence
Location
Event
Action
Notification
Commands
Timestamp
User
Source
Command
Device
Action
AI Confidence
Result
47. AI Confidence
The AI Agent should provide a confidence value:
{
"device": "bedroom_fan",
"action": "ON",
"confidence": 0.97
}
A safety policy can be:
confidence >= 0.90
│
▼
execute
confidence < 0.90
│
▼
ask user for clarification
Example:
User:
"Make the room comfortable."
AI cannot safely determine the intended action.
The system should respond:
"Would you like me to turn on the bedroom fan or adjust the lights?"
48. AI Safety Rules
The AI Agent should never:
- Invent devices.
- Execute unknown commands.
- Expose passwords/API keys.
- Modify security settings without authorization.
- Disable alarms without authorization.
- Unlock doors based solely on an ambiguous voice command.
- Treat an unknown face as an authorized user.
For high-risk actions, use explicit confirmation.
Example:
User:
Unlock the main door.
AI:
I can unlock the main door.
Please confirm: UNLOCK MAIN DOOR
Then execute only after confirmation.
49. n8n Command Validation
A Code node can validate an AI response.
Example JavaScript:
const allowedDevices = [
"living_room_light",
"bedroom_light",
"kitchen_light",
"living_room_fan",
"bedroom_fan"
];
const allowedActions = [
"ON",
"OFF",
"STATUS"
];
const command = $json;
if (!allowedDevices.includes(command.device)) {
throw new Error("Invalid device");
}
if (!allowedActions.includes(command.action)) {
throw new Error("Invalid action");
}
return [{
json: {
valid: true,
device: command.device,
action: command.action
}
}];
50. Telegram Command Examples
The user can send:
/light bedroom on
or:
Turn on the bedroom light.
or:
Is the bedroom fan on?
or voice:
"Turn off all the lights."
The AI Agent converts natural language into a structured operation.
51. Example Telegram Conversation
USER:
Turn on the living room light.
BOT:
🤖 Processing your request...
AI:
Device = living_room_light
Action = ON
ESP32:
Command executed successfully.
BOT:
✅ Living room light is ON.
Another example:
USER:
What's the temperature?
BOT:
🌡️ Current temperature: 28.6°C
💧 Humidity: 63%
Security:
BOT:
🚨 SECURITY ALERT
Unknown person detected at the main entrance.
Time: 22:41
Status: Unauthorized
52. Full Project Sequence
The complete project operates as follows:
Step 1
Power on ESP32.
Step 2
ESP32 connects to Wi-Fi.
Step 3
ESP32 initializes sensors.
Step 4
Camera subsystem initializes.
Step 5
ESP32 begins reading sensor values.
Step 6
ESP32 sends telemetry to n8n.
Step 7
n8n validates the data.
Step 8
n8n writes data to Google Sheets.
Step 9
n8n updates ThingSpeak.
Step 10
n8n checks thresholds.
Step 11
If an abnormal event occurs, n8n starts the alert workflow.
Step 12
Telegram sends the user an alert.
Step 13
Voice alerts can be generated for important events.
Step 14
User can issue commands through Telegram/web/voice.
Step 15
AI Agent interprets the command.
Step 16
n8n validates the AI-generated command.
Step 17
n8n sends the command to ESP32.
Step 18
ESP32 activates the relay.
Step 19
ESP32 reports the result.
Step 20
n8n logs the action.
Step 21
Telegram confirms the result.
53. Complete End-to-End Diagram
SMART HOME
│
┌──────────────┴──────────────┐
│ │
Environment User
│ │
┌──────┼───────┐ ┌──────┼──────┐
▼ ▼ ▼ ▼ ▼ ▼
DHT PIR Door Voice Web Telegram
│ │ │ │ │ │
└──────┼───────┘ └──────┼──────┘
│ │
▼ ▼
ESP32 ─────────────────────► n8n
│ │
│ ┌──────┼─────────┐
│ │ │ │
│ ▼ ▼ ▼
│ AI Sheets ThingSpeak
│ Agent
│ │
│ ▼
│ Decision
│ │
◄──────────────────────┘
│
┌──────┼─────────┐
▼ ▼ ▼
Light Fan Security
│ │ │
└──────┼─────────┘
│
▼
Home Appliances
54. Project Installation Order
The safest implementation order is:
Phase 1 — ESP32
First implement:
ESP32
↓
LED
↓
Relay
↓
DHT
↓
PIR
Do not start with AI.
Phase 2 — Wi-Fi
Verify:
ESP32 → Wi-Fi
Phase 3 — HTTP
Verify:
ESP32 → n8n Webhook
Phase 4 — Cloud Logging
Add:
n8n → Google Sheets
n8n → ThingSpeak
Phase 5 — Telegram
Add:
n8n → Telegram
Phase 6 — Remote Control
Add:
Telegram → n8n → ESP32
Phase 7 — Voice
Add:
Voice → Speech-to-text → AI
Phase 8 — AI Agent
Add:
AI → Structured IoT command
Phase 9 — Face Recognition
Add:
Camera → Face recognition → n8n/ESP32
Phase 10 — Dashboard
Finally integrate the complete web dashboard.
This staged approach makes troubleshooting much easier.
55. Testing Plan
Test each subsystem independently.
Test 1 — ESP32
ESP32 powers on
✓
Test 2 — Sensor
Temperature displayed
✓
Test 3 — Relay
Relay switches
✓
Test 4 — Wi-Fi
ESP32 obtains IP
✓
Test 5 — n8n
Webhook receives JSON
✓
Test 6 — Google Sheets
New row created
✓
Test 7 — ThingSpeak
Graph receives data
✓
Test 8 — Telegram
Message received
✓
Test 9 — Remote command
Telegram
→ n8n
→ ESP32
→ relay
✓
Test 10 — AI
Voice
→ transcription
→ AI
→ command
→ ESP32
✓
Test 11 — Face
Camera
→ recognition
→ authorized/unknown
✓
Test 12 — Security
Unknown person
→ Telegram alert
✓
56. Failure Scenarios
The project should handle failures gracefully.
Internet failure
Internet OFF
│
▼
ESP32 continues local automation
│
▼
Cloud unavailable
n8n unavailable
n8n OFF
│
▼
ESP32 local rules continue
│
▼
Commands queued/retried when appropriate
Telegram unavailable
Telegram failure
│
▼
Event still logged
AI unavailable
AI unavailable
│
▼
Basic deterministic commands continue
For example:
"fan ON"
does not necessarily require AI if a fixed command parser can recognize it.
57. Security Architecture
Use:
HTTPS
API authentication
Webhook secrets
Strong Wi-Fi password
Unique device IDs
Access control
Rate limiting
Input validation
Never put these directly in public frontend code:
Wi-Fi password
n8n credentials
Telegram bot token
ThingSpeak write API key
AI API key
Google credentials
Use environment variables or secure credential storage on the server.
58. Recommended Authentication
Example device request:
POST /webhook/iot/sensor
Authorization: Bearer DEVICE_SECRET
Content-Type: application/json
n8n validates the secret before accepting the data.
For stronger deployments, use:
HTTPS
+
device authentication
+
rotatable credentials
59. Project Folder Structure
A clean project can use:
AI-Smart-Home/
│
├── esp32/
│ ├── main.ino
│ ├── config.h
│ ├── sensors.cpp
│ ├── sensors.h
│ ├── relay.cpp
│ └── relay.h
│
├── esp32-camera/
│ └── camera.ino
│
├── dashboard/
│ ├── index.html
│ ├── style.css
│ └── app.js
│
├── n8n/
│ ├── sensor-workflow.json
│ ├── command-workflow.json
│ ├── security-workflow.json
│ └── voice-workflow.json
│
├── docs/
│ ├── architecture.md
│ ├── wiring.md
│ └── testing.md
│
└── README.md
60. Recommended Project Demonstration
For an academic/project demonstration, demonstrate these six scenarios.
Demo 1 — Automatic Light
Person enters room
↓
PIR
↓
ESP32
↓
Light ON
Demo 2 — Voice Control
"Turn on bedroom fan"
↓
Telegram
↓
n8n
↓
AI Agent
↓
ESP32
↓
Fan ON
Demo 3 — Sensor Monitoring
DHT22
↓
ESP32
↓
n8n
↓
ThingSpeak
↓
Temperature graph
Demo 4 — Google Sheets
Device event
↓
n8n
↓
Google Sheets
↓
New log row
Demo 5 — Security
Unknown face
↓
n8n
↓
Telegram
↓
Voice alert
Demo 6 — AI Agent
Say:
"The bedroom is too hot."
AI interprets the intent and, based on your configured rules, can check temperature/fan status and recommend or execute an appropriate action.
61. Expected Output
The final system should provide:
✓ Automatic appliance control
✓ Voice control
✓ Face recognition
✓ Motion detection
✓ Temperature monitoring
✓ Humidity monitoring
✓ Door monitoring
✓ AI decision making
✓ n8n workflow automation
✓ Telegram alerts
✓ Telegram voice notifications
✓ Google Sheets logging
✓ ThingSpeak dashboard
✓ Web dashboard
✓ Remote control
✓ Device health monitoring
✓ Security alerts
62. Advantages
Intelligent
AI allows natural-language interaction.
Modular
Each component can be upgraded independently.
Low cost
ESP32 provides a low-cost IoT controller.
Cloud connected
Sensor information can be viewed remotely.
Automation
n8n reduces the amount of custom backend programming required.
Expandable
Additional devices can be added later.
Auditable
Google Sheets provides an easy-to-understand event history.
Real-time visualization
ThingSpeak provides cloud-based IoT visualization.
63. Limitations
The prototype has some limitations:
- ESP32 has limited computing resources.
- Advanced face recognition may require additional processing hardware.
- Internet-dependent features stop working if the cloud connection fails.
- AI decisions can be incorrect and therefore require validation.
- Telegram depends on Internet connectivity.
- Google Sheets is not intended to be a high-performance IoT database.
- Mains electrical loads require proper electrical safety.
- Biometric information requires strong privacy protection.
64. Future Enhancements
The project can be expanded with:
ESP32
+
ESP32-CAM
+
Edge AI
+
MQTT
+
PostgreSQL
+
Home Assistant
+
Mobile App
+
Voice Assistant
+
Energy Meter
+
Solar Monitoring
+
Smart Door Lock
+
Object Detection
+
Presence Detection
+
Predictive Automation
Advanced AI could eventually learn patterns such as:
User normally enters bedroom at 10 PM
│
▼
AI detects pattern
│
▼
Predicts lighting requirement
│
▼
Prepares automation
65. Final Architecture
The recommended final system is:
┌──────────────────┐
│ USER │
└────────┬─────────┘
│
┌─────────────┼──────────────┐
│ │ │
▼ ▼ ▼
Voice Web Telegram
│ │ │
└─────────────┼──────────────┘
▼
┌────────────────┐
│ n8n │
│ Automation │
│ AI Agent │
│ API Gateway │
└───────┬────────┘
│
┌──────────────────┼───────────────────┐
│ │ │
▼ ▼ ▼
AI Model Google Sheets ThingSpeak
│
▼
Command Validation
│
▼
ESP32
│
┌──────┼─────────┐
│ │ │
▼ ▼ ▼
Sensors Camera Relays
│ │ │
│ ▼ ▼
│ Face AI Appliances
│
▼
Environment Data
│
└──────────────────────► n8n
│
┌─────────────┴──────────────┐
▼ ▼
Telegram Alert Dashboard
│
▼
User Notification
66. Final Project Description
This project presents an AI-powered Agentic IoT smart home system based on ESP32. The ESP32 acts as the edge controller responsible for acquiring sensor data and controlling household appliances. Sensors such as DHT22, PIR, LDR and door sensors provide environmental and security information, while a camera/vision subsystem provides face-recognition capabilities.
The system communicates with an n8n automation server, which acts as the central workflow orchestration layer. n8n receives sensor events, executes automation rules, communicates with cloud services, manages notifications, and connects the IoT system to an AI Agent.
The AI Agent provides natural-language intelligence. Users can issue commands through text or voice, such as:
"Turn on the bedroom fan."
The voice command is converted into text, interpreted by the AI Agent, converted into a structured device command, validated by the automation workflow, and delivered to the ESP32. The ESP32 activates the corresponding relay and returns the device status.
The same platform supports security automation. When a person is detected, the camera/face-recognition system determines whether the person is authorized. Authorized events can trigger normal automation, while unknown-person events can trigger security workflows. n8n can then send Telegram text and voice alerts, record the event in Google Sheets, and update the cloud dashboard.
Sensor values can be sent to ThingSpeak for visualization and historical analysis. ThingSpeak supports channel-based data collection with multiple fields and API-key-based access.
The resulting system therefore combines:
IoT + Edge Computing + Face Recognition + Voice Interaction + AI Agents + n8n Automation + Telegram + Google Sheets + ThingSpeak + Web Dashboard
into one integrated smart-home platform.
The most important architectural principle is that AI should make the system smarter, not make the system unsafe. Essential local controls remain on the ESP32, while n8n and the AI Agent provide higher-level orchestration, interpretation, analytics and notifications.
67. One-Line Project Statement
"An AI-powered Agentic IoT smart home automation system that combines ESP32 edge control, voice and face recognition, n8n workflow automation, AI-agent decision making, Telegram voice alerts, Google Sheets logging, ThingSpeak cloud monitoring and a web-based IoT dashboard for intelligent, secure and remotely accessible home automation."
68. Recommended Implementation Stack
Hardware
ESP32
ESP32-CAM
DHT22
PIR
LDR
Door Sensor
Relay Module
Buzzer
Firmware
Arduino C/C++
Wi-Fi
HTTP/HTTPS
JSON
Automation
n8n
Webhooks
HTTP Request
AI Agent
AI
Speech-to-text
LLM
Text-to-speech
Face Recognition
Cloud
Google Sheets
ThingSpeak
Telegram
Frontend
HTML
CSS
JavaScript
Optional advanced backend
PostgreSQL
MQTT
Node.js
69. Documentation References
For implementation details, the current n8n documentation covers its Telegram integration and trigger/action capabilities.
ThingSpeak's documentation describes channel fields and API-key-based writing/reading.
Recommended next build
For an actual working prototype, I would build it in this exact order:
- ESP32 + DHT22 + PIR + relay
- ESP32 → n8n Webhook
- n8n → Google Sheets
- n8n → ThingSpeak
- Telegram Bot → ESP32 control
- Telegram voice → speech-to-text → AI Agent
- AI Agent → validated ESP32 commands
- ESP32-CAM → face recognition
- Unknown-face → Telegram text + voice alert
- HTML/JavaScript IoT dashboard
- Security, authentication and fail-safe logic
That sequence gives you a functioning project at every stage rather than trying to debug ESP32, camera, AI, n8n, Telegram and cloud services simultaneously.
