Measuring 12v on ESP32 or ESP8266

If you stick with the voltage diviver you don;t have to worry about current and what the components can handle.

But a small fuse in the wires from battery to voltage divider would never hurt.

To protect against shortening the cable and shorterning your car battery.
Place the fuse as close to the battery as possible on the plus side.

A small 0.5A or even smaller blade fuse or glass fuse will do depending on the diameter of the cable

Oh and on the other question. A wemos D1 mini and a voltage divider will take ages to empty a car battery or generator battery. Your generator maintainer can handle the extra load from the wemos without problems.

So, since I started looking at this, I have learned a little more about my generator. It appears i can do what i am wanting by tapping into the transfer switch in the house. This is much better since I don’t have to leave anything outside.

There is a line coming into the transfer switch that feeds the battery power to a terminal block. From there, I can tap in and get the power I need to power the esp32 via a 12v to 3.3v stepdown and also monitor the battery voltage via a voltage divider and adc input. I also can monitor whether or not the generator is running by tapping into one side of the line output from the generator that feeds the panel when it is running, before the switch is engaged. This will require an AC120v to DC5v transformer and another voltage divider to adc input.

So, with that said, here is my drawing of what I have planned. Please let me know if you see anything that would cause an issue that i may have overlooked.

Biggest question I have is concerning whether or not i should be using one GRD point on the ESP32 or should I use multiple points.

Thanks for the input.

the-buzz-man

Check Shelly Uni device.
Can measure up to 30V without external dividers.
As well can be powered from battery directly.

2 Likes

https://www.aliexpress.com/item/1005006435754157.html?src=google&src=google&albch=shopping&acnt=708-803-3821&slnk=&plac=&mtctp=&albbt=Google_7_shopping&albagn=888888&isSmbAutoCall=false&needSmbHouyi=false&albcp=19373854259&albag=&trgt=&crea=en1005006435754157&netw=x&device=c&albpg=&albpd=en1005006435754157&gad_source=1&gclid=EAIaIQobChMIt9yQ36uVhAMVRqhmAh3rRwSkEAQYBSABEgJIIfD_BwE&gclsrc=aw.ds&aff_fcid=cf9344b6475e4c41abdc834cbe34d69f-1707175351224-00404-UneMJZVf&aff_fsk=UneMJZVf&aff_platform=aaf&sk=UneMJZVf&aff_trace_key=cf9344b6475e4c41abdc834cbe34d69f-1707175351224-00404-UneMJZVf&terminal_id=edc8254cdb914e52bbed04a67f2d3cca&afSmartRedirect=y

1 Like

Thanks for sharing the wiring diagram. I am planning to connect similar one. Have you got this completed? Can you share the YAML and update that you have done on the components or the wiring?

I pretty much did set it up exactly like my drawing. I think the only change I made was that I used the #22 ground for all the devices except for the 12v to 3.3v stepdown.

Everything has been working fine since I set it up. I haven’t lost power since then, but it has notified me each week when the test run is done.

Here is the YAML I am using:

sensor:
 - platform: wifi_signal
   name: "WiFi Signal Sensor"
   update_interval: 60s   

 - platform: adc
   pin: GPIO4
   name: "battery"
   attenuation: auto
   accuracy_decimals: 3
   update_interval: 60s
   filters:
      - multiply: 1.01

 - platform: adc
   pin: GPIO6
   name: "120vSupply"
   attenuation: auto
   accuracy_decimals: 3
   update_interval: 60s 
   filters:
      - multiply: 1.02    

I’ve used the filters to get it to match the readings on my multimeter.

I’ve created two template sensors in HA to get voltage back to where it should be by multiplying it x5:

Battery Template:

{{ (((states('sensor.generator_battery') |float -0.0 ) * 5)) | round(4)}}

120v Supply Template:

{{ (((states('sensor.generator_120vsupply') |float -0.0 ) * 5)) | round(4)}}

Here is a current screenshot of the panel I use to monitor it:

You can see the last run was on 3/06 when the voltage went up and stayed there during the run time.

I’ve set up the following automations to keep me informed:

  • If battery gets above 14v
  • If battery gets below 12v
  • If the ESP32 goes offline
  • If the ESP32 comes back online
  • When the generator is running (when 120v supply reads above 4v)
  • When the generator turns off (when 120v supply is below 1)

My goal for this project was to be notified when it does its’ weekly test runs. I’m not always home to hear it run and know that everything is working correctly. I do realize that if we lose power, I won’t know immediately as my network will go offline until the generator cranks and gives it power. My HA box is on a UPS, so it should be able to let me know shortly after the network is restored.

Let me know if you have any other questions or if I can be of any help.

the-buzz-man

1 Like

Thanks for your immediate reply and the YAML. I have ordered these voltage dividers and waiting for its delivery. I am connecting it to esp32 as voltage input sensor to do further automation. I will reach here if I am finding anything different or stuck somewhere.

I have received my voltage stepdown unit (same product that you are using) and tested it, It is working fine. I want to keep the input voltage within safe value that GPIO pin can support, using 5V as input and getting 1V output from that unit.

I have connected above mentioned step down to esp32 devkit GPIO as voltage sensor. However when the step down unit is disconnected from esp32, only esp32 is powered on, random voltages are shown in the web page of esp32. This is triggering false positive and the conditions mentioned is getting executed. Adding any physical resistor is required to prevent this? Or do we need to call out Pullup or Pulldown on the supported pins in the YAML? I would like to keep the voltage as zero when the step down is not receiving any power from input or disconnected with esp32.

  - platform: adc
    pin: GPIO33
    name: "Sensor Voltage"
    id: sensor_voltate
    attenuation: auto
    accuracy_decimals: 2
    update_interval: 5s
    filters:
       - multiply: 1.01
    on_value_range:
      - above: 0.51
        below: 3.0
        then:
          - if:
              condition:
                switch.is_off: motor_power
              then:                     
                - switch.turn_on: relay1

