Offline energy monitor (Orange Pi)

Orange Pi Zero 3 stores PZEM data locally and shows graphs even without internet.

Server / Home Assistant Board: ESP32 DevKit V1 (WROOM-32) Level: ●●● ⏱ 3–5 h

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Graphs that work when the internet does not

Cloud dashboards are useless exactly when you need them. An Orange Pi Zero 3 on your local network collects the PZEM data from the ESP32 by MQTT, stores it, and serves a simple page with charts, with no connection to the outside.

Things that bite in practice

The board has no battery-backed clock. After a blackout it starts with a wrong date until it can reach an NTP server, and your graphs get a gap or a jump. Add a DS3231 RTC module, or take the timestamp from the ESP32 which already knows the time.

  • A full Grafana and InfluxDB stack is heavy for a board with 1 to 4 GB. A small Python script with SQLite and a static chart page is enough for one meter.
  • Write to the card in batches, say once a minute, to spare it.
  • Keep the Orange Pi on a UPS too. The card dislikes sudden power cuts, and so will you.
  • Export the daily totals to a CSV file for your own records.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • PZEM-004T v3.0 (100A, coil)
  • Orange Pi Zero 3 (2 GB)
  • microSD 32 GB A1 (industrial / high endurance)
  • Plastic project enclosure
  • Inline fuse holder + fuses

Wiring

Module Module pin ESP32 pin Note
PZEM-004T TX / RX UART GPIO16 / GPIO17
ESP32 ↔ Orange Pi Zero 3 Wi-Fi / LAN MQTT 1883 fully local, no cloud

Libraries

  • PZEM004Tv30
  • PubSubClient

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <PubSubClient.h>

const char* MQTT_HOST = "192.168.1.10";   // IP of your Raspberry Pi / mini-PC
const uint16_t MQTT_PORT = 1883;
const char* MQTT_USER = "esp32";
const char* MQTT_PASS = "mqtt-password";

WiFiClient netClient;
PubSubClient mqtt(netClient);

bool mqttConnect(const char* clientId) {
  mqtt.setServer(MQTT_HOST, MQTT_PORT);
  uint32_t t0 = millis();
  while (!mqtt.connected() && millis() - t0 < 10000) {
    if (mqtt.connect(clientId, MQTT_USER, MQTT_PASS)) return true;
    delay(500);
  }
  return mqtt.connected();
}
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(Serial2, 16, 17);
void setup() {
  Serial.begin(115200);
  connectWiFi();
  mqttConnect("esp32-energy");
}
void loop() {
  if (!mqtt.connected()) mqttConnect("esp32-energy");
  mqtt.loop();
  static uint32_t t = 0;
  if (millis() - t > 5000) {
    t = millis();
    String s = String("{"V":") + pzem.voltage() + ","A":" + pzem.current() + ","W":" + pzem.power() + ","kWh":" + pzem.energy() + "}";
    mqtt.publish("home/energy/main", s.c_str());
  }
}

docker-compose.yml

services:
  mosquitto:
    image: eclipse-mosquitto:2
    restart: unless-stopped
    ports: ["1883:1883"]
    volumes: ["./mosquitto:/mosquitto/config", "./mosquitto-data:/mosquitto/data"]
  nodered:
    image: nodered/node-red:latest
    restart: unless-stopped
    ports: ["1880:1880"]
    volumes: ["./nodered:/data"]

node-red-note.txt

In Node-RED: mqtt in (topic home/energy/main) → json → function (daily kWh) → file / dashboard. Install node-red-dashboard from the palette.

Build tips

  • Run all services in Docker and keep a nightly backup to a USB drive.
  • Keep one ESP32 per measuring point so a failure does not stop the others.

What you need

Buy the parts kit · Estimated total: $50.50

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
PZEM-004T v3.0 (100A, coil) × 1
$9.00
Buy at AliExpress Buy at Amazon.com
Orange Pi Zero 3 (2 GB) × 1
$25.00
Buy at AliExpress Buy at Amazon.com
microSD 32 GB A1 (industrial / high endurance) × 1
$8.00
Buy at AliExpress Buy at Amazon.com
Plastic project enclosure × 1
$3.00
Buy at AliExpress Buy at Amazon.com
Inline fuse holder + fuses × 1
$1.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Ukraine: we buy and sell these parts ourselves, order them on this site.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Smart energy meter

Reads voltage, current, power and kWh with PZEM-004T and publishes them to a web page, MQTT or Home Assistant.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–4 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Balcony solar power monitor

Measures output and yield of a plug-in solar kit with a PZEM meter and shows it on a web page or in Home Assistant.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–4 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Washing machine and dishwasher cycle notifier

Recognises the start and the end of an appliance cycle from its power draw and sends a message when it is finished, handy when power comes in windows.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.