DIY ESP32 AC Power Meter (with Home Assistant/Automation Integration)

478,977
0
Published 2020-11-22
Have fun and win via JLCPCB E-exhibition: jlcpcb.com/E-exhibition
$2 for 4-Layer PCBs: jlcpcb.com/
Previous video:    • Building a Tube Amp! Does it produce ...  
Home Assistant video:    • DIY Home Automation Intruder Alarm Sy...  
Power video:    • Electronic Basics #38: True, Reactive...  
Facebook: www.facebook.com/greatscottlab
Twitter: twitter.com/GreatScottLab
Support me for more videos: www.patreon.com/GreatScott?ty=h
More project information (pictures, schematics,....) on Patreon: www.patreon.com/posts/esp32-power-43701117

Parts list: (affiliate links)
ESP32: s.click.aliexpress.com/e/_AfKZrJ
Current Transformer: s.click.aliexpress.com/e/_A661E9
Voltage Transformer: s.click.aliexpress.com/e/_Adyvfr
Resistor Kit: s.click.aliexpress.com/e/_dTPpXjt
Capacitor Kit: s.click.aliexpress.com/e/_d7dOwRz

Websites which were shown in the video:
learn.openenergymonitor.org/electricity-monitoring…
github.com/Savjee/EmonLib-esp32
esphome.io/index.html
esphome.io/components/sensor/custom.html

In this project I will show you how to build an ESP32 AC power meter that can be used with your home assistant setup. That means I will firstly explain how to actually measure and calculate real and apparent power along with the power factor and then I will show you how to use the ESP32 in combination with some complementary components in order to create the power meter. Let's get started!

Thanks to JLCPCB for sponsoring this video.
Visit jlcpcb.com/ to get professional PCBs for low prices.

Music:
2011 Lookalike by Bartlebeats

All Comments (21)
  • @Asu01
    This is exactly what I need, thanks! Now I can monitor how much power I'm drawing from my neighbour's power grid and adjust my load so it won't make any suspicion.
  • @KevinDC5
    I actually just received my very first ESP8266 NodeMCU in the mail yesterday and have been pondering a project all night. Amazing that you post this today!🤘🏼🤘🏼
  • @AmplifierWorld
    What a great energy you delivered while saying " stay creative and see u next time"
  • The circuit shown at 6:42 is a nice idea and definitely works in a pinch, but it's a serious source of error in your measurements and can easily DESTROY your expensive ESP32. Firstly it relies on the precision and drift of the offset voltage resistor divider, which is not insignificant as if you are using 5% resistors, your center voltage and thus powerline measurement could also be off by 5% (or around 16v at line level). Also at startup, before the 10uF capacitor charges to 1.65v, the input of the ADC swings negative, which can seriously damage some devices which don't have stringent input protection. Finally, if there is some fault in the line which causes the transformer to output a higher than expected voltage, this will exceed the power rail of the circuit and discharge straight into the ESP32. You want a circuit called a "Clamper" or "DC Restorer" which will fix your voltage above ground potential (protecting the ESP32 ADC) and allow you to take advantage of the full scale of the ADC input. This also saves on two precision resistors for the voltage divider, and a rail-to-rail buffer amplifier will tend to isolate the ESP32 from any voltages over the supply rails. With an output buffer you can also use a smaller capacitor value, with higher voltage rating and non-tantalum type for safety such as a ceramic disk capacitor. You can also safely add an external ADC if you want to increase your measurement accuracy substantially. (Just remember to sample the max voltage to calculate the zero crossing point for the AC signal, as there is no center offset voltage now) There is no fundamental difference between your expensive power meter and a circuit you can build at home, you just need to find all your sources of error and minimize them! :) Here is example circuit for reference https://tinyurl.com/y2aoed7z
  • @didnotkn0
    Great video, I love incorporating tech into homes like this. I would also like to say thank you for making videos, you have been such a huge inspiration to me and a large reason why I want to get into electrical engineering, much love from Phoenix, AZ.
  • @ZeroMass
    My Sunday morning is complete... Coffee and GREAT SCOTT!!
  • Your channel is always a great place to watch some cool videos utilizing microcontrollers like the ESP32. It’s such a versatile controller to have around! I’ve used them for all sorts of things, I had one hosting an access point with a simple html interface to control a project I had made.
  • @user-yq3lv4js9c
    I had something like that in mind for a long time, great job!!! Adding a temperature sensor on a solar heater and a power relay we could remotely power on its internal resistor when we need it (without have it on all the time). We can also watch the power consumption for security reasons and be able to turn on the outside lights remotely, and so on. Home (and not only) automations with microcontrollers is so simple this days and we can do so many things that really worth spending some time learning how to program them which is pretty simple and a great way to learn children how and why programming is fun and why maths physics and chemistry is necessary most of the time on whatever we do :-)
  • @jeffpkamp
    Some points from my experience building The same thing for my own home: if you can't find a 12-volt AC former, you can step down the voltage just using a standard voltage divider with 10 or 20 times the resistance on the upstream resistor (depending on if you're in the Europe or US). If you want it isolated, you can use a one-to-one speaker transformer, or they have potted transformers the one-to-one ratio specifically for this task. Also the ESP32 ADC has abysmal accuracy without some sort of filtering in software. I actually used an Arduino nano to measure the current on the two phases coming into my house (US) and pass that off to an ESP8266 to send to my server. The values I got out of this setup were within 0.1% of what the electric company said I used.
  • @adityag.5372
    Hey! This video doesn't start with the word "recently" 😅😅
  • @rzdakira
    "Handy and shocking." A pun across two languages. I love it
  • Great Scott, love watching your videos! It improved my electronics knowledge by a ton!
  • @DrGreenGiant
    I've recently done this myself, well similar. I wrote my own code in the IDF and used the SCT-013 current clamp so I could measure the whole house current. No touching of live wires needed since it's a clamp rather than pass through doughnut. Works very well but I am assuming voltage since I don't have an isolating transformer yet to measure it. That's the next upgrade!
  • @HemonDey
    Thanks for this video, I enjoy watching your channel and its great content. I've created an energy metering system in my house using existing energy meters with pulsed outputs, basically gives a pulse for each 1whr consumed - this significantly reduces the complexity of the project as it means only having to count pulses to get near instantaneous energy consumption values. Also if you also monitor milliseconds between pulses, you can work out near instantaneous power consumption as well. These meters are very common and easy to obtain, and they also by their nature have to be reasonably accurate - an added bonus is that they also typically come in a small form factor (1x din width), and pulses are isolated from mains. I populate the energy/power values directly into a time series database (Influx) and graph with results using Grafana.
  • @Felix-ve9hs
    I just installed Home Assistend on my Proxmox Server and was searching for a "smart" Power Meter I could use with it, perfect timing :D
  • @rob_cek
    Im always so fascinated by your projects and even more how economical you make them even though you live in germany where gross can shoot up very high, keep up the spirit scott! (Im from slovakia, so you can understand the meaning of the comment)
  • We just did this for our EE senior design project back in the spring! We won first place!
  • @thetechboy8529
    I am waiting for this video for a long time. The most informative video on this topic on YouTube Thanks sir
  • I have literally no idea what I'm watching But I still love his videos :)