Counters, utility meters, delta and long term stats

Hi there,

I’ve a little challenge that I’d like to tackle in the most proper way.
My wallbox charger for EV is not providing a full, long term, counter of kWh it used to charge my cars.
So it’s not possible to create a utility meter based on this.

I can still poll when it charges with a status:
sensor.wallbox_portal_status_description
and at what intensity:
number.wallbox_portal_max_charging_current).

It also provides some energy added counter:
sensor.wallbox_portal_added_energy

I two ideas here:
1/ If the energy added counter works by charge session, when a session starts, poll the value, poll it at the end of the charge and add it to some variable.

2/ Count the number of minutes when the status is “charging” at 16A and the number of minutes it’s charging at 32A, add the two in a templated sensor and

In both cases I can add the amount to a utility meter “Daily” and reset it at midnight. The meter would be of Delta type since it’s not counting absolute since zero (I cannot make it permanent sadly, it’ll reset on every HA reboot).

I can maybe save / restore those values when HA stops & start to make it some sort of “permanent counter from the beginning” and not a delta one?

Now how to add it to a weekly, monthly, yearly utility meter? Since it’s a delta, it can work for a daily one, but the daily value reset will not make it suitable for a long term meter no?

I’m guessing the same problem is true for all kind of utility meter source resetting at midnight (delta type)? How to keep long term stats of these ?

Answering my own question, utility_meter.calibrate probably allows to do the job.
Utility meters are long-lasting; they can be forced into value using this method, it should do the job nicely.