Agentic AI Smart Grid Load Analytics and Real-Time Energy Optimization System Using ESP32

Agentic AI Smart Grid Load Analytics and Real-Time Energy Optimization System Using ESP32, n8n, Telegram Voice Alerts, Google Sheets & ThingSpeak
<?php echo $title; ?>

Agentic AI Smart Grid Load Analytics

ESP32 + n8n + AI Agent + 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 Board1
ACS712 Current Sensor1
ZMPT101B Voltage Sensor1
Relay Module1
OLED Display1
WiFi Router1
Power Supply1

4. Circuit Connections

Module ESP32 Pin
ACS712 OUTGPIO34
ZMPT101B OUTGPIO35
OLED SDAGPIO21
OLED SCLGPIO22
Relay INGPIO26

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:

  1. Webhook Node
  2. Function Node
  3. AI Agent Node
  4. IF Condition
  5. Telegram Node
  6. Google Sheets Node
  7. ThingSpeak Update Node

9. Telegram Bot Setup

  1. Open Telegram
  2. Search BotFather
  3. Create new bot using /newbot
  4. Copy Bot Token
  5. Get Chat ID
  6. 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