Monitor your car battery in Home Assistant

I’m struggling here. I can’t get the voltage multiplier to work correctly.

I am using a ESP32 based D1 Mini as I need a more powerful ESP for a GPS sensor. I created a resistor for 1.46M ohm (as that’s the closest I could get to 1.22M with the resistors I have. I have the resistors connected to the Voltage input from the DC power shield to the A0 pin (on the ESP32 that’s GPIO36).

I’m using ESPHome on the ESP and this is how I have the sensor setup.

  # VCC input voltage
  - platform: adc
    pin: GPIO36
    name: "BigBlue Battery Level"
    update_interval: 10s
    filters:
      - multiply: 10.90909090909091

The issue I am having is that the voltage is always 12v. I’ve got the ESP connected to my bench power supply and if I up the voltage to say, 14v, the sensor still shows 12v.

I tried adding attenuation to the config, as on the ESPHome docs it mentions there is a limit on the ESP32 but this didn’t make a difference other than increasing the voltage to 24v and 42.55v on the sensor.

ESP32 Attenuation
On the ESP32, the voltage measured with the ADC caps out at 1.1V by default as the sensing range or the attenuation of the ADC is set to 0db by default.

To measure voltages higher than 1.1V, set attenuation to one of the following values:

0db for a full-scale voltage of 1.1V (default)

2.5db for a full-scale voltage of 1.5V

6db for a full-scale voltage of 2.2V

11db for a full-scale voltage of 3.9V

I don’t get why… :frowning:

I took a quick look at the esp32 d1 mini datasheet and it doesn’t look like it has a voltage divider.

If I remember corretly, the ESP32 ADC can read up to 3.3v so anything above 3.3v will always give the max value ( 12v in your case). Try to feed it something between 0 and 3.3 volts and see if you the readings go up and down with it.

Hopefully your ADC was not damaged already.

If I measure the voltage between A0 and GND I get just over 3.3v.

The ESP32 doesn’t have a pin called A0. I suspect you have a ESP8266. ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

Also the pics I can find of the ESP32 D1 mini doesn’t show any pin labelled A0.

It doesn’t, it’s GPIO36. The D1 mini esp32 has the same layout as the esp8266 version, just with extra pins. In esphome you can still use the esp8266 names.

Where is that documented?

I’ll try and find it. But either way I’ve tried it with both GPIO36 and A0.

The issue, as MrDIY stated above is that the ESP32 version doesn’t have the voltage divider. I created one using resistors between V in and GND and coming off the middle of the string to the ADC pin. This was 2.4v.

I was getting a voltage reading in ESPhome however the value was jumping around and didn’t seem to work correctly.

Can you draw it and post the circuit diagram? Just pen, paper and a cellphone pic will do.

These are the only resistor values I have to hand, but the output is 2.4v.

Even better than pen and ink :slight_smile:

I still don’t see that the esp32 d1 mini exposes GPIO36. At least not on the pic I posted above, or in the github schematic that @MrDIY posted. In fact the schematic shows it a not connected.

What is the label that you have this actually connected to?

I do acknowledge that there are plenty of inaccurate schematics and pictures online, perhaps show us a pic of your device if you think it is different to what @MrDIY and I have posted.

This is the version I am using. D1_Mini_ESP32_-_pinout.pdf (shopify.com)

you can see the GPIO36/ADC-0 pin top left.

That is good - you should get 2.4v. Using these resistors you can feed A0 directly into the ESP32 IO36 for 12v batteries.

I suspect your esp32 got damaged when you fed it the 14-20v earlier. Try to use your power supply and feed the esp32 0-3.3 volts and check the ADC values. If that is not working try another esp32.

1 Like

I think you may be right. I have just had two more delivered so I will try again.

You could also just try another GPIO.

1 Like

Good idea, as there are a few ADC pins.

Good news! It is working now :slight_smile: New ADC pin worked. Thanks everyone. Now I have a GPS tracker and battery monitor for my car.

1 Like

Just to finish this off, espressif call GPIO36 “sensor_vp”. See https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf

This seems to be what they are labelling as “SVP” on the D1 mini esp32 boards. So you are right, it is GPIO36 and the labelling fooled me. Makes sense now I know SVP stands for sensor_vp.

You live and learn. Thanks for the pinout pdf, I have 6 of these devices sitting in a drawer, and that will be handy.

Glad you got it going too!

2 Likes

I have stumbled upon this excellent topic on creating a voltage sensor for - actually anything.
Newbie in HA and ESPHome.
Having a problem getting the above accepted in my configuration.yaml file.

homeassistant:
  customize: !include customize.yaml
  sensors:
    - platform: mqtt
        name: Battery Voltage
        state_topic: "battery_voltage/sensor/c270_cdi_battery_monitor/state"
        unit_of_measurement: 'V'
        device_class: voltage
        qos: 2
        payload_available: "online"
        payload_not_available: "offline"

Getting
Error loading /config/configuration.yaml: mapping values are not allowed here
in “/config/configuration.yaml”, line 58, column 13

Doing something wrong somewhere.
Help will be highly appreciated!

sensor:
Singular.

I think that is it at least

Do you have it below homeassistant or is that a copy paste error?
It can be below but it shouldn’t be indented

homeassistant:
  customize: !include customize.yaml

sensor:
  - platform: mqtt
      name: Battery Voltage
      state_topic: "battery_voltage/sensor/c270_cdi_battery_monitor/state"
      unit_of_measurement: 'V'
      device_class: voltage
      qos: 2
      payload_available: "online"
      payload_not_available: "offline"

Hellis81, thank you for your reply.
Picked it up just now. This has been greying my last brown strands of hair.
Also swapped state_topic & name:
Validates!!