What's the best way to accumulate the values of a sensor?

Hey everyone,

I’m looking for a way to sum up all increases of a sensor since it started its measurements.
Basically, I have a sensor from an integration from my car that shows me the current charge level (it’s an EV) in % or kWh (it’s just a simple conversion). This sensor decreases its value while driving, and increases while recharging. What I’m now looking for is a way to some kind of variable (or something similar) to see the total accumulated charge.

E.g:
The variable has value 8010 kWh
I charge 20 kWh, drive around and loose 8 kWh, recharge another 15 kWh. The “accumulated charge”-variable should now be 8045 kWh, and completely ignore the -8 kWh.

What would be the best way to do this?

Thanks in advance!

Maybe a utility meter:

I’m not sure how it handles deceasing values if you don’t have it set to net metering though. Give it a try and see what happens.