Good day.
I’m kind of hoping someone can assist me with this, as I can’t seem to find anything related to “total consumed current” on any of my searches. (Essentially a battery capacity meter)
ESPHome does pop up with an autocomplete for “total_consumed_current”, but no matter what I tried, I couldn’t resolve issues in the format in order for it to actually save without errors.
What I am planning to do is build a unit with a ina219 to test a 12v car batteries capacity (as an example), so, here in lies my query.
I’ve also thought of just taking the declared amount of the power, and then dividing the sum by the volts again to get back to amperes total, but I don’t think that would give me an accurate consumption of Ah.
The code below is for one of the ina219’s which is for my micro solar setup, and not the capacity meter, but I was messing around in there to see if I could find a solution to my future problem
# Power/Wattage Sensor
- platform: ina219
i2c_id: bus_a
address: 0x40
shunt_resistance: 0.010069 ohm
update_interval: 0.2s
bus_voltage:
id: ina219_1b_bus_voltage
name: "INA219 1B Bus Voltage"
unit_of_measurement: "V"
accuracy_decimals: 3
filters:
- throttle_average: 5s
# Would something along these lines work for total current consumed?
# I probably won't require the power and volts,
# but thought I could leave that in for the future
current:
id: ina219_1b_current
name: "INA219 1B Current"
unit_of_measurement: "A"
accuracy_decimals: 2
filters:
- multiply: 10
- throttle_average: 5s
on_value:
then:
- lambda: |-
static long last_time = 0;
if (last_time == 0) {
last_time = millis();
return;
}
long duration = millis() - last_time;
last_time = millis();
float cur = id(ina219_1b_current).state * 1000.0;
float volt = floor(id(ina219_1b_bus_voltage).state * 100) / 100.0;
float power = volt * cur;
if (volt == 0 || fabs(cur) < 2.0) {
return;
}
float ah = cur * duration / 1000.0 / 3600.0;
id(amp_hour) += ah;
id(work_time) += duration;
power:
id: ina219_1b_power
name: "INA219 1B Power"
unit_of_measurement: "W"
accuracy_decimals: 3
filters:
- multiply: 10
- throttle_average: 5s
shunt_voltage:
id: ina219_1b_shunt_voltage
name: "INA219 1B Shunt Voltage"
unit_of_measurement: "mV"
accuracy_decimals: 2
filters:
- multiply: 10000
- throttle_average: 5s
- platform: total_daily_energy
id: ina219_1b_daily_energy
name: "INA219 1B Daily Energy"
power_id: ina219_1b_power
filters:
- multiply: 0.001
unit_of_measurement: "Wh"
device_class: energy
# Alternative to getting current consumed
# (wrong platform most likely) ???
- platform: total_daily_energy
id: ina219_1b_hourly_current
name: "INA219 1B Hourly Current"
power_id: ina219_1b_current
unit_of_measurement: "Ah"
device_class: current
# Or maybe something in this line???
- platform: template
name: "INA219 1b Hourly Current"
id: ina219_1b_hourly_current
lambda: return id(ina219_1b_current).state * duration ;
accuracy_decimals: 2
unit_of_measurement: Ah
icon: "mdi:flash"
update_interval: 0.2s
filters:
- throttle_average: 5s
Also, if possible, some guidance to automate this in ESPHome. Basically, a trigger on current greater than 0.01A and switch off when a battery gets below12v.
I hope this made Any sense to someone out there, but if not, let me know, and I’ll try and clarify.
I’m sure it’s something I’m just overlooking, and probably ridiculously simple, but it evades me at the moment.
Thank you in advance for any insightful tips or hints.
Ps. Apologies for the long winded explanation and also if there are any formatting errors, as I was doing this on my phone during a power outage