Keep energy sensor data (stop from resetting)

Hi there,

i have a heat meter which gives an impulse everytime it steps up by 1 kWh. I attached a D1 mini to it and configured it via ESPHomes pulse counter feature to count the impulses and then use the “total” function to give me the readout in HA.
It works good but sometimes the D1 restarts or there is an interruption in the power supply so the value resets to 0.
I want a readout in HA with the actual real value of the heat meter (e.g add the actual value to the sensor via developer settings tab).
So i can’t use the integration sensor as that requires a sensor which reads in W not kWh. Is there some template that i could use so the sensor only ever adds values and never resets to 0?

Have you looked at utility meters.

Utility meters do quite the opposite, they reset to zero to get day/month totals. AFAIK sensors need to be derived from a special class in order to save their state, so I doubt that can be retrofitted. Input helpers do keep state though, so what I would do is use an input helper to store the grand total.
If you need to have it in the right device_class I’d use a template sensor to convert. But maybe there is a simpler way I do not know about.