Siddhant Kumar
Project 070 · Energy

Smart Energy Meter.

A single whole-home meter that not only shows real-time consumption but disaggregates it into appliance-level insights — telling you what is using power, from one measurement point.

Advanced 14–22 hours 31 min read EnergyMeteringApp
Jump to source Bill of materials
Smart Energy Meter — reference build illustration MCU VCC · GND · SIG · NC
Difficulty
Advanced
Build time
14–22 hours
Indicative cost
₹3,500 – ₹6,000
Platform
ESP32 DevKit V1 (ESP-WROOM-32)
Category
Energy
Last updated
28 July 2026
Contents — 27 sections

Project Overview

A single whole-home meter that not only shows real-time consumption but disaggregates it into appliance-level insights — telling you what is using power, from one measurement point.

A conventional meter gives you one number: total consumption. It cannot tell you that the geyser is your biggest cost, that a fridge is failing and drawing more each week, or that something is left on overnight. Sub-metering every circuit is expensive and invasive. This project takes a smarter route: a single whole-home meter that measures the total, and then disaggregates that total into appliance-level insights using the technique called non-intrusive load monitoring (NILM) — inferring which appliances are running, and how much each is using, from the aggregate signal at one measurement point.

The foundation is accurate real-time whole-home measurement — real power, energy and power factor from a CT clamp or meter module on the incoming supply. On top of that sits the disaggregation: appliances have characteristic signatures in the aggregate power signal — a heating element switches on as a clean rectangular step of a specific size, a motor draws an inrush spike then settles, an electronic device has its own pattern — so when the total power steps up by ~2 kW in a rectangular fashion, that is very likely the geyser turning on. By detecting these on/off events and matching their signatures to known appliances, the meter attributes the total consumption to individual loads without a sensor on each one.

The result is genuinely useful: real-time and historical consumption, a breakdown of which appliances cost the most, alerts when an appliance behaves abnormally (a fridge cycling too often, a heater left on), and the data to actually reduce a bill. It is honest that NILM is an inference, not a measurement — it works best for larger, distinct loads and struggles to separate several small or similar appliances, and it needs a training/learning phase to recognise a home's specific appliances — so its appliance figures are informative estimates, not billing-grade sub-metering. But as a single-point meter that combines accurate whole-home measurement with appliance-level disaggregation, it delivers most of the value of expensive per-circuit sub-metering from one clamp, turning an opaque bill into an itemised, actionable picture of where the energy goes.

An ESP32 development board with the ESP-WROOM-32 module and USB connector
A single whole-home meter that disaggregates the total into appliance-level insight. Photograph sourced from Wikimedia Commons — ESP32 Espressif ESP-WROOM-32 Dev Board.jpg. Reused under the licence stated on that page; please check it before republishing.

What this project does

  • Measures accurate real-time whole-home power, energy and power factor
  • Disaggregates the total into appliance-level usage (NILM)
  • Detects appliance on/off events by their power signatures
  • Attributes consumption and cost to individual appliances
  • Learns a home's specific appliances during a training phase
  • Alerts on abnormal appliance behaviour (failing/left-on)
  • Turns an opaque bill into an itemised, actionable breakdown

Real-World Applications

SettingHow it is used
Home energy awarenessSeeing which appliances cost the most and where to cut, from one meter.
Appliance fault detectionCatching a failing fridge/pump drawing more, or something left on.
Demand/efficiency programmesAppliance-level data for efficiency advice and demand response.
Elderly / activity awarenessInferring appliance usage patterns (with consent) for wellbeing.

Deployment contexts where a build of this kind earns its keep.

Features & Capabilities

  • Single-point measurement, appliance-level insight
  • Event-detection + signature-matching NILM
  • Real power/energy/PF whole-home base
  • Per-appliance cost breakdown
  • Learned per-home appliance models
  • Abnormal-behaviour alerts
  • Honest: NILM is inference, not per-appliance metering

Difficulty, Time & Required Skills

AttributeValue
Difficulty levelAdvanced
Estimated completion time14–22 hours
Indicative build cost₹3,500 – ₹6,000
Primary disciplineEnergy
Reference platformESP32 DevKit V1 (ESP-WROOM-32)

Skills you should have (or will pick up)

  • Whole-home real-power measurement (CT/meter)
  • Event detection in the aggregate power signal
  • Appliance signature extraction and matching (NILM)
  • Learning/training per-home appliance models
  • Consumption attribution and alerting

