Agentic AI Smart Grid Load Analytics and Real-Time Energy Optimization System Using ESP32, n8n, Telegram Voice Alerts, Google Sheets & ThingSpeak

1. Project Overview
This project provides a real-time smart grid energy monitoring and optimization system using ESP32,
AI-powered analytics, n8n workflow automation, Telegram alerts, Google Sheets logging, and
ThingSpeak cloud visualization.
2. System Architecture
Smart Sensors
|
V
ESP32
|
V
n8n
|
------------------
| | |
V V V
AI Google ThingSpeak
Agent Sheets Dashboard
|
V
Telegram Alerts
3. Components List
| Component |
Quantity |
| ESP32 Dev Board | 1 |
| ACS712 Current Sensor | 1 |
| ZMPT101B Voltage Sensor | 1 |
| Relay Module | 1 |
| OLED Display | 1 |
| WiFi Router | 1 |
| Power Supply | 1 |
4. Circuit Connections
| Module |
ESP32 Pin |
| ACS712 OUT | GPIO34 |
| ZMPT101B OUT | GPIO35 |
| OLED SDA | GPIO21 |
| OLED SCL | GPIO22 |
| Relay IN | GPIO26 |
5. Flowchart
START
|
ESP32 Initialization
|
Connect WiFi
|
Read Sensors
|
Calculate Power
|
Send Data to n8n
|
AI Analysis
|
Load High?
/ \
Yes No
| |
Alert Continue
|
Voice Alert
|
Relay Control
|
Repeat
6. Power Calculation
Power = Voltage × Current
7. ESP32 Arduino Source Code
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid="YOUR_WIFI";
const char* password="YOUR_PASSWORD";
String webhookURL=
"https://your-n8n-domain/webhook/energy";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED)
{
delay(500);
}
}
void loop()
{
float voltage=220;
float current=5;
float power=voltage*current;
HTTPClient http;
http.begin(webhookURL);
http.addHeader(
"Content-Type",
"application/json"
);
String payload=
"{";
payload += "\"voltage\":220,";
payload += "\"current\":5,";
payload += "\"power\":1100";
payload += "}";
http.POST(payload);
http.end();
delay(15000);
}
8. n8n Workflow
Workflow Sequence:
- Webhook Node
- Function Node
- AI Agent Node
- IF Condition
- Telegram Node
- Google Sheets Node
- ThingSpeak Update Node
9. Telegram Bot Setup
- Open Telegram
- Search BotFather
- Create new bot using /newbot
- Copy Bot Token
- Get Chat ID
- Configure in n8n
10. Google Sheets Integration
| Timestamp |
Voltage |
Current |
Power |
Prediction |
Status |
| 2026-06-12 |
230 |
4.2 |
966 |
1050 |
Normal |
11. ThingSpeak Dashboard Fields
- Field1 = Voltage
- Field2 = Current
- Field3 = Power
- Field4 = Prediction
12. AI Prediction Logic
Future Power =
(P1+P2+P3+P4+P5)/5
The AI Agent predicts future energy consumption using historical readings,
moving averages, machine learning, or LSTM forecasting models.
13. Voice Notification Logic
ESP32 Data
|
V
n8n Workflow
|
Text-To-Speech
|
MP3 Generation
|
Telegram Voice Message
14. Agentic AI Decision Rules
| Condition |
Action |
| Power > 1000W |
Warning Alert |
| Power > 1500W |
Relay Shutdown |
| Peak Load Expected |
Optimization Suggestion |
15. Future Enhancements
- LSTM Forecasting
- MQTT Integration
- Grafana Dashboard
- Solar Monitoring
- Battery Management
- Reinforcement Learning
- Edge AI Processing
16. Deployment Architecture
ESP32
|
MQTT Broker
|
n8n Automation
|
AI Agent
|
-----------------
| | |
V V V
Sheets Cloud Telegram
Project Folder Structure
SmartGridProject/
│
├── index.php
├── css/
│ └── style.css
│
├── images/
│ ├── architecture.png
│ ├── circuit.png
│ └── flowchart.png
│
├── docs/
│ ├── ESP32_Code.ino
│ ├── n8n_Workflow.json
│ └── README.pdf
│
└── assets/
For a final-year project, a better approach is to create a complete PHP web application with Login Page, Live Dashboard, ThingSpeak API Integration, Google Sheets Logging, Telegram Alert Management, AI Prediction Charts, MySQL Database, and Admin Panel rather than a single static PHP page
Comments
Post a Comment