Chart data history consolidation

I have a device outputs a single value that gets logged every 5 minutes. I don't want to store that massive amount of data over a year so want to average it out over different time periods.

Something like once I have over an hours' worth of data (12x data points) the previous hour gets averaged into a single value for the hour.

Then at the end of the day, the previous day is averaged, so the data stored is now daily, 23 hours, and 12x 5 minute values.

You sometimes see this sort of thing in historical resource graph (vCenter was a good example of this).

Does anyone have a script, node or flow that will do this?

Thanks

If you use influxdb then you can store the most recent data and can define Retention Policies and Continuous Queries to automatically downsample the data for longer term storage.