Monitoring Voltage with ESPHome, D1 Mini ADC, and Home Assistant

59,697
0
Published 2021-11-14
Monitor power supplies or other low voltage DC supplies with Home Assistant and an ESP8266 D1 Mini ADC circuit. Use an external voltage sensor module voltage divider. Use Grafana to watch values over time.

ADC Config: esphome.io/components/sensor/adc.html
ESP8266: amzn.to/3D7kQFa
Voltage Divider: amzn.to/30dhUZ4

Join this channel to get access to perks:
youtube.com/channel/UCXEa_Gzl2zjhb7K6xflyrWQ/join

Discord: discord.gg/XmFqucu

If you would like to support me:
Buy me a beverage: ko-fi.com/mostlychris
Become a patron: www.patreon.com/mostlychris



Products I reference in my videos (Contains affiliate links)
www.mostlychris.com/my-smart-home-gear/
www.xsplit.com/?ref=chriswest&discount=mostlychri&pp=stripe_affiliate

DISCLAIMERS: Some of the links above take you to affiliate sites that may or may not pay a small commission to me. As an Amazon Associate I earn from qualifying purchases. It doesn't increase the cost to you, but it does help support me in making these videos.

00:00 Intro
00:42 Program ESP8266
06:03 Volt Divider/ESP8266 Overview
08:35 Completed Wiring
10:20 Voltage Output and Multiplier
12:11 Add Sensor Integration to HA
13:00 Determine Multiplier Offset
16:24 Build Sensor Template
18:28 Display Sensor in Grafana
20:45 Overvolt Alert Automation
22:09 Final Thoughts and Wrap

Want to send me something? Send it here!
Mostlychris
24165 IH-10 West
STE 217 #164
San Antonio, TX 78257

