Esp32 Voltmeter

Hi there.

I have built me a esp32 voltmeter for 2x12v series battery bank. So i have the voltage dividers at 100k and 27k for the 12v and 100k and 10k for the 24v. I do not have any other components on the circuit.

I am using a lamda function in esphome to get the other batteries voltage which should work i believe. I have taken various measurements my multiplier for the 24v bank is 11.093 and my multiplier for the 12v is 5.018.

In Esphome I cannot get the lambda calculation to work properly.

I assume i could adjust the multiplier until the 2 voltages are the same? (Which they are currently)

What i was wondering is should i put in a capacitor on each sensor to filter out noise? I am happy with 0.1V variances.

I will post my Yaml below if that would help.

You probably won’t get much help unless you do…

esphome:
  name: inverter-voltmeter
  friendly_name: inverter-voltmeter

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "qjVQJDaHTfgm0bcKA+AxjMOe6+sF+ULZ9XOIfXGYadM="

ota:
  password: "670298d092333d002f20dfa93a489618"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Inverter-Voltmeter"
    password: "cDB0uhl3q4nc"

captive_portal:

sensor:

    - platform: adc
      pin: GPIO34
      name: "Battery bank"
      id: batterybank
      device_class: voltage
      unit_of_measurement: "V"
      attenuation: auto
      accuracy_decimals: 1
      update_interval: 5s
      filters:
        - multiply: 11.09311
        - sliding_window_moving_average:
            window_size: 20
            send_every: 20

    - platform: adc
      pin: GPIO35
      name: "First battery"
      attenuation: auto
      id: firstbattery
      device_class: voltage
      unit_of_measurement: "V"
      accuracy_decimals: 1
      update_interval: 5s
      filters:
        - multiply: 5.018
        - sliding_window_moving_average:
            window_size: 20
            send_every: 20

    - platform: template
      name: "Second battery"
      id: secondbattery
      device_class: voltage
      unit_of_measurement: "V"
      accuracy_decimals: 1
      update_interval: 5s
      lambda: return id(batterybank).state - id(firstbattery).state;
      filters:
         - sliding_window_moving_average:
            window_size: 20
            send_every: 20

You’re going to have to explain what isn’t working?

The Battery bank less the First battery is not adding up on the logs. I am going to mark as solved as I am rather going to put 2 individual esp32’s on each battery and then combine them to get the banks voltage.