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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in a previous video i showed you how i measure the heat sink and the power supply temperatures of both my radio and my power supply well today i want to take that a step further and i want to measure the voltage of the power supply to make sure i don't have any issues with voltage creeping up i did have a volt power supply failure and i want to make sure that i'm able to see that before it occurs and could damage my radio equipment so i'll be using an esp8266 and a little voltage divider board and then at the end i'll show you how i plot this in grafana so let's get started [Music] okay so we're going to start by taking our esp8266 here and we're going to plug it into our pc just any usb port now one thing i've noticed is that i've got some older usb cables and i don't know why but some of these usb cables they just they do not work at all for uh programming these so you got to make sure you have a decent cable and then it's nice and solid and fits in there well because otherwise it's not going to work all right so we're going to go to our esp home dashboard and i don't have it on the side here so we'll go supervisor esp home i'm gonna go to the web ui i'm gonna add a new uh a new sensor here or a new esp device i'm going to give it a name volt sensor 2 and then i'll add the wi-fi ssid and password and now it's going to create a configuration and install it on my device so i'm going to click connect and it's going to give you an option for a couple of these serial ports i know that my usb device the esp devices on com6 will connect and then it's going to go through the process of installing that configuration on the device and then we can talk to it over wi-fi at that point okay the configuration is now created we can close that out now the next thing we need to be able to do is we need to be able to monitor the voltage on the analog to digital converter pin which is on the device and i'll show that to you here when we get ready to build it but there is an esp home dot io page that has an adc or analog to digital sensor ads but it uses adc platform and that's what we're going to use in order to be able to sense the voltage changes or voltage level uh from the device and that we're measuring so all we have to do then is pull in this platform and the pin and the update interval and give it a name so i'm going to copy this here i'm going to go back into vault sensor 2 and i'm going to add that information i got from the esp home page and to do that we'll just pick a spot and i'll just paste it in now we have to make sure that things are correct here we do want the platform as adc we do want our pin as a0 and then we do want to change the name to something that makes sense to us so i'll just call this volts sensor 2 and my update interval will be 60 seconds we'll leave that as default we'll save it any time i make a change like that i want to go back in here and i want to validate it so i'll click on validate and make sure there's no issues here and it looks like that's correct and once that is done then we'll go ahead and install it this time we can install it wirelessly rather than doing it over the usb port so i'll do wirelessly here and now it's going to go through and compile in the adc sensor and install that on the device now while it's doing that let me talk about something else here when you read this it says the um the component prints the voltage as seen by the chip pin so on an esp8266 which is what we're using this is always zero to one zero volts to one volt um see some of the development boards like the wemos d1 mini have an in external voltage divider circuit and that scales the 3.3 volts down to the one point bolt now since we're using the wemos d1 mini we're going to add one more item here which i should have already done we're going to add a filter a multiplier and we're going to multiply that by 3.3 so we bring it back up to a voltage that is usable for us and so in order to do that we'll wait for it to build out install then we'll go in here and we'll add this filter and add a multiplier to it because we're going to be using a voltage divider here to bring it down the voltage down to a value that won't exceed the 3.3 volts that you can put into that pin and then we're also going to multiply it back up because the voltage there is a voltage divider already on the wemos board but it's not enough to keep it from being destroyed if we don't have an external voltage divider okay so it's all done it's already already built out we're going to go ahead and stop this logging and go back in here and we're going to edit and add in this filter so i'll just copy this and paste it in there and then we'll make it fit in the yaml code as it's needed so that goes under sensor here and we'll paste it in here and multiply the value we're getting from our external voltage divider here this little guy right here and we will multiply it back up to 3.3 and then we'll build a template sensor later on in home assistant that multiplies it again by a certain value that gives us the actual voltage that's coming in on or from the measured device and i'll as always we're going to validate this and we are going to install the new code we'll do it wirelessly this time it should be quicker because it doesn't have to compile anything this time it just has to update the configuration and add that filter value and it's complete and that's all we have to do to configure the esp device right now next up we need to build this little contraption we have here we're going to use this sensor right here and we're going to use the esp device we're going to solder those together and we're going to build out our little voltage sensor completely and then we'll do some other stuff after that is done so let's get over to the soldering bench and let's start building that out all right we're over here on the soldering bench now these are the two devices we're going to be hooking together we have a voltage sensor here and just let me point out that this voltage sensor has a maximum value or input value of 25 volts so you can't exceed that voltage on this device and on this we have inputs here we have a ground input and we have a vcc input these are the inputs that we're going to be hooking up our uh our power supply to and this is what we want to measure is what's coming into these uh right here and then we also have on this side we have the s the plus and the minus pin and we're going to take our output from the sensor pin right here and we're going to also connect our ground here so we'll have outputs from these two right here going into the esp8266 now this is a d1 mini and this has an internal voltage divider on it like i mentioned before and we're going to be putting in uh the voltage here as um the output of this s pin here will come into the zero or the a0 here and then we'll take the ground and we'll put it in right here on this and that's going to be our sensor value that goes into the esp8266 and if you remember in the video or in the configuration of the esp8266 we chose the adc input as pin a0 this is the only pin that will do adc inputs on this device on the 8266. you can do this on other pins on an esp32 but not on this device now we're going to power it normally by 5 volt usb we're just going to use our standard 5 volt usb input here if you're doing something like a battery monitor on it you're going to want to put in a 5 volt input here to be able to power this but we're not going to do that today it gets a little more involved you got to make sure that you have your voltages set right and everything but for today output of the s pin goes into a0 here and output of the ground or negative side of this voltage divider goes into our ground over on this pin right here so let's get our soldering iron all set up and we'll get this wired together okay so i had a really nice soldering segment all set up and done here and i did all this work on camera but it turns out that my obs software decided not to record any of it so i'm just going to show you what i've done here and then we'll go into more uh stuff on home assistant so what i've done is i've actually soldered a wire from the a0 pin here and i've also soldered a wire to the g pin here on the esp8266 both of these are connected into the pins on the voltage divider that we have here now this voltage divider takes the input from the power supply so we have the white wire which brings in our vcc so there's our vcc input on this side and then our ground input on this side and we bring them both together uh into this voltage divider circuit which then outputs uh five times less than what is being put into it and then this will take this the value that's being brought into this pin a0 and because it has a voltage divider circuit on it it will drop it down even farther and bring it into a zero to one volt range so right now coming out of the power supply you can see here that we're running about 13.92 volts so that's the input coming into this right here this voltage divider and then coming into the circuit here on the a0 pin is five times less than that value and then being output into a home assistant or output of this device here is actually a zero to one volt value because of the voltage divider on the circuit all right so let's look over at home assistant what we've got going on here you can see here what i just talked about we have a voltage coming in at .88 volts that's the voltage divider at the pin on the chip that's being measured by the adc circuit and that's because again we have a voltage so we have two voltage dividers in play here we have a voltage divider that is uh this right here we're bringing this 13 volts down to something manageable that won't blow out the front of the chip so you have a max of 3.3 volts i believe coming into the esp8266 and you need to bring it down to that value and then on this chip on this board there's another voltage divider that divides even further and so when it gets to the chip the pin on the chip it's actually showing zero to one volts and because we added the multiplier now you can see here that we have a reporting voltage of 2.91973 that's the voltage that's being multiplied this point 88 times 3.3 to give us the voltage to overcome or to compensate for the voltage divider circuit on the esp8266 now obviously if we're looking at a voltage here of 13.92 volts we definitely don't want to be reporting 2.919 in our sensor because that's not a true value so what we need to do now is we need to go through and we need to add in some logic into our sensor on home assistant to bring the voltage back up to the 13.9 volts which is what is actually being read at the power supply so let's go ahead and do some experiment with that i'm going to show you in developer tools how we can kind of play around with the numbers to get an output of what we want and then we will build the template for uh we'll build the template to use that value that we're going to come up with here before we can actually use this volt sensor and play around in the developer tools we actually need to add it to home assistant so it probably has discovered it by now so what you'll see is you'll see a notification down here so click notifications you'll see new devices discovered check it out it should show you this new device so we're going to configure that submit it and you can give it an area if you want to and now it shows up in your esp home devices as voltage center 2 with one device and one entity so here is our devices volt sensor 2 and we should have entities on here as well and this is our volt sensor actual sensor volt sensor 2 so that's the value we're going to be playing with in our templating so volt sensor 2. all right so let's go over to configuration or developer tools templates and i've already been playing with this a little bit on a different model or a different esp8266 that i was using earlier okay so right now we have a value of 14.05 volts and if you look here you have a value of 13.92 on the power supply so we want to adjust this value until we get the right value and this is where you start playing with this number right here so we're going to make this a little bit more uh let's make it 14 and i'm sure there's a way to do this with your with math um without playing with this like i just did um but i didn't so here we go this gets us pretty close now the granularity of how you want to measure this is going to determine how crazy you get with this formula i'm okay with having a value of 13.9 volts when my power supply is actually reading 13.92 now i can't adjust the power supply voltage on the power supply so i'm not able to experiment to see if turning this up a little bit higher rounds it up a little bit but we're doing a rounding of four here and i'm getting a 13.9 volt voltage so if you think about it now let's go through the steps we we come in from the power supply and we have 13.9 volts coming in from the power supply and then we bring it into this voltage divider which drops it down by five times to get it into a value that isn't going to blow this chip up so you've got a range of zero to 3.3 i believe for this esp32 chip so you bring it down with this voltage divider you can't take these these leads and put them directly on the chip you'll blow the chip up so you've got to have a voltage divider you can either buy these voltage dividers or you can build your own voltage divider using resistors i just went ahead and got these because they're they're cheap and they're easy to work with since they already have connectors and everything built into them and then of course this chip has a voltage divider on it as well or this board which drops it down to the zero one volt which is what the chip itself needs so we bring it all the way through this loop right here take the value put it into home assistant and when we bring it into home assistant we do a little math here to take that volt sensor too which is what esp8266 is sending to us and home assistant and multiplying it by a negative 0.14 value and then another five times because we're bringing it back up to the level that voltage divider the initial voltage divider is dropping it so remember the voltage divider here is dropping it by five times what the output of this power supply is so all we're doing is we are bringing it back up through the level of the power supply that is or the the first voltage divider there and then this is an adjustment factor because not every single device is going to be exactly accurate so you need to do a little bit of work here to bring the the adjustment to what your power supply is actually reading and i recommend using a volt meter to make sure you're reading the power supply correctly uh because then uh with that you're able to to make sure that this value that you're reading here is actually correct now what do we do with this here this is just a an experiment so what we want to do now is we want to make sure that we take this and we template it and we put it into home assistant as an actual value so let's do that now i'm going to bring up visual studio code and i've already done this with a different sensor so i'm going to bring up my sensor files all right so this is my sensor file i'm going to go to the bottom of the sensor file and you can see what i've done with this here this is exactly the same thing with a few extra parts so what we have here is we have a template and then we have our sensors and this is the radio ps volts calculation and this is the one that's already running i've been running it for a couple or a week or so now just to get an idea how it works unit of measurement is going to be volt and then this is the value template that we just created in our template editor so we can see that we take this value we know this works because we tested it in the template editor we know it's the correct value now the this is a case in point this is point uh 0.11 that's the difference between one esp8266 and another i had to set the other one as a calculation of 0.11 versus this one as a calculation of 0.14 just because of the difference in the tolerances of the hardware and pieces of equipment or the hardware that's on the esp8266 and then i added this final thing here this attribute templates allows this to update every minute and the reason i do that is i want to be able to plot this in grafana if the voltage of this sensor never changes or changes very infrequently which typically it should on a power supply that's decent you're never going to get a measurement here unless it changes in grafana because the way home assistant works is it only records changes it doesn't record uh every minute so i've made it actually record every minute so that i get a value let me show you what this looks like in grafana we go over to home assistant here now and i pull up my grafana and i look at my environment you'll if you watch my previous video on this you'll recognize that i did system temperature radio system temperatures of both the heat sink and the power supply so i'm watching my power supply here my the temperature of my heatsink and my power supply using a couple of davis sensors and an esp8266 i've also started watching the voltage on my power supply here because i had a failure of a power supply and i want to make sure that my voltage stays within tolerance here so let's let's edit this and i'll show you how i set this up all i did was i go down i went down here and i created a i chose of default measurements voltage entity id is the radio ps volts calculation now remember in in this template the value of the sensor name is what we're looking for we're not looking for the sensor that's coming directly from the esp8266 because that's at 2.9 something volts we have to use the sensor that is taking that value and doing the calculations here and we named it radio ps volts calc and if you look over here this is radio ps volts calc so we just fill in all the values here and then we start getting a plot along here of our voltages and you can see here that it updates every minute and that's because i set that attributes value to update every minute otherwise it would never update so attribute template minute last updated now call a minute whatever so now we have an updated voltage of um or an updated graph of our voltage values for our power supply and we're able to measure that over time now you can do this as well with something like i said something like a battery or something that is going to discharge over time you're going to want to see that here the power supply i just want to have a good idea what's going on with the power supply so if something were to happen we're starting to climb voltage-wise i could shut it down i've got a sona or tazmo tie switch on the power supply that i can remotely shut off if something were to go wrong with it since it's in the attic i want to be extra careful with that kind of stuff okay so let me show you one final thing here this is the automations that i use for this particular um setup so here's the automation all i do here is i am a notification if the power supply becomes overvolt so it's real simple i look at that uh state of that sensor radio ps volts if it goes to 14 volts uh immediately it will alert me there's no delay on it if it goes to 14 volts then i send myself a pushover notification telling me that i have a power supply overvolt it's important because once again i've said this a few times in the video i had a power supply of this exact make and model go up into about 30 volts now i don't know if that would have blown up the circuit uh when it when it did that but it probably crept up there and whenever it gets to a certain point here it'll alert me i'll check the graph if it's high i'll shut it down and that saves the equipment attached to the power supply so it doesn't blow it up i can also take this same automation if it gets to 14 volts i can go on the automation and other under actions i can actually shut that switch off so i don't even have to be around to do it it'll automatically shut it down protect my equipment from over voltage and then let me know that something bad happened with it so that is how i measure my voltage and my um i monitor that with my my esp8266 and that voltage divider circuit let me know if you have any questions uh i'm not an electro i'm not an electronic engineer i do understand a lot of concepts so i will answer those as best i can put those down in the comments below if you want any of these things i have some links uh in my description of where i got this stuff from and then also hit me up on discord for any other questions you might have and thanks for watching if you're not a channel member i would appreciate if you would join the channel help support what i do here uh subscribe like all the good stuff and we'll see on the next video [Music] you
Info
Channel: mostlychris
Views: 17,031
Rating: undefined out of 5
Keywords: Smart Home, Home Assistant, D1 Mini, esphome, esphome home assistant, adc circuit explanation, adc circuit design, esphome power monitoring, home automation, diy power monitoring, Grafana
Id: coS9moqir8M
Channel Id: undefined
Length: 23min 7sec (1387 seconds)
Published: Sun Nov 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.