Solar PV revenue calculation

Hi

I need a bit of guidance. Tried my best, and with some OpenAI help, but never got this one solved.

I would like to create a template that hourly calculates my revenue from solar PV sales. I have all the entities to make this happen, it is done easily in the energy dashboard, but i would like to have a utility meter summing up my sales, so track my return of investment. I would also like to create a saved electricity bill sum, in the same way. I have made templates that calculate my saved energy purchase. I have entities providing me sales price and consumption price. So i got the data, but not the skills.

Sold electricity: sensor.nr_tvedevej_12_power_returned
Price of sol electricity: sensor.energi_data_service_salg

First task would be to create a utility meter with an hourly cycle. Easy done: sensor.cerius_elsalg_denne_time

My challenge is now is to multiply the value of sensor.cerius_elsalg_denne_time with sensor.energi_data_service_salg at the 59 minute and 59 second moment every hour to calculate the revenue from that hour. And ad this to a total sum of revenue.

Any ideas ?

Regards Tommy