Bill of Materials

Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.

ComponentKey specificationQtyApprox. cost
ESP32 DevKit V1 (ESP-WROOM-32)
Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC1₹450
PZEM-004T v3 AC energy meter (100 A CT)
The measurement side sits at mains potential — the opto-isolated UART is the only safe boundary.
80–260 VAC, 0–100 A, voltage/current/power/energy/PF/frequency, ±0.5 %1₹950
ACS712 hall-effect current sensor (20 A)
Zero-offset drifts with temperature — re-zero at boot with no load.
±20 A, 100 mV/A, 80 kHz bandwidth, 1.2 mΩ internal resistance, 2.1 kV isolation1₹180
ZMPT101B AC voltage sensor
Trim the on-board pot so the idle output sits exactly at Vcc/2.
0–250 VAC input, 2 mA:2 mA precision transformer, ±1 % linearity1₹220
0.96″ SSD1306 OLED display
Static images burn in — invert or scroll the screen periodically.
128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C1₹250
microSD card 32 GB A1 class
For 24/7 loggers buy a high-endurance card — normal cards die in months.
A1 rated, 10 MB/s random write, UHS-I, endurance-grade recommended1₹450
5 V 3 A regulated SMPS adapter
Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A.
100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection1₹350
CT clamp / meter on the main
Whole-home real-power measurement
Split-core CT + voltage ref, or a PZEM with CT, on the incoming supply1₹900
Higher-rate sampling front-end
Signature detection benefits from higher-rate data
For capturing transients/signatures (fast ADC or a metering IC)1₹600
Compute for NILM
Match compute to the NILM method
ESP32 for simple event NILM; a Pi for heavier disaggregation/ML1
DIN enclosure + isolationSafe mains-side enclosure and isolation1₹700

Estimated total: ₹5,050, excluding tools, shipping and consumables.

Tools and consumables

  • Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
  • Digital multimeter — continuity, DC volts and current ranges
  • Wire strippers, flush cutters and a small set of precision screwdrivers
  • Heat-shrink tubing and a heat gun (or a lighter, carefully)
  • A laptop with a USB port and the toolchain listed above

Hardware Specifications

PartSpecificationSupplyInterfaceReference
ESP32 DevKit V1 (ESP-WROOM-32)Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC3.3 V logic / 5 V USBUART, SPI, I²C, I²S, CAN, PWMDatasheet
PZEM-004T v3 AC energy meter (100 A CT)80–260 VAC, 0–100 A, voltage/current/power/energy/PF/frequency, ±0.5 %5 V logic sideUART Modbus-RTU 9600Datasheet
ACS712 hall-effect current sensor (20 A)±20 A, 100 mV/A, 80 kHz bandwidth, 1.2 mΩ internal resistance, 2.1 kV isolation5 VAnalogueDatasheet
ZMPT101B AC voltage sensor0–250 VAC input, 2 mA:2 mA precision transformer, ±1 % linearity5 VAnalogueDatasheet
0.96″ SSD1306 OLED display128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C3.3–5 VI²C (0x3C)Datasheet
microSD card 32 GB A1 classA1 rated, 10 MB/s random write, UHS-I, endurance-grade recommended3.3 VSDIO / SPIDatasheet
5 V 3 A regulated SMPS adapter100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection5 VDC barrel / USBDatasheet

Consolidated electrical and interface specifications for every active part in the build.

Power Budget & Supply Sizing

Add up the typical active current of every part, then size the supply with at least 50 % headroom so transmit bursts and motor inrush never brown out the controller.

LoadSupply railTypical current (mA)Notes
ESP32 DevKit V1 (ESP-WROOM-32)3.3 V logic / 5 V USB160Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
PZEM-004T v3 AC energy meter (100 A CT)5 V logic side20The measurement side sits at mains potential — the opto-isolated UART is the only safe boundary.
ACS712 hall-effect current sensor (20 A)5 V10Zero-offset drifts with temperature — re-zero at boot with no load.
ZMPT101B AC voltage sensor5 V20Trim the on-board pot so the idle output sits exactly at Vcc/2.
0.96″ SSD1306 OLED display3.3–5 V20Static images burn in — invert or scroll the screen periodically.
microSD card 32 GB A1 class3.3 V100For 24/7 loggers buy a high-endurance card — normal cards die in months.
5 V 3 A regulated SMPS adapter5 V3000Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A.

