Voltage Divider Battery Monitor Quesion

So i have built multiple boxes for my backyard to transmit BLE to Wifi for my plant monitoring sensors, everything is working fine and i am trying to get the voltage of the battery along with the percentage but im not sure if i am calculating this properly

My system is put together just like this one at

https://randomnerdtutorials.com/power-esp32-esp8266-solar-panels-battery-level-monitoring/

Utilizing a 100k and 27k resistor as in the diagram, i am pulling voltage and converting battery percentage correctly, but im not sure if the values are correct or how to check

I followed the instructions exactly and i am just wondering if my data is correct

Here is my yaml file

# Battery Sensor
  - platform: adc
    id: solar_plant_batt_voltage 
    pin: GPIO33
    attenuation: auto
    name: ${friendly_name} Battery Voltage
    update_interval: 1s
    accuracy_decimals: 1
    filters:
    #u se moving median to smooth spikes
      - median:
          window_size: 10
          send_every: 10
          send_first_at: 10
      - delta: 0.1 # Only send values to HA if they change 
      - throttle: 30s #Limit values sent to Ha
# Convert the Voltage to a battery  level (%)
  - platform: copy
    source_id: solar_plant_batt_voltage
    id: solar_plant_batt_level
    icon: "mdi:battery"
    name: ${friendly_name} Battery Level
    unit_of_measurement: '%'
    accuracy_decimals: 1
    filters:
      - calibrate_linear:
      # Map from voltage to Battery level
          - 0.41 -> 0
          - 3.1 -> 100
      #Handle/cap boundaries
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);
      - delta: 0.5 #Only send values to HA if they change 
      - throttle: 30s #Limit values sent to Ha

Here is what the unit is reporting

[14:58:30][D][sensor:094]: ‘BLE Proxy 4ca15c - East Garden Battery Voltage’: Sending state 3.01160 V with 1 decimals of accuracy
[14:58:30][D][sensor:094]: ‘BLE Proxy 4ca15c - East Garden Battery Level’: Sending state 96.71378 % with 1 decimals of accuracy

I have a 10000 mAh battery in the unit that runs at 3.7 i have a 6v solar panel charging the battery all is working fine there, i am using the instructions to drop the voltage down from 3.7 to 3.3 volts successfully.

Looking at the settings its mapping the voltage but is it mapping it correctly since it is stating that 3.1 is 100% which really it is not, im not sure if i can just change these numbers to reflect what they should be or are there other calculations needing to be done or should they be calculated differently???

To me this below doesnt make sense but its what the writeup states

  # Map from voltage to Battery level
      - 0.41 -> 0
      - 3.1 -> 100

Help is appreciated i just want to get correct values so i can know where the battery is at during the night and day,

Also if possible is there a way i can get any information for how much the battery is being charged or the charging state? I am using a TP4056 solar charger to charge the battery, not sure how or if possible i can get charging state from it or the battery.

Would it be better if i used an external voltage divider or some other sensor to accomplish this or use what i currently have setup?? I see Adafruit has one the max17048 would this be better?

Thanks!

If it’s a lithium cell and tp4056 is a lithium charger then 0% is closer to 2.7v and 100% is 4.2V.

Thanks for the help!

It is, so changing the values is all i need to do to make this correct?

Best to check with multimeter the actual voltage across the cell to compare against expected. 27k 100k may be off a bit. Sorry upper value voltage across the voltage divider to adc pin may be 3.3v which would be a voltage of 4.2v across the cell. You are working out % and not voltage which would be 3.3 —> 4.2
2.0 → 2.7 or close to that.
Lower voltage will not be anything like 0.4

Gotcha, i changed the values and this is what its reporting now

[15:21:32][D][sensor:094]: ‘BLE Proxy 4ca15c - East Garden Battery Voltage’: Sending state 3.01809 V with 1 decimals of accuracy
[15:21:32][D][sensor:094]: ‘BLE Proxy 4ca15c - East Garden Battery Level’: Sending state 21.20626 % with 1 decimals of accuracy

When i check the voltage at the TP4065 coming from the battery i am seeing 3.8 volts even though its reporting 3.0, so something is definitely off for some reason and im not sure what is causing this, am i using the wrong resistors for it to be that far off or is it calculations?

Oh and my other BLE Proxy is reporting 3.10 volts but the battery is showing 3.99 on my meter

[15:30:09][D][sensor:094]: ‘Bluetooth Proxy - Back Yard WiFi Battery Voltage’: Sending state 3.13752 V with 1 decimals of accuracy
[15:30:09][D][sensor:094]: ‘Bluetooth Proxy - Back Yard WiFi Battery Level’: Sending state 29.16828 % with 1 decimals of accuracy

It’s reporting 3.99 volts input at the first resistor and 3.25 volts at second resistor so it’s off by about .15 not a big deal but why am I not getting battery voltage and I’m getting voltage from the esp32

So I really have no way at this point the way it’s configured to see the battery voltage from what I’m seeing

I’m a little lost at this point I did fine the one ble proxy was wired wrong for the resistors I fixed that didn’t change anything

Remember that the pin you’re using has impedance too, which will be in parallel with your voltage divider’s one resistor. You need to account for this.

ResistorVoltage
As Parautenbach said the Resistance of your load(the rest of your device) will lower the combined resistance of the part of the circuit your are getting your ADO voltage at. The numbers in calculations below just need adjusted a little for each use.

    filters:
      - multiply: 1.25

The way I do it with cells and voltage divider calculation is to get the voltage of the whole cell by multiply ADO by 1.25(4/3.2)
1/R=1/R2+1/RL

  - platform: template
    sensors:
      solar_plant_batt_voltage:
        friendly_name: Battery Capacity
        device_class: battery
        unit_of_measurement: "%"
        value_template: >
            {{ ((states('sensor.solar_plant_batt_voltage')|float-2.7)/0.0156)|round(2) }}

Then in HA I setup a template sensor to give the useful capacity of the cell. (4.2-2.7)*66 was roughly equal to 100%. I used the / as I couldnt find the * (multiplication) symbol just to explain that weird calculation.

Volpic
If you create a graph it’s easy to see if battery is charging or discharging.