All Comments (21)
  • @primusnz
    You can eliminate the need for a template sensor entirely by adding a lambda section to the filters and doing the adjustment calculation in there. filters: - multiply: 3.3 - lambda: return (x-0.08)*5;
  • @mikesmods317
    Long time subscriber Chris! I'm finally getting around to using this setup to monitor my vehicle batteries. Ordered the voltage dividers today. Thanks for the awesome videos man!!
  • @Mobytts69
    I like how you're straight to the point, no cheesy jokes, no cringe "I'm the ultimate dad" vibes, just very technical and to the point yet slow and clear enough to follow and not get lost. Thanks for your quality content!
  • @webluke
    I think I learned more about how to build things with ESPHome and Home Assistant in this video than in many others. Not to mention it was well thought out and easy to follow. Now I'm off to set up a voltage monitor for a solar attic fan.
  • @Corgitronics
    Instead of performing the additional calculations, I would just change the filter from 3.3 to 15.8 then the ESP32 would report the actual PSU voltage directly back to HA.
  • @binky_bun
    It's cool to see how you did this but in terms of protecting your radio you're probably better off with a crowbar circuit across the power supply that shunts out the PSU and pops the fuses. I built one a few years back using an SCR turned on by a zener diode. I wouldn't want to be relying on all the moving parts of micro controllers, WiFi and services like home assistant talking to a smart plug of some sort. There's going to be some lag there and by the time it's shut off the mains the radio might already be seeing a much higher voltage than your set point. A crowbar will be pretty much instant. Not as fancy in terms of graphing and alerting but that kind of thing should always come second in scenarios like this. It's good to know about it but if your radio is already fried it's too late
  • @MaxGoddur
    It is nice to see someone creating an example using HA, ESPhome and, finally the automation. There is a real need for basic training in the areas discussed. We have enough pages or websites that explain functionality at the knowledgable programmer level.
  • Thank you for this video, Very helpful to get started. I am using this voltage monitor for my 24V off-grid battery bank. My ESP32 ADC needs to work between about 100mV and 900mV. Expecting voltages of up to 30V, I added a 1k resistor to the voltage divider output (just soldered it between A0 and GND because that was easier than messing with the smd resistors on the "voltage sensor module". Next time, I won't use the voltage sensor module, but rather build a matching voltage divider immediately.
  • Very good tutorial. I added a few extra lines in the template for the esp config in case anyone is interested. It also removes the need for an extra sensor in HA config. Just adjust the lambda value to suit. sensor: - platform: adc pin: A0 name: "Your choice" unit_of_measurement: "Volts" icon: "mdi:car-battery" accuracy_decimals: 1 update_interval: 60s filters: - multiply: 3.3 - lambda: return (x - 0.06)*5;
  • @Doerakker
    if you need or want to become confused you are doing a great job ! ;-)
  • @jmr
    Interesting video. One time no one could hear me on my radio. I bumped the knob on my power supply. I don't remember the voltage but it was very low. 🤣 I'm switched to 100% solar for all communication gear now though. I get voltage reports from my charge controller via modbus to MQTT with Tasmota now. Works great
  • @TheNCGardener
    Very good walk thru from start to finish! I have been experimenting with an ESP32 reading, LP sensor voltage, 18650 battery voltage and solar panel output and the esp wakes up, takes the readings, sends it via mqtt , and goes back to sleep. I am finding that the readings are not stable and I have been chasing the calibration factor. I have a little troubleshooting to do to track down the instability. I believe I am going to feed it a known voltage and see how stable it reads it. It may be due to dipping supply voltage when it wakes up. G6EJD does several very detailed videos on measuring voltages and using voltage dividers and the calibration math to use in your code. Also, in the ESP technical specs, it notes that each chip will have a slightly different calibration requirement. Depending on your selection of resistance used in the dividers, the ESP output impedance can also change the results as it may load down the voltage since it is roughly 1.3meg that will be in parallel with R2. Some other tricks that can be utilized in your code is averaging. I use this with a flow sensor since it seems to be very erratic with my water pressure. I can also average it even more once I get the data in Node Red.
  • Great video May i know which video editor you used for recording screen together with your face cam?
  • 21:04 in the automation you should not use state but instead use numerical state. Now if your power suply goes from 13.9 to 14.1 your automation will not fire. With numerical state you can set a above or below value
  • @MisterkeTube
    The voltage divider in the Wemos D1 is a pair of resistors, one below the actual ADC block and one towards the input which you now attach to the center of another pair of resistors, so one towards ground and one towards the voltage you want to measure, but ... the two resistors inside the Wemos are now in parallel with the external one to ground, so the total resistance is no longer what you thought your voltage divider would provide. Since the value inside the Wemos is known, you can better simply add a single resistor from the ADC pin of the Wemos to the voltage you want to measure, basically increasing the factor the new voltage divider created this way will use.
  • If it's a linear power supply and the regulator fails, the output immediately jumps to 30 V - not gradually. There should be a crowbar protection circuit inside the PS that shorts the output on over voltage so that it blows the fuse before the connected load is damaged. Still nice to know voltage, especially for PS without a meter and for a PS mounted remotely where you wouldn't see the meter anyway! I love the video and the work.! Thanks
  • If the power supply goes up to 30 volts, I don't know if it will blow up whatever you have it supplying power to, but I think it could blow up the ESP32, even after going through the voltage divider. 30 V / 5 = 6 V > 3.3 V. You may want to change your setup so that the Tasmota switch turns the power supply off automatically as soon as it gets to 3.3 V * 5 = 16.5 V.
  • @zyghom
    sorry brother but at 6:19: this is NOT a sensor but voltage divider - the sensor is in your ESP. Something is crazy with 25V max vs 3.3V max - it is probably dividing 25V into 5V for Arduino or so. With regards to accuracy of ESP ADC: it is very non-linear. It is the best (probably) to provide many ranges if you are about to measure huge range of values. And embed them into ESPHome (it is also described there on ESPHome web) rather than in HA. My sensors send the data to HA every 3s from power supply - 1 minute for potential overvoltage can be too long to act accordingly. Also, for power supply adding ampere meters is also good - from these 2 you can easily calculate Watts. Btw: with this voltage divider, if your power supply goes to 30V, you will get on the A0 .. the killer voltage ;-) (30V/5/3.3=1.8V on pin that accepts 1V)
  • @milesobrien2694
    About your USB cables not working:. As crazy as it sounds some cables have power and data, some have data only and some have power only. The last two are generally provided with some CE product like a portable fan that doesn't need data, just power to recharge the battery or just data to an already powered device. It seems like a dumb way to cut costs but if you're making thousands of devices every penny adds up.
  • Chris I finally got this going and got the template to report correctly. Question 1 is how to get the corrected voltage to report to the HA dashboard. Question 2 is how to set a voltage trigger to alert me if the voltage goes to some preset voltage (ie 11 volts) Thanks Steve