Summed typical draw is 3330 mA. With a 1.5× design margin the supply should deliver at least 5000 mA continuously at the stated rail voltage.

Software Requirements & Development Environment

Reference toolchain: Arduino IDE 2.3.x with the ESP32 board package 3.x (or PlatformIO on VS Code). Anything newer normally works; anything older may lack the board definitions used here.

  • Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
  • Add https://espressif.github.io/arduino-esp32/package_esp32_index.json under File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager.
  • Set the correct port under Tools → Port. On Linux add yourself to the dialout group: sudo usermod -aG dialout $USER and log out and back in.
  • Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
  • Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.

Required libraries

LibraryWhy it is neededInstall
WiFi (ESP32 core) bundledStation/AP connection management for the ESP32.Bundled with the ESP32 Arduino core
PubSubClient 2.8Lightweight MQTT 3.1.1 client for constrained devices.Library Manager → "PubSubClient" by Nick O'Leary
Adafruit SSD1306 + GFX 2.5.xFramebuffer and text/graphics primitives for the OLED.Library Manager → "Adafruit SSD1306"
InfluxDB 2.x + Telegraf 2.7Time-series storage with retention policies and downsampling.docker run -p 8086:8086 influxdb:2.7
Python 3.11+Runtime for the analysis, training and service code.sudo apt install python3 python3-venv python3-pip
scikit-learn 1.5+Classical models, preprocessing pipelines and evaluation metrics.pip install scikit-learn
NumPy 1.26+Vectorised array maths underpinning every other library here.pip install numpy

Block Diagram

The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.

Smart Energy Meter — system block diagramFunctional block diagram of the Smart Energy Meter system. MeasureWhole-homereal power/PFDetectEventson/off stepsSignaturesstep size/shapeDisaggregateMatchappliance modelsAttributeusage + costInsightBreakdownper applianceAlertsabnormal/left-onrightrightnone
Smart Energy Meter — system block diagram

Circuit Diagram & Wiring

Every signal line in the build is shown below, followed by a pin-by-pin connection table you can work through with a multimeter in hand.

Smart Energy Meter — wiring schematicConnection schematic showing which controller pin drives each peripheral. Sensors / InputsControllerActuators / OutputsESP32 DevKit V1(ESP-WROOM-32)3.3 V logic / 5 V USBCT / PZEMGPIO 16/17 / ADCWhole-homecurrent/powerVoltage refGPIO 35 (ADC)Mains voltage (realpower/PF)OLEDGPIO 21/22Live total +breakdownWi-FiDashboard / NILMoffloadmicroSDshared + CSLog/training dataIsolated supply3V3 regPower
Smart Energy Meter — wiring schematic
PeripheralPeripheral pinController pinSignal
CT / PZEMUART/AOUTGPIO 16/17 / ADCWhole-home current/power
Voltage refAOUTGPIO 35 (ADC)Mains voltage (real power/PF)
OLEDSDA/SCLGPIO 21/22Live total + breakdown
Wi-Fion-chipDashboard / NILM offload
microSDSPIshared + CSLog/training data
Isolated supply+/–3V3 regPower

Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.

Wiring explanation

  • Measure whole-home real power (and power factor) with a CT + voltage reference or a metering module on the incoming supply; have a qualified electrician do the mains-side install.
  • Sample fast enough to capture appliance switching transients if using transient signatures; steady-state step detection needs less.
  • Keep the low-voltage electronics isolated from the mains measurement.
  • For heavier NILM/ML, offload to a Pi/server; the ESP32 can do simple event-based disaggregation.
  • Log data during a training phase so appliance signatures can be learned.
A Grafana time-series dashboard
ESP32 module measuring real power and detecting appliance on/off events for NILM. Photograph sourced from Wikimedia Commons — Grafana dashboard.png. Reused under the licence stated on that page; please check it before republishing.

System Architecture

Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.

Smart Energy Meter — architecture stackLayered architecture from hardware to user interface. Hardware layerESP32 DevKit V1 (ESP-WROOM-32) · ACS712 hall-effect current sensor (20 A)· ZMPT101B AC voltage sensorDriver layerwifi · pubsub · ssd1306 · influxApplication logicsampling loop · filtering · thresholds · state machinePresentation layerlocal display · serial console · logged output
Smart Energy Meter — architecture stack