I am not using any physical resistors as you asked. When the generator is not running, I am getting 0.0000v from that sensor. It’s hard to say why you would be getting some random voltages. Without seeing how you have everything tied in, it’s hard to diagnose.

Thanks for your immediate reply on this. On further investigation, when I just connect the cable from stepdown (Pin S) to GPIO33 and Ground (Pin -ve) on ESP32. I have connected directly without any resistor or capacitors any where.

Step down → PIN S ----> GPIO33 → ESP32
Step down → PIN -ve → GND ------> ESP32

I am getting the voltage as 0.00 or 0.2v even though the stepdown is not connected to any power. However if we remove these cables, the GPIO33 is getting random voltage shown on esp32 web, but on the actual GPIO33 there is no voltage detected using multi meter. I tried even setting to attenuation: 11db. Just thought of sharing here.

Hello everyone,
I am interested in constructing a system that can detect when my UPS is about to power off and subsequently shut down my NAS. My initial idea involves using the ESP32 along with a voltage divider connected to the 12-volt batteries of my UPS. The first step would be to monitor the UPS voltage in order to determine the threshold at which it powers off. This threshold could then be used as a trigger to shut down my Synology NAS.

I would greatly appreciate any suggestions or insights based on your experiences.

@ the-buzz-man
How you can be advised if the ESP32 goes offline? in fact what is worring me is that in case of blackout the internet could be down with the risk that the ESP32 could not communicate with home assistant.

Thanks.

Did you try using the search box in here? A google search box? If you would have tried a search, you’d have seen stuff like this.

Or this stuff also…

Also, you should really do some reading and get a basic understanding of how esphome and HA work. One of the main reasons so many people like it is its ability to run localy or no internet needed. You dont need internet for an esp32 to communicate with HA you just need power and wifi. If you dont spend time learning and understanding the basics and instead jump straight to buying and building stuff, unfortunately your going to waste a lot of time and money.

Also, its very helpful if when asking a question that you include details about your hardware, any config/yaml that applies, log outputs that apply, and specifying which esp32 your using because, there are about 200 varietions of “esp32” and it matters sometimes.

Help us help you by providing details in your questions.

Thanks Fallingaway24 for your kindly reply,
yes I know about NUT and I know about UPSs that can be connected to NAS via USB or via SNMP but I have a very low cost UPS with no communication ports.
I was also suspecting that ESP32 was working without internet but you have kindly confirmed it. So it seems I’m on the right direction.

Regarding the type of ESP32 is the one I have used for this application

Thanks again

Gotcha! Ya, when i read your question I started having my own questions about it. Is this UPS able to fit in a shoe box or does it use an entire room?? Is this a DIY project on a budget or a high end unlimited budget? These are things people will base their answers on, so the more details you provide, the better the answers are you get.

Is everything all in one room? Is it close enough to wire things or is wireless needed ? What kind of batteries does it use? Pb? Li Ion? LifePO 4? What kind of hardware is monitoring the battery?

Instead of monitoring the battery and trying to determine when or at what voltage/load will it power down your NAS. Why not take over the whole process? You’re going to be monitoring the batteries so why not do your own low voltage shut off instead of only guessing when it will happen?

Ok, let’s go step by step.

  1. My UPS is a simple low-cost UPS but it cannot be moved because it powers a backup electrical circuit for various equipment (computers, router, wifi, etc.) located in different areas of the house, including the NAS that I want to protect from uncontrolled shutdowns.

  2. It’s a DIY project without a budget, meaning there are no budget constraints. I could easily solve the problem by purchasing another UPS with an SNMP port dedicated to the Synology NAS, and the problem would be solved. Since I like to ‘play’ with home assistants and find alternative solutions, I thought of doing this project. Essentially, creating an alternative NUT solution that reads the minimum voltage value of the UPS before it shuts off and uses it for controlled shutdown of the NAS through the Synology integration of Home Assistant. I already have the ESP32 and I am waiting for the voltage divider to arrive. However, if there are better suggestions, they are welcome.

  3. I didn’t understand this part, can you explain it better?

Instead of monitoring the battery and trying to determine when or at what voltage/load will it power down your NAS. Why not take over the whole process? You’re going to be monitoring the batteries so why not do your own low voltage shut off instead of only guessing when it will happen?

Thanks

Hello,

I finally built the circuit I had in mind. With three resistors, I managed to create a double voltage divider to reduce the UPS battery voltage. One to power the ESP32 through VIN, and another to reduce the maximum voltage of 26 volts to 3.3 for the ESP32’s pin 32.

On paper, everything is perfect. In fact, the UPS voltage of 26 volts is reduced to 3.3 for pin 32 and to 6.6 for the VIN pin. However, the ESP32 does not “turn on” with the VIN voltage of 6.6 volts.

At this point, I tried to power the ESP32 with the USB cable, leaving only the pin (gray cable) and the GND (white cable) connected. The ESP32 turned on, but when I tried to connect the GND, the house circuit breaker tripped.

I can’t understand why.


You can’t power esp with voltage divider. Voltage divider voltage depends on current draw.

This might help:
Here’s your divider with just voltmeters connected. Outputs 6.6V and 3.3V

Esp32 draws around 100-250mA, so let’s add 0.5W load to this circuit:


How are the voltages??
Obviously those readings will never happen because Esp32 will never turn on…

1 Like

Why don’t you use a step down to power the esp32?

1 Like

Understood!
image
I measured the resistance between GND and VIN pins, with the Esp32 off, of circa 2000 ohm.
With these schema it should work, correct?


Or should I consider also the resistance between Pins 32 and GND?