Energy: PV return to grid with variable pricing

In the next few days, my PV will finally be ready for use and will also return some kwhs to the grid.

The “returned energy” will be paid based on a variable rate (hourly).

I receive the paid price for the following day from a sensor (created by node-red which pulls the information via an API).
Preview:

How could I calculate the earnings from the returned energy and show it in the energy dashboard?

Thanks!