Working Principle

The meter's ambition is to give appliance-level insight from a single measurement point, which is valuable because per-appliance sub-metering is expensive and invasive while a single whole-home meter is cheap and non-invasive. The bridge between the two is non-intrusive load monitoring — the idea that the aggregate electrical signal at the meter contains, mixed together, the individual contributions of every running appliance, and that with the right processing you can pull those contributions back apart. It rests on accurate whole-home measurement as its foundation and clever inference as its magic.

The foundation must be solid: accurate real-power measurement of the whole home, including power factor, because everything downstream is inference on top of it. A CT clamp with a voltage reference (or a metering module) on the incoming supply gives real-time total power and energy. This alone is useful — real-time consumption feedback measurably reduces usage — but it is the raw material for the disaggregation.

Disaggregation works because appliances have distinctive signatures in the aggregate signal. When an appliance switches on or off, the total power steps, and the size and shape of that step is characteristic: a resistive heater (geyser, kettle, iron) switches as a clean, rectangular step of a specific magnitude; a motor (fridge compressor, pump) shows a brief inrush spike then settles to a running level; electronic devices have their own patterns; some appliances even cycle in recognisable rhythms. The classic, tractable NILM approach is event-based: detect these on/off events in the power stream, extract each event's signature (step magnitude, transient shape, power factor change), and match it to a library of known appliance signatures, thereby attributing that chunk of consumption to that appliance. More advanced NILM uses machine-learning models, but the event-and-signature approach captures the core idea and runs on modest hardware.

The output is an itemised, actionable picture — which appliances cost the most, when they run, and how their behaviour changes — enabling real savings and catching faults (a fridge cycling too often, a heater left on). But the design is honest about NILM's nature: it is an inference, not a measurement, and it has real limits. It works best for larger, distinct loads whose signatures stand out, and struggles to separate several small or similar appliances whose events overlap or look alike; it needs a learning/training phase to recognise a specific home's appliances, since signatures vary between makes and models; and its attributions are best-estimates, not billing-grade sub-metering. So the meter presents appliance figures as informative estimates, is upfront about uncertainty, and leans on the rock-solid whole-home total for anything that must be exact. Within that frame, it delivers most of the value of expensive per-circuit metering from a single clamp — the genuinely useful trick of turning one aggregate signal into an appliance-by-appliance understanding of where a home's energy, and money, goes.

The maths behind it

Whole-home real power (foundation)

plainWhole-home real power (foundation)
P = V_rms · I_rms · cosφ   (real power, W)
E = ∫ P dt                  (energy, kWh)

Accurate real power + power factor is the base signal NILM
disaggregates. Current alone (apparent power) is not enough.

Event detection

plainEvent detection
Detect steps in the power stream:

  ΔP = P(t) − P(t−Δ)
  event if |ΔP| > threshold (sustained)  → appliance on/off

Each event's magnitude, sign and transient shape form its
signature.

Signature matching (NILM)

plainSignature matching (NILM)
Match an event signature s to appliance models {m}:

  appliance = argmin_m distance(s, signature(m))
  attribute the step power to that appliance until its OFF event

Best for large/distinct loads; small/similar loads overlap →
report as estimates, learn per-home models.

Program Flowchart

The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.

Smart Energy Meter — firmware flowchartControl flow through the main program loop. Measure whole-home powerPower step (on/off event)?Extract signature; match applianceUpdate totalsExtract signature; matchapplianceAttribute consumption toapplianceUpdate totalsAbnormal behaviour?AlertReport breakdownAlertReport breakdown
Smart Energy Meter — firmware flowchart

Assembly Instructions

Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.

  1. Install accurate whole-home measurement

    Fit a CT + voltage reference (or metering module) on the incoming supply for real power/PF, installed by a qualified electrician, with the electronics isolated from the mains.

    Sample fast enough to capture the switching transients your NILM method uses.

  2. Set up event detection and learning

    Detect on/off events in the power stream and log a training period so appliance signatures can be learned (label known appliances by switching them).

  3. Set up disaggregation and reporting

    Match events to appliance models, attribute consumption, and report the breakdown and alerts; offload heavier NILM to a Pi/server if needed.

