Custom long term statistics in entity as 2D array

Dear all,
so I want a heatmap plot: sun azumith, elevation and then the max power I got via solar panels. This works perfect as you can see here: Plot Example Except, each time the plot loads, I need to load historic data and actually I want to load data form the last year. This is so inefficient…

The core of this is a 2D array, which holds the max power values.

So, how can I write an automation, that loads this existing array, including the sensor data azimuth, elevation and power, so that I can do the processing of the data from the last 2 hours and write back the array to the entity.

From there, plotting will be probably be a piece of cake.