This is especially useful right now. I have been staying home so much my car battery was too low the first time I tried to drive somewhere. I will probably make one of these so I can be alerted when I need to top the battery up with a charge so I don’t damage the battery any further! Thank you!
Glad it helped! If you feel fancy, you can automate that as well by plugging in the car battery charger ( something like this amzn.to/2MozsHc) to a smart wall plug and have an automation turn it on at specific low voltage and off when the battery is fully charged.
Thanks for this. I just built this after my battery went dead last weekend. I’m using ESPHome instead of Tasmota, and I got it up and running quickly and was able to calibrate it without any issues.
I have done this build using the D1 mini with power shield and noticed that even in deep sleep it consumes over 7mA of power draining my motorcycle battery in less than 55 days. If you do not use deep sleep the battery will die within 10 days. The problem appears to be the power shield that consumes nearly 7mA. This, unfortunately, does not make this project suitable for vehicles that are not used for long periods of time.
I also done one with a d1 mini and the power shield but deep sleep does'nt work when I connect the power shield. Do you know how I can solve it? I clarify that it works by directly plug the d1 mini but not when I plug in the power shield
Fantastic!!! I was wondering to find something like that sometime ago and now I found. Going to install one in my car, one in my motorcycle and in each of my Nobreaks. Great job.
I made a server version in 2019, can be viewed from any browser device. Put a zener ~3.0-3.3v across the ADC pin to clamp spikes and a 0.1uf cap to filter. I had a spike hit mine and it changed the input impedance to 12K, damaged. Also add a fuse and a TVS diode on the input power feed as well.
Not sure if MrDIY is still monitoring (or anyone else for that matter) but if you are, fantastic project. I got it 99% working. Only thing I can't overcome is how to get Home Assistant to message me when my battery voltage is below 12 volts. Any screen shots of the automation setup would be greatly appreciated. Thanks. And again, well done!
It seems like in your setup, the ESP8266 is always powered by the car battery. If so, how do you prevent it from draining the car battery? Also, how did your drop the voltage to power the Wemos as 12V is too much to power it.
Very interesting project, I'm excited to give it a try. Wondering, is there any protection needed in front between this and the battery to deal with voltage spikes on start or if hooking up a booster in the event the battery dies?
I don’t wanna be that guy, but you forgot half your voltage divider :/ And btw, a high resistance is good for a voltage divider, but 1.4 Mega ohm is way too much. You should decrease to 390kohm and 26kohm for example. Nice work on the software part tho, and it’s a really cool idea!
Thank you Thomas! No, don't worry. And by the way, I didn't forget the other half. The Wemos D1 Mini has a voltage divider built-in. What I did is simply extending "the one half" to increase the range. Also, I didn't have a choice in the value of the resistor as "the other half" is already set in the d1 mini. You can technically change it but that involves de/soldering tiny SMD components - if you want to go that route.
Nice project. I guess your car is parked inside your Wifi coverage which does not apply to most of the people. It would be interesting to see the deep sleep telemetry period settings. After all the project is for protecting the battery not for draining it ;)
It's running stock Tasmota, so will probably only have the modem sleep power saving enabled. Deep sleep won't be happening as D0 wasn't connect to RST, allowing for wakeup from deep sleep.
That's super cool. Can you log all the voltages over time in a graph? There are these bluetooth battery monitors that I have been looking into but as a software developer I would prefer something that I have control over. Excellent idea.
thanks for the video, hoping you could help clarify something. You showed connecting two resistors to make the 1.44Mohm (R1 leg) but I didn't see the other leg of the divider (R2 100kohm). It looks like you connected the 2 resistors making R1 from hte +ve terminal to A0. Does the hat play any role in this?
This is a great idea and video. However, I wish you could have a diagram that shows more detail on the connections. It is not very clear where you are connecting the resistors. Thanks for the video though
Actually, remembering to add the pullup resistor to the 18B20's data pin makes the sensor appear in the Tasmota setup and Home Assistance interface was pretty simple after that. Thanks again for the clear and detailed instructions.
@@MrDIYca Just for added data. Tested and found on a hot day the setup reads one to two tenths high, and it hasn't been cold enough to test it any further, but for cold weather climates, it could be very important. Great video camera work, editing, good clean commentary audio levels, good scripting, keep up the good work, by the way.
I'm a little confused, at 1:26 the video shows 2 resistors soldered together, the right hand one appears to be (Brown/Black/Black/Green) 100 x 10^5 =10 MOhm, and the left hand one looks like (Green/Blue/Black/Violet maybe? It looks Pink but there's no Pink colour code) which would be 560 x 10^7 = 5.6GOhms!!?? If what looks to be Green in the video is actually Yellow then the 1MOhm would be right but the other one would be 460 or 470 something if what looks Blue is actually Violet? either way, its not 220 anything (Red/Red/Black)!
Hello, in the video, I recommended using a 1.22 MOhm resistor (1MΩ + 220KΩ) but I didn't have a 220KΩ at the time so I used a 440KΩ instead and this is what you are seeing in the video - good eye!
****Be aware***. Changes to Home Assistant. Platform key is no longer used. Also take note on the syntax in the value template. Mine was "Range1" and not Range. I assume this is because I am using an ESP32 that has 4 ADC pins instead of just 1 like the ESP8266. Working as of 1/7/2024 , this is the new declaration for the configuration.yaml . mqtt: sensor: name: motobattery unique_id: motobattery state_topic: "tele/motobattery/SENSOR" unit_of_measurement: "v" value_template: "{{ (value_json.ANALOG.Range1 | float / 100 | round(2) )}}" qos: 2
Love this project. Would you be interested making something similar but with something like a ct-clamp where it measures amps/watts that are actually being used by something running off a 12v battery?
Great project and video. Tool me awhile to get it going as I hadn't used Home Assistant before, is it possible you could show the code that sends out the notifications please?
@@MrDIYca many thanks for replying I now have it fully working, the only mod I would like is a sleep / deep sleep mode. The car I need it for is a Toyota C-HR 1.8 Hybrid which has a 12V battery problem when not used regularly.
Will the ESP8266 drain the battery or is there no problem with that? My dashcam has a device reading the battery level and shutdown the parking observation, if battery is too low. - So you could send the ESP to deep sleep, if it occurs.
Rough calculation: ESP8266 uses 170mA at 3.3V (0.6W). A typical car battery has 40A at 12v (480Wh). That means the ESP8266 by itself can drain the battery from full to 50% in 400h (16 days). That should give you a frame of reference. If you add deep sleep, it should last years. You might want to read this post - community.home-assistant.io/t/monitor-your-car-battery-in-home-assistant/201508
I have everything together adjusted the range where it matches and added the code to config yaml... I get the raw values for voltage... like 1270 instead of 12.70v??? what am I doing wrong. value_template: "{{ (value_json.ANALOG.Range | float / 100 | round(2) )}}" When I try to add the card to HA it says entity is non-numeric. I can analog range and it shows up1,270 but cant get battery volts to show
The device sends the voltage in the 1270 format. But in HA, it takes that and /100 giving 12.7. You probably have a misconfiguration in HA. I would check the HA's forum for help, it is pretty active. I remember seeing this non-numeric issue with another thing I did in HA but it had to do with old values not being numeric, so HA assumes the whole sensor is non-numeric.
Hi MrDIY. Thank you for this video. It works great. I notice that the D1 power shield can be power by 24v also. Will it be possible to measure battery voltage on 24v? If so please could you assist me to determine the resistors needed to measure 24v
Thanks for sharing... I have followed your example and built this project to monitor the starter battery on my back-up generator.. Everything went well up to the point of Home Assistant. I got an mqqt brochure error. Did you already have a brochure installed in HA? This is my first time doing something like this..
Hi, i follow your suggestion to build a similar one. I have built one using a D1 mini with 1220k ohm and 100k ohm to measure the car battery. The data is sent to HA API at home. It works perfectly with the deep sleep. However, I am facing a problem when I drive my car to another place not within the intranet, the esphome node would continuously search the WIFI and not going to deepsleep. Do you have such kind of problem? Thanks
thanks for the video. i'm a bit confused about your voltage divider. Isn't the analog input range 0.0 - 3.2 Volts? Why scale the voltage down to 0 - 1.0 Volts?
Hi Frank. The ESP8266 ADC pin input voltage range is 0 to 1V. The Wemos D1 mini, which uses the ESP8266 chip, comes with an internal voltage divider that increases this range to 0 - 3.3V on pin A0. Hope this helps!
@@rogerfar Hi Roger, what do you mean by ref voltage? The d1 mini ADC can't exceed 1 volt. The resistors bring the battery voltage range from 0 - 12 down to 0 -1. I have shown in the video the calculator I used to come up with these vaules - check it out.
@@MrDIYca This confused me too but after looking at the schematic I see why. You're both right. The ESP8266 wants 1V. The Wemos D1 Mini wants to use a 3.3V range so they put a voltage divider on board already: So it goes ("D1 max 3.3V input" - 220K - "ADC max 1V input" - 100K - GND). In the video you add a 1.22M resistor in series so it now goes ("External max 16V input" - 1.22M - 220K - "ADC max 1V input" - 100K - GND). The 3.3V input point is still there in between the new 1.22M and the on-Wemos 220K but it's not used any more so isn't mentioned. It's more obvious if you draw it...
How are you powering the ESP8266 D1 mini? Is it only on when the car is engaged/turned on? Or is the D1 mini *always* on? Wouldn't powering the D1 mini drain your battery?
It is powered on all the time but only sends a msg every 30 mins. In theory, yes, anything connected to a battery will eventually drain it but it will take months. Hopefully you will get a notification before that happens :)
First of all, very nice videos and IOT ides, good luck with the channel, hope that channel will continue with smart home DIY ideas based on ESP boards. Just one question, calculation for voltage divider was for 16V battery and the measured battery voltage is actually 12V. Is it possible to do this only with NodeMcu ESP8266 board? Should be able to take 12V if I am not mistaken? Would be nice to show some examples with ESPHome in the future.
Thank you Marko. I check the schematic for NodeMCU and it looks like it simular to the D1 mini. They both use a 220k/100k voltage divider for the ADC so that means they are both limited to 3.3v. You will still need to extend the range to accept 12v.
@@MrDIYca Please check this link: components101.com/development-boards/nodemcu-esp8266-pinout-features-and-datasheet Under NodeMCU ESP8266 Specifications & Features You will find Input Voltage: 7-12V.
Hi Marko, the device can accept 7-12v but the Analog Pin can only accept 0-3.3v. Scroll down until you see: Analog Pin | A0 | Used to measure analog voltage in the range of 0-3.3V. This is why I extended the voltage divider.
Hi MrDIY. Thank you for getting back to me wrt the 24v. I have a 12v setup as per your video It work great but I notice that when the power goes out it drains my battery very quickly its a 7ah lithium battery. Brad new. I dont know how its possible as the D1 with power shield should really not draw alot of power. I am a noob at this stuff so hoping you might know why this is happening. All I have different from yours is that I have a 1.20 mega Ohm resistor as I was not able to find the 1 megaOhm and a220k Ohm as per your video. It still works to measure the battery level. Does this maybe affect it? Thanks in advance for your assistance
This looks fantastic and i can think of numerous uses but i just cant get it to work. I have set the device using Tasmota exactly as described and setup home assistant on a Pi3 and followed all the instructions but the device does not show up on home assistant. I must be missing something :( I tried installing an MQTT server on home assistant but still could not get it work?
I highly recommend visiting the Home Assistant Forum and Dicord help channel. There are a lot of amazing people over there that will give you a hand with the MQTT server setup: home-assistant.io/help
@@MrDIYca I think i am now getting there thanks :) I had lots to learn about home assistant but now have a few sensors working so now back to the voltage monitor. I do have another question. You use the voltage divider to lower the sense voltage but it appears you are just using two resistors in series and connecting one end to input voltage and the other to the A0. But usually a voltage divider is used from the center tap of the two resistors?
Great. Yes, that is because I am not creating a voltage divider. D1 mini already has a voltage divider built-in using 100kΩ and 220kΩ resistors. I am simply increasing the 220kΩ end by adding an extra 1200kΩ ( 1MΩ + 200kΩ) for a total of 1440kΩ. Effectively creating a voltage divider with 100kΩ and 1440kΩ resistors.
@@MrDIYca The problem i am having now is when i copy your code into the configeration.yaml file it does not like the unique_id:car-elantra-battery line? So will not allow me to save it into the file?
@@MrDIYca Hello, I think I understood it wrong from the other video that I was watching. On their's they did not include the power supply for the D1 Mini, assuming they used the USB of the computer to power it up, when I disconnected it from the computer the D1 is off ( lol ) ... So in powering our D1, we need a buck converter right to supply 5V to the D1. then the 1440 MegaOhm is for the A0. In your case, the Battery Shield was able to handle the battery voltage? My usage: I want to build a smart battery monitor for my Koi Airpump built-in UPS that I will also convert to full solar setup.
Is it possible to use this for monitoring a 36 volts e-bike battery that when it is fully charged have 42 volt and empty 33 volt? I want to monitoring the storage charge so I can stop it when the battery have 38 volts. All help is appreciated.
You can play with the resistors to increase the range but your problem will be the power shield. It is rated for 24v max. I am sure you can find another converter that will take in 48v and give you the 5v needed.
So I out everything together and added the code to config yaml... I get the raw values for voltage... like 1250 instead of 12.50v??? what am I doing wrong. value_template: "{{ (value_json.ANALOG.Range | float / 100 | round(2) )}}"
that is true. It has been monitoring my car for 2 weeks now and I was able to start it just fine the other day. But it would be useful to get accurate energy usage for a span of one day or so.
@@arnsle Not in deep sleep they won't! Deep sleep drops power consumption below 1mA into the micro-ampere range. If the ESP8266 is allow to idle-sleep the WiFi modem, power consumption should drop from 70ma @ 5v to around 25-30mA IIRC. It will be less than that on the 12v side (somewhere in the order of 15mA), since current is relative to voltage. Even so, if the car was parked up for a couple of months you would want to charge the battery up anyway, as the onboard electronics as well as this would drop the battery state of charge more than enough to cause some permanent damage to the battery if not charged.
Yes, Tasmota don't go to the deep sleep. Does not matter how often make voltage readings. I tried to measure D1 + shield and 18-40mA. So I went with mysensors and Nrf24l01+ it goes to deep sleep but because of the lm2596 does not go less 4mA. Maybe need to try different stepdown regulator.
Hi Michael, no you can not use the car battery directly witht he D1 mini. I used the Wemos D1 mini power shield amzn.to/2ZmI0Vq you can see it in the videio at 00:24
@@MrDIYca Laughing... I didn't see any reply to this until now. I did see the power shield board in video, but didn't know what it was until I researched it today (really brief on that in video). Anyhow gave tasmota a try and I am now able to read voltage, temp, humidity, and DewPoint thanks to your video and others. Integration to MQTT was a pain, but now that I've been using it (setoption19 1 in tasmota was key for me) my life is getting better. Don't understand why alexa doesn't see anything (it did with ESPHome), but I was really looking for local control anyway. Just got a Shelly 1PM that I will wire up to my air conditioner in power shed and then I will start doing some automations. This home assistant/tasmota/MQTT/Python/etc is not for the faint of heart. Towards the end of your video you are trying to calibrate your voltage output using AdcParam... do you know what each individual entry represents? 6, 0, 1023, 0, number
@@michaelbatchelder great to hear you got most of it figured out. It does indeed have a steep learning curve at the beginning. For the AdcParam command, it goes like this: mode (6 for linear range remapping) , input range low value=0, input range high value=1023, output range low value=0,output range high value=number you are searching for. It is basically mapping the analog values it reads (0,1023) to a range that makes sense to us, aka, the battery voltage (0 to 1600) or ( 0v to 16.00V once we divide it by 100 in the MQTT sensor). A side note: in the video I actually used a bigger resistor. I used a 1.44Mohm instead of 1.22Mohm. That is why my adcParam were bigger. You will probably be in the 1600 range as compared to my 1770 in the video.
@@MrDIYca I have all the elements/values showing up on LoveLace interface on Home assistant, voltage of 28.8v reading 2878. Can I format that "2878" to an aesthetic reading that shows 28.78v? Sorry to pick your brain so much, but I appreciate all the help you have given so far. My hassIO install is new, with some Tuya switches (really slow reaction time on them, may flash them and install tasmota), weather, network sent/received (don't understand the naming structure, list 3 sets, but I only have one router), and a roku. I am sure there are multiple ways to get things accomplished. I also see the NodeMCU that I have will except 12v for power, will have to test to see, but I have a dc to dc transformer in the shed that converts 24v to 12v. Going to add to more batteries to the solar shed and setup everything the next set of days off.
@@michaelbatchelder personnaly I prefer tasmota over tuya cloud, I made a tutorial on how to flash them using a proxmox vm here ruclips.net/video/DDYK7cE9rEA/видео.html). I believe you can try templating to format the value www.home-assistant.io/docs/configuration/templating and use the value to do something like value_template: "{{ (value | float / 100 | round(2) )}}"
The battery shield is rated for 24V max. The batteries can easily exceed that, especially while charging. I don't recommend you use it with a 24v system.
having this constantly powered with no regard to deep sleeping is not a good idea. you should move this project to esphome so that you can check for ssid and deepsleep for 30 for example
Did you really just directly connect the ADC pin to the power through 1.2M ohms? That is not how voltage dividers work at all. Consider yourself lucky you didn't destroy you ESP8266. The voltage divider is between the power and ground and the wire to the ADC is from the middle of the two resistors. Your values are far too high to do this without a buffer. You should get decent results with between 5k-15k total resistance between power and ground as there is a calibration step. Last step you need to do is put a zener across the voltage divider. Car power systems can be dirty so this is added to make sure that the voltage across your divider never exceeds 15v.
No, I did not connect the battery directly to the ADC pin. I extended the BUILT-IN voltage divider in the Wemos D1 mini board. I created a video explaining the difference between ESP8266 modules and boards (.. and the extra features they have , such as voltage dividers). Check it out here - ruclips.net/video/dGrJi-ebZgI/видео.html
This is especially useful right now. I have been staying home so much my car battery was too low the first time I tried to drive somewhere. I will probably make one of these so I can be alerted when I need to top the battery up with a charge so I don’t damage the battery any further! Thank you!
Glad it helped! If you feel fancy, you can automate that as well by plugging in the car battery charger ( something like this amzn.to/2MozsHc) to a smart wall plug and have an automation turn it on at specific low voltage and off when the battery is fully charged.
Thanks for this. I just built this after my battery went dead last weekend. I’m using ESPHome instead of Tasmota, and I got it up and running quickly and was able to calibrate it without any issues.
would you mind providing the yaml? I did this in tasmota 4 years ago but I'm looking to switch over, but i'm still learning esphome
I'd add a small fuse to the takeoff from the battery. Cool project.
I have done this build using the D1 mini with power shield and noticed that even in deep sleep it consumes over 7mA of power draining my motorcycle battery in less than 55 days. If you do not use deep sleep the battery will die within 10 days. The problem appears to be the power shield that consumes nearly 7mA. This, unfortunately, does not make this project suitable for vehicles that are not used for long periods of time.
I also done one with a d1 mini and the power shield but deep sleep does'nt work when I connect the power shield. Do you know how I can solve it? I clarify that it works by directly plug the d1 mini but not when I plug in the power shield
Thanks for idea! I build same sensor, but use my own code with esp8266 deep sleep mode, works fine.
Civilman would you like to share your code please? davelucas3ATgmailDOTcom
Fantastic!!! I was wondering to find something like that sometime ago and now I found. Going to install one in my car, one in my motorcycle and in each of my Nobreaks. Great job.
Glad it was helpful!
I made a server version in 2019, can be viewed from any browser device. Put a zener ~3.0-3.3v across the ADC pin to clamp spikes and a 0.1uf cap to filter. I had a spike hit mine and it changed the input impedance to 12K, damaged. Also add a fuse and a TVS diode on the input power feed as well.
Not sure if MrDIY is still monitoring (or anyone else for that matter) but if you are, fantastic project. I got it 99% working. Only thing I can't overcome is how to get Home Assistant to message me when my battery voltage is below 12 volts. Any screen shots of the automation setup would be greatly appreciated. Thanks. And again, well done!
You might want to check this post - community.home-assistant.io/t/monitor-your-car-battery-in-home-assistant/201508
It seems like in your setup, the ESP8266 is always powered by the car battery. If so, how do you prevent it from draining the car battery? Also, how did your drop the voltage to power the Wemos as 12V is too much to power it.
using the power shield, the input can be up to 24v! the shield then downscale to 5v for the D1 chip
Very interesting project, I'm excited to give it a try. Wondering, is there any protection needed in front between this and the battery to deal with voltage spikes on start or if hooking up a booster in the event the battery dies?
I don’t wanna be that guy, but you forgot half your voltage divider :/
And btw, a high resistance is good for a voltage divider, but 1.4 Mega ohm is way too much. You should decrease to 390kohm and 26kohm for example.
Nice work on the software part tho, and it’s a really cool idea!
Thank you Thomas! No, don't worry. And by the way, I didn't forget the other half. The Wemos D1 Mini has a voltage divider built-in. What I did is simply extending "the one half" to increase the range. Also, I didn't have a choice in the value of the resistor as "the other half" is already set in the d1 mini. You can technically change it but that involves de/soldering tiny SMD components - if you want to go that route.
Great video. Thank you.
Nice project. I guess your car is parked inside your Wifi coverage which does not apply to most of the people. It would be interesting to see the deep sleep telemetry period settings. After all the project is for protecting the battery not for draining it ;)
It's running stock Tasmota, so will probably only have the modem sleep power saving enabled. Deep sleep won't be happening as D0 wasn't connect to RST, allowing for wakeup from deep sleep.
Thanks
But it will drain your car battery in a week or so. It should employ some deep sleep and send reading every 24 hrs
How could you do this and also measure Current through the battery? I'm looking to measure battery usage.
That's super cool. Can you log all the voltages over time in a graph? There are these bluetooth battery monitors that I have been looking into but as a software developer I would prefer something that I have control over. Excellent idea.
Very useful, thank you.
Glad it was helpful!
thanks for the video, hoping you could help clarify something. You showed connecting two resistors to make the 1.44Mohm (R1 leg) but I didn't see the other leg of the divider (R2 100kohm). It looks like you connected the 2 resistors making R1 from hte +ve terminal to A0. Does the hat play any role in this?
Yes, correct. The wemos d1 mini already has a voltage divider. I simply extended it.
@@MrDIYca thank you clarifying that, appreciate you taking the time to explain
This is a great idea and video. However, I wish you could have a diagram that shows more detail on the connections. It is not very clear where you are connecting the resistors. Thanks for the video though
Great idea! I added how I wired the resistor at www.instructables.com/id/DIY-Monitor-Your-Car-Battery-Code-Setup
@@MrDIYca Thank you so much! That's great!
@@MrDIYca Your wiring diagram shows R1(1.44 megohm), where is R2 (100 kilohm)?
@@mgillis1948 The R2 is built-in the Wemos d1 mini. I added a 1.22M to make it 1.44M. Hope that clarifies things for you!
@@MrDIYca Thank you for the clarification.
What should these calculations be for a 24V battery?
Good job, all works great. Wonder if you can include an 18B20 read to make more sense of voltage reading...? (I tried, too challenging at my level...)
Actually, remembering to add the pullup resistor to the 18B20's data pin makes the sensor appear in the Tasmota setup and Home Assistance interface was pretty simple after that. Thanks again for the clear and detailed instructions.
Awesome, so what did you end up using it for? mapping the voltage to %?
@@MrDIYca Just for added data. Tested and found on a hot day the setup reads one to two tenths high, and it hasn't been cold enough to test it any further, but for cold weather climates, it could be very important.
Great video camera work, editing, good clean commentary audio levels, good scripting, keep up the good work, by the way.
I'm a little confused, at 1:26 the video shows 2 resistors soldered together, the right hand one appears to be (Brown/Black/Black/Green) 100 x 10^5 =10 MOhm, and the left hand one looks like (Green/Blue/Black/Violet maybe? It looks Pink but there's no Pink colour code) which would be 560 x 10^7 = 5.6GOhms!!?? If what looks to be Green in the video is actually Yellow then the 1MOhm would be right but the other one would be 460 or 470 something if what looks Blue is actually Violet? either way, its not 220 anything (Red/Red/Black)!
Hello, in the video, I recommended using a 1.22 MOhm resistor (1MΩ + 220KΩ) but I didn't have a 220KΩ at the time so I used a 440KΩ instead and this is what you are seeing in the video - good eye!
****Be aware***. Changes to Home Assistant. Platform key is no longer used. Also take note on the syntax in the value template. Mine was "Range1" and not Range. I assume this is because I am using an ESP32 that has 4 ADC pins instead of just 1 like the ESP8266.
Working as of 1/7/2024 , this is the new declaration for the configuration.yaml .
mqtt:
sensor:
name: motobattery
unique_id: motobattery
state_topic: "tele/motobattery/SENSOR"
unit_of_measurement: "v"
value_template: "{{ (value_json.ANALOG.Range1 | float / 100 | round(2) )}}"
qos: 2
Love this project. Would you be interested making something similar but with something like a ct-clamp where it measures amps/watts that are actually being used by something running off a 12v battery?
Possibly! this would be ideal for my solar setup. I will add it to my backog :)
@@MrDIYca just ordered some parts to try it myself using a pzem-017. If it does not work ill wait to see how you do it.
How much battery does it drain while running? Did you implement deep sleep mode?
Great project and video. Tool me awhile to get it going as I hadn't used Home Assistant before, is it possible you could show the code that sends out the notifications please?
I used HA notifications for that - so it is a bit dificult to show the code without HA ;)
@@MrDIYca many thanks for replying I now have it fully working, the only mod I would like is a sleep / deep sleep mode. The car I need it for is a Toyota C-HR 1.8 Hybrid which has a 12V battery problem when not used regularly.
Can i use a 1.5Mohm resistor?
you write that you should have 1.44Mohm but 1M ohm + 220K ohm is it not 1.22mohm then? It is confusing
It is one 220k risistor in d1 mini
Will the ESP8266 drain the battery or is there no problem with that? My dashcam has a device reading the battery level and shutdown the parking observation, if battery is too low. - So you could send the ESP to deep sleep, if it occurs.
Rough calculation: ESP8266 uses 170mA at 3.3V (0.6W). A typical car battery has 40A at 12v (480Wh). That means the ESP8266 by itself can drain the battery from full to 50% in 400h (16 days). That should give you a frame of reference. If you add deep sleep, it should last years. You might want to read this post - community.home-assistant.io/t/monitor-your-car-battery-in-home-assistant/201508
I have everything together adjusted the range where it matches and added the code to config yaml... I get the raw values for voltage... like 1270 instead of 12.70v??? what am I doing wrong.
value_template: "{{ (value_json.ANALOG.Range | float / 100 | round(2) )}}" When I try to add the card to HA it says entity is non-numeric. I can analog range and it shows up1,270 but cant get battery volts to show
The device sends the voltage in the 1270 format. But in HA, it takes that and /100 giving 12.7. You probably have a misconfiguration in HA. I would check the HA's forum for help, it is pretty active. I remember seeing this non-numeric issue with another thing I did in HA but it had to do with old values not being numeric, so HA assumes the whole sensor is non-numeric.
What resistance should you use for 24v battery version. Is that possible. Want to do same for DIY energy storage.
This will not work with 24v. The shield doesn't support it.
Hi MrDIY. Thank you for this video. It works great. I notice that the D1 power shield can be power by 24v also. Will it be possible to measure battery voltage on 24v? If so please could you assist me to determine the resistors needed to measure 24v
I don't think so. A 24v battery can actually go up to 28v when fully charged.
Thanks for sharing... I have followed your example and built this project to monitor the starter battery on my back-up generator.. Everything went well up to the point of Home Assistant. I got an mqqt brochure error. Did you already have a brochure installed in HA? This is my first time doing something like this..
Sorry, I am not familiar with brochure. Maybe check the HA support forum?
Hi, i follow your suggestion to build a similar one. I have built one using a D1 mini with 1220k ohm and 100k ohm to measure the car battery. The data is sent to HA API at home. It works perfectly with the deep sleep. However, I am facing a problem when I drive my car to another place not within the intranet, the esphome node would continuously search the WIFI and not going to deepsleep. Do you have such kind of problem? Thanks
not an ESPhome expert, you might have more luck checking out the Home Assistant forums
@@MrDIYca ok thanks. I just found the solution using on_boot loop to solve the problem.
thanks for the video. i'm a bit confused about your voltage divider. Isn't the analog input range 0.0 - 3.2 Volts? Why scale the voltage down to 0 - 1.0 Volts?
Hi Frank. The ESP8266 ADC pin input voltage range is 0 to 1V. The Wemos D1 mini, which uses the ESP8266 chip, comes with an internal voltage divider that increases this range to 0 - 3.3V on pin A0. Hope this helps!
@@MrDIYca so why using those resistor values? Shouldn't you use 3.3v as a ref voltage?
@@rogerfar Hi Roger, what do you mean by ref voltage? The d1 mini ADC can't exceed 1 volt. The resistors bring the battery voltage range from 0 - 12 down to 0 -1. I have shown in the video the calculator I used to come up with these vaules - check it out.
@@MrDIYca This confused me too but after looking at the schematic I see why. You're both right. The ESP8266 wants 1V. The Wemos D1 Mini wants to use a 3.3V range so they put a voltage divider on board already: So it goes ("D1 max 3.3V input" - 220K - "ADC max 1V input" - 100K - GND). In the video you add a 1.22M resistor in series so it now goes ("External max 16V input" - 1.22M - 220K - "ADC max 1V input" - 100K - GND). The 3.3V input point is still there in between the new 1.22M and the on-Wemos 220K but it's not used any more so isn't mentioned. It's more obvious if you draw it...
Hi, can you explain what to do to measure 84v max? 20s 18650. Many thank, Konrad
Hi, this solution will not work for you. The shield I believe it limited to 24v max.
How are you powering the ESP8266 D1 mini? Is it only on when the car is engaged/turned on? Or is the D1 mini *always* on? Wouldn't powering the D1 mini drain your battery?
It is powered on all the time but only sends a msg every 30 mins. In theory, yes, anything connected to a battery will eventually drain it but it will take months. Hopefully you will get a notification before that happens :)
First of all, very nice videos and IOT ides, good luck with the channel, hope that channel will continue with smart home DIY ideas based on ESP boards.
Just one question, calculation for voltage divider was for 16V battery and the measured battery voltage is actually 12V. Is it possible to do this only with NodeMcu ESP8266 board? Should be able to take 12V if I am not mistaken?
Would be nice to show some examples with ESPHome in the future.
Thank you Marko. I check the schematic for NodeMCU and it looks like it simular to the D1 mini. They both use a 220k/100k voltage divider for the ADC so that means they are both limited to 3.3v. You will still need to extend the range to accept 12v.
@@MrDIYca Please check this link: components101.com/development-boards/nodemcu-esp8266-pinout-features-and-datasheet
Under NodeMCU ESP8266 Specifications & Features You will find Input Voltage: 7-12V.
Hi Marko, the device can accept 7-12v but the Analog Pin can only accept 0-3.3v. Scroll down until you see:
Analog Pin | A0 | Used to measure analog voltage in the range of 0-3.3V. This is why I extended the voltage divider.
Is the WiFi signal affected with the D1 Mini being under the hood?
It depends on how far the car is from the wifi AP. If your phone can pick the wifi signal next to the car then you are probably okay.
Hi MrDIY. Thank you for getting back to me wrt the 24v. I have a 12v setup as per your video It work great but I notice that when the power goes out it drains my battery very quickly its a 7ah lithium battery. Brad new. I dont know how its possible as the D1 with power shield should really not draw alot of power. I am a noob at this stuff so hoping you might know why this is happening. All I have different from yours is that I have a 1.20 mega Ohm resistor as I was not able to find the 1 megaOhm and a220k Ohm as per your video. It still works to measure the battery level. Does this maybe affect it? Thanks in advance for your assistance
I guess the d1 is stuck trying to connect to the AP (that is offline) until it runs out of battery. Maybe a timeout can help?
This looks fantastic and i can think of numerous uses but i just cant get it to work. I have set the device using Tasmota exactly as described and setup home assistant on a Pi3 and followed all the instructions but the device does not show up on home assistant. I must be missing something :( I tried installing an MQTT server on home assistant but still could not get it work?
I highly recommend visiting the Home Assistant Forum and Dicord help channel. There are a lot of amazing people over there that will give you a hand with the MQTT server setup: home-assistant.io/help
@@MrDIYca I think i am now getting there thanks :) I had lots to learn about home assistant but now have a few sensors working so now back to the voltage monitor. I do have another question. You use the voltage divider to lower the sense voltage but it appears you are just using two resistors in series and connecting one end to input voltage and the other to the A0. But usually a voltage divider is used from the center tap of the two resistors?
Great. Yes, that is because I am not creating a voltage divider. D1 mini already has a voltage divider built-in using 100kΩ and 220kΩ resistors. I am simply increasing the 220kΩ end by adding an extra 1200kΩ ( 1MΩ + 200kΩ) for a total of 1440kΩ. Effectively creating a voltage divider with 100kΩ and 1440kΩ resistors.
@@MrDIYca The problem i am having now is when i copy your code into the configeration.yaml file it does not like the unique_id:car-elantra-battery line? So will not allow me to save it into the file?
Instead of Resister (megaohm) possible to use a buck converter?
No the resistors are needed to measure the battery voltage
@@MrDIYca Hello, I think I understood it wrong from the other video that I was watching. On their's they did not include the power supply for the D1 Mini, assuming they used the USB of the computer to power it up, when I disconnected it from the computer the D1 is off ( lol ) ...
So in powering our D1, we need a buck converter right to supply 5V to the D1. then the 1440 MegaOhm is for the A0.
In your case, the Battery Shield was able to handle the battery voltage?
My usage: I want to build a smart battery monitor for my Koi Airpump built-in UPS that I will also convert to full solar setup.
Please add an appropriate fuse for your wire size so you don't burn your car down. LOL Great project otherwise.
Is it possible to use this for monitoring a 36 volts e-bike battery that when it is fully charged have 42 volt and empty 33 volt?
I want to monitoring the storage charge so I can stop it when the battery have 38 volts.
All help is appreciated.
Hi Hunder, the answer is no, you can't using this shield as it is limited to 24v I believe
Ok. thanks!
Se if I can find any other way.
Can this be tweaked to use with 48v system
You can play with the resistors to increase the range but your problem will be the power shield. It is rated for 24v max. I am sure you can find another converter that will take in 48v and give you the 5v needed.
So I out everything together and added the code to config yaml... I get the raw values for voltage... like 1250 instead of 12.50v??? what am I doing wrong.
value_template: "{{ (value_json.ANALOG.Range | float / 100 | round(2) )}}"
Do you know what is the raw value coming into HA? value_json.ANALOG.Range?
@@MrDIYca 1250 or sooo
17:00:30.457 MQT: tele/Battery-Transit-250/SENSOR = {"Time":"2021-06-17T17:00:30","ANALOG":{"Range":1270}}
can a module publish to 2 different mqtt brokers?
I don't think Tasmota allows mutiple MQTT connections.
Good idea. Did you try to measure current consumption? Just interested what drain it has?
No, I haven't but D1minis usually use 70mA. I have it pulling the voltage every 15 minutes.
70mA when in deep sleep. Plus you have a power shield too.
that is true. It has been monitoring my car for 2 weeks now and I was able to start it just fine the other day. But it would be useful to get accurate energy usage for a span of one day or so.
@@arnsle Not in deep sleep they won't! Deep sleep drops power consumption below 1mA into the micro-ampere range. If the ESP8266 is allow to idle-sleep the WiFi modem, power consumption should drop from 70ma @ 5v to around 25-30mA IIRC. It will be less than that on the 12v side (somewhere in the order of 15mA), since current is relative to voltage. Even so, if the car was parked up for a couple of months you would want to charge the battery up anyway, as the onboard electronics as well as this would drop the battery state of charge more than enough to cause some permanent damage to the battery if not charged.
Yes, Tasmota don't go to the deep sleep. Does not matter how often make voltage readings. I tried to measure D1 + shield and 18-40mA. So I went with mysensors and Nrf24l01+ it goes to deep sleep but because of the lm2596 does not go less 4mA. Maybe need to try different stepdown regulator.
And how with esphome?
Check my post on the home assistant forum someone already ported it to esphome.
buat yg via bluetooth om
Question, did you use the vehicles battery to power the D1? I thought it required 5v usb and a car battery would be over 12
Hi Michael, no you can not use the car battery directly witht he D1 mini. I used the Wemos D1 mini power shield amzn.to/2ZmI0Vq you can see it in the videio at 00:24
@@MrDIYca Laughing... I didn't see any reply to this until now. I did see the power shield board in video, but didn't know what it was until I researched it today (really brief on that in video). Anyhow gave tasmota a try and I am now able to read voltage, temp, humidity, and DewPoint thanks to your video and others. Integration to MQTT was a pain, but now that I've been using it (setoption19 1 in tasmota was key for me) my life is getting better. Don't understand why alexa doesn't see anything (it did with ESPHome), but I was really looking for local control anyway. Just got a Shelly 1PM that I will wire up to my air conditioner in power shed and then I will start doing some automations. This home assistant/tasmota/MQTT/Python/etc is not for the faint of heart. Towards the end of your video you are trying to calibrate your voltage output using AdcParam... do you know what each individual entry represents? 6, 0, 1023, 0, number
@@michaelbatchelder great to hear you got most of it figured out. It does indeed have a steep learning curve at the beginning. For the AdcParam command, it goes like this: mode (6 for linear range remapping) , input range low value=0, input range high value=1023, output range low value=0,output range high value=number you are searching for. It is basically mapping the analog values it reads (0,1023) to a range that makes sense to us, aka, the battery voltage (0 to 1600) or ( 0v to 16.00V once we divide it by 100 in the MQTT sensor).
A side note: in the video I actually used a bigger resistor. I used a 1.44Mohm instead of 1.22Mohm. That is why my adcParam were bigger. You will probably be in the 1600 range as compared to my 1770 in the video.
@@MrDIYca I have all the elements/values showing up on LoveLace interface on Home assistant, voltage of 28.8v reading 2878. Can I format that "2878" to an aesthetic reading that shows 28.78v? Sorry to pick your brain so much, but I appreciate all the help you have given so far. My hassIO install is new, with some Tuya switches (really slow reaction time on them, may flash them and install tasmota), weather, network sent/received (don't understand the naming structure, list 3 sets, but I only have one router), and a roku. I am sure there are multiple ways to get things accomplished. I also see the NodeMCU that I have will except 12v for power, will have to test to see, but I have a dc to dc transformer in the shed that converts 24v to 12v. Going to add to more batteries to the solar shed and setup everything the next set of days off.
@@michaelbatchelder personnaly I prefer tasmota over tuya cloud, I made a tutorial on how to flash them using a proxmox vm here ruclips.net/video/DDYK7cE9rEA/видео.html). I believe you can try templating to format the value www.home-assistant.io/docs/configuration/templating and use the value to do something like value_template: "{{ (value | float / 100 | round(2) )}}"
What resistors do I need to monitor 24V? Is it 2.44 MOhm?
The battery shield is rated for 24V max. The batteries can easily exceed that, especially while charging. I don't recommend you use it with a 24v system.
@@MrDIYca Thank you, good to know!
@@MrDIYca But what if I connect it to only one of my 6 18650 battery cells, so it measures only around 3.7-4.2 volts?
Can you monitor anything else? Like weather the doors are locked?
Hi Benjamin, no it is connected directly to the battery and not through the CAN bus.
having this constantly powered with no regard to deep sleeping is not a good idea. you should move this project to esphome so that you can check for ssid and deepsleep for 30 for example
Did you really just directly connect the ADC pin to the power through 1.2M ohms? That is not how voltage dividers work at all. Consider yourself lucky you didn't destroy you ESP8266. The voltage divider is between the power and ground and the wire to the ADC is from the middle of the two resistors. Your values are far too high to do this without a buffer. You should get decent results with between 5k-15k total resistance between power and ground as there is a calibration step.
Last step you need to do is put a zener across the voltage divider. Car power systems can be dirty so this is added to make sure that the voltage across your divider never exceeds 15v.
No, I did not connect the battery directly to the ADC pin. I extended the BUILT-IN voltage divider in the Wemos D1 mini board. I created a video explaining the difference between ESP8266 modules and boards (.. and the extra features they have , such as voltage dividers). Check it out here - ruclips.net/video/dGrJi-ebZgI/видео.html