Step-by-Step Implementation Guide

Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.

  1. Detect events and disaggregate

    Detect power steps, extract each event's signature, match to the appliance library, and attribute consumption until the matching off-event.

    pythonnilm-event.py
    # Event-based NILM: detect steps, match signatures, attribute energy.
    import numpy as np
    
    class Appliance:
        def __init__(self, name, step_w, pf, tol=0.15):
            self.name, self.step_w, self.pf, self.tol = name, step_w, pf, tol
        def matches(self, dP, pf):
            return abs(dP - self.step_w) < self.tol*self.step_w and abs(pf-self.pf)<0.1
    
    def detect_events(power, pf, thresh=150):
        events = []
        for t in range(1, len(power)):
            dP = power[t] - power[t-1]
            if abs(dP) > thresh:                      # a step = appliance on/off
                events.append((t, dP, pf[t]))
        return events
    
    def disaggregate(events, library):
        active = {}                                    # appliance -> power
        usage  = {a.name: 0.0 for a in library}
        for (t, dP, pf) in events:
            if dP > 0:                                 # turn-on
                for a in library:
                    if a.matches(dP, pf): active[a.name] = dP; break
            else:                                      # turn-off
                for name, p in list(active.items()):
                    if abs(-dP - p) < 0.2*p: del active[name]; break
        return active, usage
    def detect_events(power, pf, thresh=150)Finds steps in the aggregate power — the on/off events of individual appliances that NILM keys on.
    def matches(self, dP, pf)An appliance is recognised when a power step matches its characteristic magnitude and power factor, the essence of signature matching.
    if dP > 0: # turn-onA positive step is an appliance turning on and is matched to the library; the attributed power runs until its off-event.
    if abs(-dP - p) < 0.2*p: del active[name]A negative step near a known active appliance's power is that appliance turning off, closing its usage interval.
  2. Attribute, alert and report

    Accumulate per-appliance energy and cost, alert on abnormal behaviour (a fridge cycling too often, a heater left on), and report the breakdown — clearly labelling appliance figures as estimates.

Complete Source Code

The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.

cppsmart-energy-meter.ino
/* ═══════════════════════════════════════════════════════════════
   Smart Energy Meter — ESP32 (whole-home + event NILM)

   Measures accurate whole-home real power/energy/PF and disaggregates
   into appliance-level usage by detecting on/off power events and
   matching their signatures. Appliance figures are ESTIMATES.
   ══════════════════════════════════════════════════════════════════ */

#include <WiFi.h>
#include <PubSubClient.h>
#include <PZEM004Tv30.h>

#define STEP_THRESH 150.0f    // W step = an appliance event

PZEM004Tv30 pzem(Serial2, 16, 17);
WiFiClient net; PubSubClient mqtt(net);

struct Appliance { const char* name; float stepW; float pf; float energyWh; };
Appliance lib[] = {
  {"Geyser", 2000, 1.00, 0}, {"Fridge", 150, 0.65, 0},
  {"AC", 1200, 0.90, 0}, {"Kettle", 1500, 1.00, 0} };
const int NA = 4;
float prevP = 0; int activeIdx = -1; uint32_t activeSince = 0;

int matchAppliance(float dP, float pf){
  for (int i=0;i<NA;i++)
    if (fabsf(dP - lib[i].stepW) < 0.15f*lib[i].stepW &&
        fabsf(pf - lib[i].pf) < 0.1f) return i;
  return -1;
}

void setup(){
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID,WIFI_PASS); mqtt.setServer(MQTT_HOST,1883);
}

