How to create energy dashboards in Grafana with ESP32
Learn how to monitor your home electrical consumption using an ESP32, non-invasive SCT-013 sensors, the MQTT protocol, and beautiful Grafana charts.
Summary
- SCT-013 sensors measure alternating current safely without cutting any cables
- ESP32 microcontrollers process analog signals and convert them into useful data
- The MQTT protocol transmits energy readings lightly over home Wi-Fi networks
- Centralized time-series platforms store historical measurements for deep analysis
- Grafana transforms raw numbers into intuitive visual dashboards and alerts
What is home energy monitoring with open hardware?
Monitoring your home electricity consumption used to be an industrial privilege or required installing expensive, closed proprietary meters. Today, with the rise of the internet of things, we can build custom monitoring systems spending very little while understanding exactly where every watt goes. The secret lies in combining affordable development boards with sensors that measure electron flow without any shock risk or wire stripping.
When we combine accessible hardware with robust visualization software, we pave the way for real improvements in our routine and monthly utility bills. Before assembling any circuit on your workbench, ensure your power setup is safe and isolated, following best practices similar to those we discuss on how to shield bench power supplies from surges and noise to prevent false readings caused by electrical grid interference.
How does the non-invasive SCT-013 current sensor work?
The SCT-013 sensor is a split-core current transformer that clamps around just a single power conductor of your electrical installation. In practice, it acts like a miniature reversible electrical generator: the magnetic field created by the alternating current passing through the wire induces a small proportional electrical current in the internal winding of the sensor.
Since this 100-ampere sensor generates a very low and safe output current, we connect it to a burden resistor on the circuit board to convert that current into a voltage measurable by a microcontroller. This analog voltage oscillates along with the power grid wave, requiring our device code to take multiple samples per second to capture the peak value or calculate the true root mean square.
Processing the electrical signal on the ESP32 microcontroller
The ESP32 is a compact chip featuring built-in Wi-Fi and Bluetooth connectivity, alongside twelve-bit analog-to-digital converters capable of translating received voltage into software-friendly numbers. However, reading alternating current requires a small mathematical trick, because the sinusoidal wave crosses zero dozens of times per second and assumes both positive and negative values.
To work around this, we use a simple voltage divider circuit with two resistors and a capacitor to lift the signal reference point, allowing the microcontroller to read the entire wave without damaging its analog input. The code continuously reads for several power grid cycles, squares the values, takes the average, and applies calibration to finally output current in amperes and estimated power in watts.
Transmitting consumption data via the MQTT protocol
Once the microcontroller calculates the consumed power, we need to send this information to a central server without relying on messy network cables around the house. That is where the MQTT protocol comes in, an extremely lightweight messaging technology designed specifically for internet of things devices and unstable networks.
The ESP32 acts as a publisher that sends short packets containing the measured value to a specific channel, called a topic, on a central broker in the local network. Other systems can subscribe to this same channel to listen to real-time updates, ensuring instant communication, low bandwidth consumption, and total independence from external cloud providers.
Designing the perfect control panel in Grafana
With energy data flowing across the local network and being stored in a time-series database like InfluxDB, the final step is creating the visual interface that provides clarity on daily consumption. Grafana steps in right here, connecting to the database to transform cold numbers into line charts, circular gauges, and detailed tables.
We can configure panels showing instant power in watts, monthly totals, and even visual alerts if any appliance starts pulling more energy than usual. This integrated view helps identify hidden villains on the electricity bill and validates the efficiency of any conservation measure implemented in daily life.
Final considerations
Building your own energy monitoring system using low-cost hardware and open visualization tools is a fascinating project bridging practical electronics and data engineering. Besides providing noticeable financial savings through conscious appliance use, the assembly process teaches valuable concepts about signal sampling, MQTT communication, and time-series persistence.
With the structure running stably on your local network, you gain total autonomy to expand the project with more sensors, create consumption-based automations, or integrate these data points with other smart home platforms. Technology stops being a commercial black box and becomes a transparent tool under your complete control.