While I abandoned the original project, I got back to this for another project and thought I’d drop some more details here as the info I found was a little scattered and confusing for a newbie…
Based on:
-
This article: ESP8266 battery level meter | ezContents blog,
-
This thread: ESPHome Battery Level Sensor,
-
These objectives and resistors I had:
-
Some help/checks from @ssieb over on Discord,
-
This board/schema
-
The ESPHome docs: Analog To Digital Sensor — ESPHome
-
This wiring
-
And this ESPHome config:
sensor:
- platform: adc
id: solar_plant_batt_voltage
pin: GPIO32
attenuation: auto
name: ${friendly_name} Battery Voltage
update_interval: 1s
accuracy_decimals: 1
filters:
#use 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
I’m not really 100% if both of the black wires are required?
Only one ground is required.