A Complete Raspberry Pi Power Monitoring System

As the world has become more environmentally conscious, we’ve seen an uptick in projects that monitor or control home energy use. At a minimum one of these setups involves a microcontroller and some kind of clamp-on current sensor, but if you’re looking for resources to take things a bit farther, this Raspberry Pi energy monitoring system created by [David00] would be a great place to start.

This project includes provides software and hardware to be used in conjunction with the Raspberry Pi to keep tabs on not just home energy consumption, but also production if your home has a solar array or other method of generating its own power. Data is pulled every 0.5 seconds from a MCP3008 ADC connected to up to five six current sensors to provide real-time utilization statistics, and visualized with Grafana so you can see all of the information at a glance.

While [David00] has already done the community a great service by releasing the hardware and software under an open source license, he’s also produced some absolutely phenomenal documentation for the project that’s really a valuable resource for anyone who wants to roll their own monitoring system. He’s even offering hardware kits for anyone who’s more interested in experimenting with the software side of things than building the PCB.

Home energy monitoring projects are certainly nothing new, but the incredible advances we’ve seen in the type of hardware and software available for DIY projects over the last decade has really pushed the state-of-the-art forward. With so many fantastic resources available now, the only thing standing between you and your own home energy monitoring dashboard is desire and a long weekend.

