Building a smart power strip to monitor each socket with ESP32 gives you granular control and real-time energy data for every appliance in your home. Unlike commercial smart plugs that monitor one device at a time, a DIY ESP32 smart power strip monitors 4-6 sockets simultaneously — tracking power consumption, setting per-socket schedules, and detecting abnormal energy draw. This is especially valuable in Indian homes where electricity tariffs are tiered and tracking individual appliance consumption can save thousands of rupees annually.
Table of Contents
- Project Overview and Benefits
- Required Components
- High-Voltage Safety Guidelines
- Circuit Design and Wiring
- Energy Monitoring with PZEM-004T
- ESP32 Firmware with MQTT
- Home Assistant Dashboard
- Frequently Asked Questions
Project Overview and Benefits
A 4-socket smart power strip with ESP32 offers:
- Per-socket ON/OFF control via app or voice
- Real-time power consumption per socket (watts, amps, voltage)
- Energy usage history and daily/monthly kWh tracking
- Overcurrent protection (software cutoff + hardware fuse)
- Schedule-based automation
- Home Assistant integration via MQTT or ESPHome
For Indian homes where peak-hour electricity rates are 2-3x higher (most state DISCOMs have time-of-use tariffs in 2026), knowing exactly which device consumes what power is invaluable.
Required Components
- ESP32 DevKit V1
- 4x 5V relay modules (or 1x 4-channel relay board)
- PZEM-004T V3.0 energy monitoring module (one per socket, or shared with multiplexing)
- Hindalco or Finolex 6A extension board (as base – strip and reuse)
- 4x 6A fuses + fuse holders
- HiLink HLK-PM05 5V power supply module (for ESP32 power)
- Metal or ABS project enclosure (larger than standard extension box)
- Terminal blocks and appropriate 10A wire
Budget: Rs 1,500-2,500 for a 4-socket smart power strip.
High-Voltage Safety Guidelines
Working with 230V AC mains is dangerous and potentially fatal. Follow these guidelines strictly:
- Always work with power disconnected from mains
- Use properly insulated wire rated for 10A minimum
- All mains-side connections must be inside a grounded metal or UL94 V0 rated plastic enclosure
- Use proper 6A fuses on each outlet leg
- Earth (ground) all metal enclosure surfaces
- Keep low-voltage ESP32 circuitry optically isolated from mains side via relay
- If unsure, hire a licensed electrician to verify your wiring before powering on
This project should only be attempted by those with prior electronics experience. Do not rush the assembly.
Circuit Design and Wiring
The circuit has two completely separate sections: the mains (230V) side and the control (5V/3.3V) side.
MAINS SIDE (230V AC - DANGER):
Input Live (L) -+- Fuse 1 - Relay 1 NO - Socket 1 Live
+- Fuse 2 - Relay 2 NO - Socket 2 Live
+- Fuse 3 - Relay 3 NO - Socket 3 Live
+- Fuse 4 - Relay 4 NO - Socket 4 Live
Input Neutral (N) ---- All Socket Neutrals
Input Earth (E) ------ All Socket Earths + Enclosure
PZEM-004T: Insert CT (current transformer) clamp
around the Live wire AFTER the relay,
before the socket - one per monitored socket
CONTROL SIDE (5V/3.3V - SAFE):
HiLink HLK-PM05: Input = L+N mains, Output = 5V
5V -- ESP32 VIN
5V -- Relay module VCC (each relay)
ESP32 GPIO pins -- Relay IN pins:
GPIO 16 -> Relay 1 (Socket 1)
GPIO 17 -> Relay 2 (Socket 2)
GPIO 18 -> Relay 3 (Socket 3)
GPIO 19 -> Relay 4 (Socket 4)
ESP32 GPIO 16/17 (RX2/TX2) -> PZEM-004T RX/TX
Energy Monitoring with PZEM-004T
The PZEM-004T V3.0 is a popular energy monitoring module widely available in India (Rs 400-600 each). It measures:
- Voltage (80-260V AC, accuracy 0.5%)
- Current (0-10A with built-in CT, 0-100A with external CT)
- Power (0-2300W)
- Energy (kWh accumulated)
- Frequency (45-65 Hz)
- Power factor
#include <PZEM004Tv30.h>
// PZEM on Serial2 of ESP32
PZEM004Tv30 pzem(Serial2, 16, 17); // RX, TX
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float energy = pzem.energy(); // kWh
float frequency = pzem.frequency();
float pf = pzem.pf(); // Power factor
// Print readings
Serial.printf("Voltage: %.1f Vn", voltage);
Serial.printf("Current: %.3f An", current);
Serial.printf("Power: %.1f Wn", power);
Serial.printf("Energy: %.3f kWhn", energy);
Serial.printf("PF: %.2fn", pf);
ESP32 Firmware with MQTT
#include <WiFi.h>
#include <PubSubClient.h>
#include <PZEM004Tv30.h>
#include <ArduinoJson.h>
const char* ssid = "YOUR_WIFI";
const char* mqttServer = "192.168.30.100"; // Home Assistant IP
const int relayPins[] = {16, 17, 18, 19};
bool socketState[] = {false, false, false, false};
WiFiClient wifiClient;
PubSubClient mqtt(wifiClient);
PZEM004Tv30 pzem(Serial2, 25, 26);
void callback(char* topic, byte* payload, unsigned int length) {
String msg = String((char*)payload, length);
// Parse topic: smartstrip/socket/1/set
String topicStr = String(topic);
int socketNum = topicStr.charAt(20) - '1'; // 0-indexed
if (socketNum >= 0 && socketNum < 4) {
bool newState = (msg == "ON");
digitalWrite(relayPins[socketNum], newState ? LOW : HIGH);
socketState[socketNum] = newState;
// Publish state
String stateTopic = "smartstrip/socket/" + String(socketNum+1) + "/state";
mqtt.publish(stateTopic.c_str(), newState ? "ON" : "OFF");
}
}
void publishEnergy() {
StaticJsonDocument<200> doc;
doc["voltage"] = pzem.voltage();
doc["current"] = pzem.current();
doc["power"] = pzem.power();
doc["energy"] = pzem.energy();
doc["pf"] = pzem.pf();
String output;
serializeJson(doc, output);
mqtt.publish("smartstrip/energy", output.c_str());
}
void setup() {
for (int i = 0; i 10000) { // Every 10s
publishEnergy();
lastPub = millis();
}
}
Home Assistant Dashboard
Add these to your configuration.yaml to create full smart power strip entities in Home Assistant:
mqtt:
switch:
- name: "Smart Strip Socket 1"
command_topic: "smartstrip/socket/1/set"
state_topic: "smartstrip/socket/1/state"
icon: mdi:power-socket-in
sensor:
- name: "Strip Power"
state_topic: "smartstrip/energy"
value_template: "{{ value_json.power }}"
unit_of_measurement: W
device_class: power
- name: "Strip Energy Today"
state_topic: "smartstrip/energy"
value_template: "{{ value_json.energy }}"
unit_of_measurement: kWh
device_class: energy
Frequently Asked Questions
Is it safe to build a mains-connected device at home?
It can be safe if you follow proper guidelines. Use quality components rated for 10A+, use proper insulation, include fuses on each outlet, and have a licensed electrician review your wiring before first power-on. If you are not comfortable with mains wiring, purchase a commercial smart power strip and use it alongside an ESP32 for monitoring only.
How accurate is PZEM-004T for electricity billing?
The PZEM-004T has a stated accuracy of 0.5% for voltage and 1% for power — sufficient for practical energy monitoring. It will not match your DISCOM smart meter exactly due to CT placement and calibration differences, but is accurate enough for tracking relative appliance consumption and identifying energy hogs.
Can I monitor surge protector power strip without opening it?
Not easily. The PZEM CT clamp must encircle the live wire after the relay. However, you can use a commercial smart plug (TP-Link Kasa, Shelly PM) on individual sockets for non-invasive monitoring, and integrate those with Home Assistant for energy tracking without any 230V DIY work.
What is the maximum load per socket?
Design your smart strip for 6A per socket (1,380W at 230V Indian mains). This covers most home appliances: laptop chargers (65-100W), phone chargers (20-65W), desk fans (30-75W), LED TVs (50-150W). Do not use it for high-load appliances like geysers, ACs, or induction cooktops – those need dedicated smart plugs with appropriate ratings.
Add comment