Create template to sum power usage between two dates

Hi community, may you lease help me in doing a template that calculate the average between a specificic date and now?
And if I want two sum two sensors and make the daily average between that specific date and now?

Template-based sensor do not have access to previous values. You would need to use a SQL sensor to access the database.