Making a counter from a sensor value

Hi,

I am trying to make a counter for a photovoltaic installation.

The entity from pvoutput provides the amount of kwh produced at the end of the day. I would like to have a counter that adds that value to itself every evening.

I have been reading quite a bit, but can’t seem to get it right. And does the code go into the automations or the sensor file?