36 thoughts on “A Complete Raspberry Pi Power Monitoring System

    1. Dude, it’s a pretty cool project, it’s really fun and educational, plus it brought a ton more knowledge into the hacker’s world about how those devices work. Not everything is about a dry mathematical gain you know.

    2. Very, very little compared to most household appliances. So little that it probably cannot measure it’s own power usage against the backdrop of household appliances. You’re worried about a few watts when the device is being used to help prevent the overuse of kilowatts.

    3. Rpi4 running this will use something between 650 milliwatts (idle) to 900 milliwatts (unlikely but it draws around this when taxed). So 0.64 watts idle – 0.9 watts, maxed out will be about 0.0216 kWh per day, or 7.884 kWh per year. By comparison, an A++ EU energy rating on a fridge is awarded for devices using 280 kWh per year or less.

    4. In my case I think your point is well taken. I did a power generation and consumption project with a Raspberry Pi on my 45W Harbor Freight solar panel system. In that case the 4w or so consumed by the 5v power supply and the Pi was significant! Worried about the marine battery voltage over night after an overcast day, I ended up adding an Arduino running a crude clock which put the Pi to sleep at night and woke it up in the morning. Was a rube system, but it was fun and educational to fight with it.

      1. good to know. Was thinking about running my Pi directly from a battery that is being charged by a solar panel because of the conversion losses in the power supply. Anyhow, my project only needs to run during the day anyway.

    5. How do you reduce energy consumption in a meaningful way if you can’t quantify what you are using in a timely manner? Pinheads don’t care about excessive consumption because more always means better in their books.

      Nice project, good effort, thank you for sharing!

      1. I expect Medix means if it can cope with other voltages then 230 (208V or 400V) or if it can distinguish between the different phases. Google “three phase power line” if you are confused ;)

        1. Exactly, 5 sensors is fine, but I wanted to know if the software is written to account for phase differences, etc to measure 3-phase power (not as straightforward as single phase).

          Sure, I could modify it myself, but why re-invent the wheel if it’s already been done!

          1. Just sticking an ADC to a PI and taking 0.5sec snapshots means that OP is *assuming* that all measurement comes from pure resistive loads. The results won’t be the same as what the utilitity company measures.

            You would either use a energy monitoring chip (e.g. see link below) or have at least have a microcontroller *real time* sampling the instantaneous power to calculate the real power.


          2. Hi, David00 (project creator) here…

            The software does not currently support 3-phase power monitoring. It can be expanded to support 3-phase, but right now, it is only intended for single/split-phase systems.

            Also, there is an error in the article – I will try to contact the author. The project supports up to 6 total current transformer inputs, not 5. :)

          3. I can’t reply to atomd or tekkieneet directly – not sure why, but I wanted to correct their assumption on the capabilities of my project.

            atomd said in a comment below:
            “there’s no support for input voltage, so It can’t really distinguish reactive power nor calculate real power.”

            The project does have a requirement for AC input source voltage. In the documentation, I have listed the requirement for a 9V AC power supply. This is used to sample the AC grid voltage for phase and level.

            tekkieneet said in a comment below:
            Just sticking an ADC to a PI and taking 0.5sec snapshots means that OP is *assuming* that all measurement comes from pure resistive loads. The results won’t be the same as what the utilitity company measures.

            You would either use a energy monitoring chip (e.g. see link below) or have at least have a microcontroller *real time* sampling the instantaneous power to calculate the real power.”

            Your comments are correct, but that’s not how my project works. :)
            There is no assumption that all loads are purely resistive – this project is capable of measuring and calculating real power from ALL types of loads. The code takes tens of thousands of samples per second from all inputs, corrects for phase errors incurred by the very short time delay between samples, then calculates instantaneous power in order to get a truly accurate real power calculation.

            You don’t NEED an energy monitoring chip to accurately measure power – sure, the dedicated monitoring chips would be slightly more accurate, but they’re also limited in the number of inputs they accept.

          4. Last time I did 3-phase power measurement, I had 8 pairs of sample and hold on the inputs of a data acquisition system (that I designed). The voltage channels and current channels were sampled and exported to a spreadsheet where the power are calculated. I had my result compared to a lab grade box that does proper 3-phase power measurements.

            Calibration is not as difficult at least in my case as the voltage and current sensors can handle DC, so taking enough data point, run that on linear regression on the spreadsheet for the slope. offset, residuals etc. Based on how well the data is fitted, one can use a simple linear fit or piecewise linear fit over the range to handle non-linearity.

            These day, I would have used the cheapo STM32F103 ($2 Blue Pill) as it has 2 independent 12-bit 1Msps ADC. The ADC can be triggered off hardware timer without software intervention and results stored via DMA. It won’t have software jitters like the RPi. Sample the voltage and current on the pair of ADC and you won’t have to mess around with phase shifts.

  1. “… it brought a ton more knowledge into the hacker’s world about how those devices work.”

    The information is poor quality and does not address the fundamentals of data acquisition for power monitoring.

    “Not everything is about a dry mathematical gain you know.”

    Oh geez, just no. Please turn in your geek/nerd card. Numbers are everything. Whether you are a plumber, bus driver, or disc jockey, numbers matter. Math is not dry. It explains everything. Where the math is missing, all is suspect.

    About the ‘numbers’. A 10 bit ADC, where the INL, DNL, Vos and other stuff are at least 8 LSB over a 50 degree temperature range; and where there is no controlled Vref, where there is no input Z for a SAR converter, where the “calibration” is only a simple scaling factor, we can only assume that the “dry math” is suspect. His six digits of data is fantasy and has no meaning.

    1. That’s a bit harsh, but a point well taken that citing six digits of precision is beyond the capabilities and limited calibration and reference source available to the hardware. I have taught electronics for quite a few years, and at the outset of my courses students never cease to write down figures with fewer than whatever number of digits show up on their calculators. That’s even when the measurements being taken have uncertainty of perhaps +/- 5% of the reading. It takes more effort for students to account for the sources of uncertainty, but I work on getting students to cite their final answers with appropriate precision and a +/- percent total accuracy. I’m old enough that I started out on a slide rule (thankfully very briefly) and then moved to using an HP calculator that defaulted to reading out just a few digits to the right of the decimal point. HP obviously had designers that appreciated displaying numbers with precision that makes engineering sense.

      I still have to chuckle when I see an answer like -20.000625 dBm when students are taking readings by looking at the screen of an oscilloscope for a lab exercise.

      Having said all that, this project should still be plenty useful for helping a home owner identify and track power use.

    2. Hi There,

      David00 (project creator) here. I just wanted to correct you on one point regarding calibration. The calibration is not just a simple scaling factor as you’ve suggested. I’ve written a complex phase correction algorithm to adjust for phase errors brought about by the time between samples and the inherent phase error in each CT. Please see the theory section I’ve described here which describes part of the calibration process for this project.


      Lastly, this is a hobbyist grade power monitor – it is not intended to compete with commercial revenue grade monitoring systems striving for absolute accuracy.

      1. FYI: You are talking about phase correction for the individual ADC channel. This is more or less a fixed phase shift errors that are common to the same hardware.

        Brian and Bill talking about the calibrations needed to take care of ADC accuracy – linearity, offsets etc (+ error introduced by thew current sensors) The latter is needed for calculating the readings accurately for *individual* systems for component tolerances/variations etc.

        1. Oh, yes, thank you for clarifying!

          I have not gone into correcting for ADC accuracy itself. I feel that going down that level of detail would require a highly accurate calibration source which most homeowners don’t have access to. I think that, given the intended scope and audience of this project, calibrating using a simple scaling factor AFTER the inherent phase errors have been corrected for, against a common Kill-A-Watt or consumer grade AC clamp meter, was sufficient.

      2. @David00,

        Truly, this is a great effort and with your understanding at this point, I cant help but think you would be great at helping me with monitoring gas sensors like the MQ-4. Im a complete noob and I need to spend more time doing projects like this than going at it alone. Thanks for this.

  2. Such a useful tool! I’ve been wondering what various things around the house are drawing while I’m away or in my daily activities.

    The kitchen range is an on-demand device as it is not on all day, but when I turn on my desktop computer, what does it draw?

    If I turn on the subwoofer/speakers, what’s the draw now? When I turn on the Tripp-Lite 12V/40A power supply, what is the draw?

    How does power draw change when I have the Elecraft K3 (ham radio transciever) receiving? Transmitting?

    These have largely been unknowns, wadded up in the power bill at the end of the month, where I could expect my hobby activities contribute here and there to the power consumption in the house. Now I could put this device on a cord and witness impact I have on contributions to my overall power consumption by monitoring the optional devices around the house.

    Useful! (So no wonder I see unthinking, visionless critiques of it.)

  3. Hi everyone – this is David00 (project creator) here!

    I wanted to stop by and leave a comment because I’m seeing some incorrect assumptions being made and posted by people in this comment section. Also Tom, thank you for featuring my project in your post – there is one typo, though, and that is the project supports 6 total current transformer inputs (not 5).

    1. The project is able to calculate real power from ALL types of loads. The project takes tens of thousands of samples per second from up to 6 current transformers and one required AC voltage input source, corrects for phase errors, calculates instantaneous power, then calculates real power, apparent power, and power factor. This project inspects the harmonics of each individual current transformer. It does not just read the ADC and print the value.

    2. The project does not currently support 3-phase monitoring. It is theoretically capable of it, with some major assumptions being made about the two other phases that can’t be sampled, but if you just want to get an idea of 3-phase power consumption with no real requirements for accuracy, the project in its current state can be modified to support it.

    3. I really do appreciate the input from seasoned electrical engineers with a career full of experience. However, I would like to kindly remind these folks that this project is NOT striving to compete against the accuracy of solutions from the likes of Siemens, Fluke, etc. This project is for home monitoring from a DIY/hobbyists perspective… and the cost of the hardware involved reflects that!!

    1. I’m looking for a similar project that uses an esp32, which already includes wifi and several (8?) adc inputs and costs much less (2€), is much smaller and uses much less energy. Maybe not as precise but I dont need high precision, i just want a low cost, many-input monitor to install in my fusebox to find out which of my 20 circuits in the house are using the energy that i see on the main meter (several 100w overnight).

  4. These current sensors are pure sh*t. We used them and found them to be way off their specs too often. And due to their size they aren’t very good at measuring small loads. Aaand I wanted to point out that there is an open source project doing the exact same thing with a raspberry and these current sensors: emonPi (openenergymonitor). It’s much more mature and comes with proper software.

    1. If you had a look at the project documentation, you’d see that this project is derived from OpenEnergyMonitor. Also, if you were familiar with their project at all, you’d have seen that they thoroughly tested the YHDC SCT-013-000 and found it to be sufficient for this purpose.

      Project documentation: https://github.com/David00/rpi-power-monitor/blob/master/README.md

      YHDC SCT-013 sensor test report: https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/yhdc-sct-013-000-ct-sensor-report

  5. David00 — this looks great.

    I have a similar but lower-tech setup in my own home: in my case, two CTs in the panel feeding into a ESP8266, using the same ADC as you use. I have them sample about 0.5 s (can’t remember exactly how much) of the current waveform every 20 sec and then calculate Irms from that.

    I don’t need metering-grade accuracy — but in my testing, found that the current draw my setup measured was within a few percent of a Kill-a-Watt type meter. That is good enough for my purposes. I haven’t bothered getting an AC-AC transformer to calculate power.

    I had a professional electrician put the CTs in my panel for me.

    In my case, the ESP8266 sends current draw info via MQTT to a broker running in-house, which then sends it on to InfluxDB running on an Amazon Lightsail VPS. Grafana then visualizes it.

    My system also has temperature / humidity sensors in a few rooms in the house, as well as a temperature sensor in the main furnace outflow duct. The combination of being able to see current draw and the performance of my HVAC system has been very valuable. I don’t have an algorithm to distinguish the different loads from one another, but can usually tell by looking at the graphs.

    Some things that this setup has done for me: (a) Revealed a problem with the fuser on my MFD laser printer. (b) Revealed the cause of a failure with the main board on my furnace. (c) Revealed the cause of the failure of my AC compressor. (d) Revealed the cause of a slow warm-up cycle on my oven.

    If I wanted metering-grade, I’d buy a professional system. For now, what I have is great, and its cost has been paid back at least 10-fold by catching problems before they get worse.

  6. so many negative comments!

    the details of this “horrible!” project are out there so you can fix it. didn’t your parents ever tell you “share a nice pull request or don’t share anything at all”?

    “cranky, combative” is just not a good look for you… yes, you.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.