void loop(){
  if(!mqtt.connected()&&WiFi.status()==WL_CONNECTED) mqtt.connect("meter-1");
  mqtt.loop();

  float p  = pzem.power();          // whole-home REAL power (foundation)
  float e  = pzem.energy();         // whole-home energy (exact)
  float pf = pzem.pf();
  if (isnan(p)) { delay(1000); return; }

  float dP = p - prevP; prevP = p;
  uint32_t now = millis();

  if (dP > STEP_THRESH){                              // an appliance turned on
    int idx = matchAppliance(dP, pf);
    if (idx>=0){ activeIdx=idx; activeSince=now; }
    char m[80]; snprintf(m,sizeof m,"{\"on\":\"%s\",\"step\":%.0f}",
      idx>=0?lib[idx].name:"unknown", dP);
    mqtt.publish("meter/event", m);
  } else if (dP < -STEP_THRESH && activeIdx>=0){       // turned off
    float hrs = (now-activeSince)/3600000.0f;
    lib[activeIdx].energyWh += lib[activeIdx].stepW * hrs;   // attribute (est.)
    activeIdx = -1;
  }

  // whole-home total is exact; appliance breakdown is estimated
  char m[240];
  int n = snprintf(m,sizeof m,"{\"total_W\":%.0f,\"energy_kWh\":%.3f,\"appliances\":{", p, e);
  for(int i=0;i<NA;i++)
    n += snprintf(m+n,sizeof m-n,"\"%s\":%.0f%s",
      lib[i].name, lib[i].energyWh, i<NA-1?",":"");
  snprintf(m+n,sizeof m-n,"}}");
  mqtt.publish("meter/1/breakdown", m);

  delay(1000);
}
float p = pzem.power(); // whole-home REAL power (foundation)The exact whole-home real power and energy are the trustworthy foundation; NILM only allocates this total to appliances.
if (dP > STEP_THRESH){A power step above the threshold is an appliance on-event, the trigger for signature matching.
int matchAppliance(float dP, float pf)Matches the step's magnitude and power factor to the appliance library — the disaggregation, best for large distinct loads.
lib[activeIdx].energyWh += lib[activeIdx].stepW * hrs; // attribute (est.)Energy is attributed to the appliance for the interval it was on, explicitly as an estimate.
// whole-home total is exact; appliance breakdown is estimatedThe design keeps the exact total authoritative and presents the appliance split as informative estimates — honest about NILM's nature.

Configuration & Calibration

Configuration steps

  • Configure whole-home real-power measurement and the event-detection threshold.
  • Build/learn the appliance library (signatures) during a training phase for the specific home.
  • Set tariff for cost attribution and abnormal-behaviour alert rules.
  • Choose on-device (event NILM) vs offloaded (ML) disaggregation.

Calibration procedure

An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.

  1. Whole-home accuracy

    Verify real power/energy against a reference; this foundation must be accurate.

  2. Appliance learning

    Run the learning phase switching known appliances so their signatures are captured; validate detections.

  3. Thresholds

    Tune the event threshold and match tolerances to detect real appliance events without excess false ones.

Dataset, Model & Training

Dataset

NILM can use event-and-signature matching (lightweight, on-device) or trained machine-learning models. For ML NILM, models are trained on labelled aggregate-power data where individual appliance states are known, learning to disaggregate the total.

A per-home learning phase (switching known appliances while recording) captures that home's specific signatures, which vary by make/model.

DatasetSizeLicenceUse here
REDD / UK-DALE / othersMultiple homesResearch (check terms)Train/benchmark NILM models
Your-home learning setDays of labelled eventsYour own dataAdapt signatures to your appliances

Data preprocessing

  • Compute real power (and power factor) from voltage/current; resample to the analysis rate.
  • Detect events (steps) and extract features per event (step magnitude, transient shape, PF change).
  • Label events with the known appliance during the learning phase.
Smart Energy Meter — ML pipelineFrom raw data through training to deployed inference. 1Aggregate powerwhole-home2Event detecton/off steps3Featuresmagnitude/PF/shape4Match/modelappliance5Attributeusage estimate
Smart Energy Meter — ML pipeline

Model architecture

Event NILM: a rule/nearest-signature matcher (tiny, on-device). ML NILM: models such as combinatorial optimisation, factorial HMMs, or neural sequence models (on a Pi/server).

Match compute to method — the ESP32 handles event NILM; heavier ML runs offloaded.

Layer / stageShape or configurationPurpose
Event detectorthresholded ΔPFind appliance on/off events
Feature vectorstep, PF, transientSignature per event
Matcher/modelNN / HMM / NN-seqAssign event to appliance
Attributioninterval integrationPer-appliance energy (estimate)

Hyperparameters

HyperparameterValueWhy
event threshold~150 WTrade sensitivity vs false events
sample rate1 Hz–kHzHigher rate captures transients for better ID
match tolerance~15%Signature variation between instances

Training process

  • Record a learning period labelling each appliance's events to build/adapt its signature.
  • For ML NILM, train on labelled aggregate data and validate on held-out homes/periods.
  • Focus accuracy on large, distinct loads; accept lower accuracy for small/similar ones.

Evaluation, Metrics & Deployment

NILM accuracy is judged per appliance (did we detect it, and estimate its energy) and overall (how much of the total is correctly attributed).

MetricValueWhat it tells you
Large-load accuracyhighGeyser/AC/kettle etc. detected well
Small/similar loadslowerOverlap/ambiguity limits accuracy
Energy attribution errorper applianceEstimate vs true where known
Whole-home totalexactThe foundation is a real measurement

Figures from the reference training run described above — reproduce them before trusting your own changes.

NILM confidence by load type (illustrative)Disaggregation is strong for large distinct loads, weaker for small/similar ones. Large distinct (geyser)92 %Cyclic (fridge)78 %Similar small loads45 %
NILM confidence by load type (illustrative)

Deployment

  • Run event NILM on the ESP32 or offload ML NILM to a Pi/server; keep the exact whole-home total authoritative.
  • Present appliance figures as estimates with confidence; refine with the learning phase.
  • Log data to improve models over time.

Inference example

pythoninfer.py
# Per-event appliance inference (event NILM).
def infer_event(dP, pf, library):
    best, best_d = None, 1e9
    for a in library:
        d = abs(dP - a.step_w)/a.step_w + abs(pf - a.pf)
        if d < best_d and abs(dP - a.step_w) < 0.15*a.step_w:
            best, best_d = a, d
    return best        # None = unknown/overlapping load

Testing Procedure & Expected Output

Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.

TestWhat you should see
Switch a large appliance (geyser)Event detected and attributed; breakdown updates
Run several small appliances togetherSome ambiguity — figures shown as estimates
Compare total to a reference meterWhole-home total accurate
Leave a heater onLeft-on alert
Degrade a fridge (more cycling)Abnormal-behaviour alert
Run the learning phaseAppliance signatures learned; accuracy improves

Bench-test checklist. If a row fails, stop and fix it before moving on.

Expected output

The app shows live total consumption, a per-appliance breakdown and cost (as estimates), history, and alerts for abnormal/left-on appliances.

jsonmeter-breakdown.json
{
  "total_W": 2380,
  "energy_kWh": 512.4,
  "appliances": { "Geyser": 4200, "Fridge": 1100, "AC": 3300, "Kettle": 300 },
  "note": "appliance figures are NILM estimates; total is measured"
}

An accurate whole-home total with an estimated appliance breakdown — enough to see the geyser and AC dominate the bill and target them, while the total stays exact.

A city skyline at night
A dashboard shows which appliances cost the most — from one measurement point. Photograph sourced from Wikimedia Commons — Smart city.jpg. Reused under the licence stated on that page; please check it before republishing.

Troubleshooting: Common Errors & Fixes

Appliance figures wrong

Likely cause. NILM ambiguity / no learning

Fix. Run the learning phase; accept lower accuracy for small/similar loads; present as estimates

Total inaccurate

Likely cause. Measuring current/apparent, not real power

Fix. Measure real power with power factor; verify against a reference

Missed appliance events

Likely cause. Threshold too high or sampling too slow

Fix. Lower the threshold; sample faster for transients

Simultaneous switches confuse it

Likely cause. Overlapping events

Fix. Known NILM limit; use higher-rate features/ML; report uncertainty

Safety concern

Likely cause. DIY mains install

Fix. Use a qualified electrician; isolate electronics from mains

The sketch will not upload — "Failed to connect" or "avrdude: stk500_recv()"

Likely cause. The bootloader is not being reached: wrong port, wrong board, a serial monitor holding the port open, or a USB cable that only carries power.

Fix. Close every serial monitor, confirm Tools → Board and Port, and swap to a known data-capable USB cable. On an ESP32 hold BOOT while the IDE prints "Connecting…", then release. If a peripheral is wired to the UART pins (GPIO 1/3 on ESP32, D0/D1 on Uno) unplug it — it fights the programmer.

The board resets in a loop, or the serial monitor prints "Brownout detector was triggered"

Likely cause. The supply cannot deliver peak current. Wi-Fi transmit bursts, relay coils and servos all pull far more than their average draw.

Fix. Power peripherals from a separate regulated supply with a common ground rather than from the board 5 V pin. Add a 470–1000 µF electrolytic capacitor across the supply near the load, and use a real power adapter rather than a laptop USB port.

Serial monitor shows garbage characters

Likely cause. Baud rate mismatch between Serial.begin() and the monitor, or a floating/shared UART line.

Fix. Set the monitor to 115200 to match the sketch. If it still garbles, the crystal or the USB bridge is being confused by noise — shorten the cable and keep motor wiring away from the USB lead.

An I²C device is not detected

Likely cause. Wrong address, missing pull-ups, swapped SDA/SCL, or a bus too long for the pull-up value.

Fix. Run an I²C scanner sketch first — it should print the device address. Most breakout boards include 4.7 kΩ pull-ups, but if you have chained four of them the parallel resistance is too low; remove the pull-ups from all but one board. Keep the bus under 30 cm at 100 kHz.

Performance Optimisation

  • Keep the whole-home measurement accurate and continuous — it is the foundation.
  • Run event NILM on-device; offload heavier ML to a Pi/server.
  • Sample faster where transient signatures improve identification.
  • Anchor exactness to the total; present appliance splits as estimates.
  • Replace every delay() with a millis() comparison — blocking delays are the single most common cause of dropped readings.
  • Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
  • Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
  • Use uint8_t / uint16_t where the range allows; on an 8-bit AVR a 32-bit add costs four times as much.
  • For battery builds use deep sleep between samples: an ESP32 drops from ~160 mA awake to about 10 µA asleep, which is the difference between days and months of runtime.
  • Profile before optimising — print micros() deltas around each stage and fix the slowest one first.

Safety Precautions

  • Mains measurement is dangerous — use a qualified electrician for the mains-side install and isolate the electronics.
  • NILM appliance figures are estimates, not billing-grade sub-metering — present them honestly.
  • Respect privacy: appliance-usage data reveals occupancy/behaviour; secure and consent it.
  • Keep the whole-home total authoritative for anything that must be exact.
  • Mains voltage kills. Anything on the load side of the relay is at 230 V. Do not work on a powered circuit, and never leave exposed mains wiring on a bench where someone could touch it.
  • Keep at least 6 mm of creepage between the mains and low-voltage sides of any board you make, and never route mains tracks under the microcontroller.
  • Have a qualified electrician do the final installation into a consumer unit or wall fitting. In most jurisdictions this is a legal requirement, not a suggestion.
  • Fit an RCD/RCBO upstream and fuse the load appropriately for its rating.
  • Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
  • Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
  • Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.

Maintenance

  • Re-run/extend the learning phase as appliances change.
  • Verify whole-home accuracy periodically.
  • Tune thresholds/models as usage patterns shift.
  • Review alerts and refine appliance models.
  • Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
  • Rotate the microSD card annually and keep an image of the working system. Cards used as loggers wear out silently.
  • Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
  • Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.

Future Improvements & Upgrades

A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.

  • Add higher-rate transient signatures and ML NILM for better disaggregation.
  • Add solar/export awareness for prosumer homes.
  • Add appliance-level anomaly detection for predictive maintenance.
  • Integrate demand-response and time-of-use optimisation.
  • Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
  • Add connectivity — an ESP32 and an MQTT publish turn a local gadget into something you can graph, alert on and analyse over months.
  • Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
  • Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
  • Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
  • Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.

Frequently Asked Questions

How can one meter tell what each appliance uses?

By disaggregation (NILM): appliances have characteristic signatures in the aggregate power signal, so detecting on/off events and matching their step size and shape attributes the total to individual appliances — from a single measurement point.

Is the appliance breakdown accurate?

It is an informed estimate, not a measurement. It works well for large, distinct loads (geyser, AC, kettle) and less well for small or similar appliances whose events overlap. The whole-home total, though, is a real, exact measurement.

Does it need setup for my home?

Yes — a learning phase where you switch known appliances so it captures their specific signatures, since these vary by make and model.

Why measure real power, not just current?

Because appliances are often inductive and current alone overstates consumption and hides power factor. Real power (with PF) is the accurate foundation NILM builds on.

What can I actually do with it?

See which appliances cost the most and cut them, catch a failing appliance drawing more or something left on, and verify savings — most of the value of expensive per-circuit metering from one clamp.

References & Learning Resources

These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.

  1. Non-intrusive load monitoring (NILM)Reference
  2. Hart's NILM (original work)Reference
  3. Power factor and real powerReference
  4. Real-time energy feedback and savingsReference
  5. NILM datasets (REDD/UK-DALE)Reference