Create template sensor for changes in the current hour only

I have energy producers (PV,grid) and consumers (EV, house,grid) as accumulating sensors (kWh) (they are present as immediate power values (W) as well).
I need to make a running tally within the current hour of the changes (as we are billed/reimbursed by the grid import/export) for each full hour. I would like to control my EV charging to “use up” any positive energy export (from the PV) before the hour ends (how I will do this is another story).
So: how can I start a sensor each hour (at XX:00) at zero (0) kwh and update it for each change to the accumulating sensor, to hold the diff of the accumulated sensor since the hour start (XX:00).
Something like: hour-sensor-value = sensor(at now) - sensor(at last full hour XX:00)
Thanks!

Use this with an hourly cycle in net consumption mode:

Feed it with a template sensor that calculates your net energy usage (export - import),

1 Like

Thank you for poiting med in this direction (I thought the Energy dashboard was the only thing of such kind).
One question: is this sensor updated “live” in the hour (that is every 10s where my input is updated)? If not, I cant “soak up” the remaining exported enegy before the hour ends.

Template sensors update whenever the entities they use update. So every 10 seconds in our case.

1 Like

Thank you so much for this advice, I had an error in my template sensor so it didn’t update…
It’s working perfect now (and even found some more Helper sensor to use!)