The voltage you are measuring is not the direct battery voltage. Your Battery (if you have an 18650) will range from 4.2 to approx. 2,8V. The board takes that voltage and regulates it to (i think) 3V. If the battery is near empty, this voltage will drop below 3V and therefore you can detect a low voltage scenario. This would be approach 1.
If you would like to get a more precise information on your battery, you could solder the battery + via an voltage devider to the ESP Analog input. (The esp pin will not accept a voltage greater than 3,3V on its analog in).
You will have to measure the battery voltage then and compare it to the voltage the ESP measures. Calculate the factor value by (Battery voltage) / (ESP measurement)
- platform: adc
pin: A0
name: "clever name here"
update_interval: 30s
unit_of_measurement: "%"
accuracy_decimals: 0
icon: mdi:battery-medium
filters:
- multiply: insert (Battery voltage) / (ESP measurement) here
- calibrate_polynomial:
degree: 3
datapoints:
- 0.00 -> 0.0
- 3.00 -> 0.0
- 3.23 -> 10.0
- 3.33 -> 20.0
- 3.40 -> 30.0
- 3.48 -> 40.0
- 3.57 -> 50.0
- 3.65 -> 60.0
- 3.72 -> 70.0
- 3.80 -> 80.0
- 3.88 -> 90.0
- 4.15 -> 95.0
- 4.20 -> 100.0
- lambda: |-
if (x <= 100) {
return x;
} else {
return 100;
}
If you manage the electrical part, the above mentioned code will give you a rough estimation on the battery capacity. In my system this has prooven to be sufficiently reliable.