Calculate amount of 'free' solar power that can be taken back from the grid at any time

You didn’t try my response here?

That’s a working example…

Hi there,
I would like to explore additional steps based on what was already discussed in this thread, but I’m very new to HA, just managed to get the integrations working but nothing more.

My solar installation is in Spain and I pay 20 cents/kWh while I sell it for 0.5 cent and I have no buffer, what is sent is “lost”. So I would like to run a sensing loop (automation?) that:

1/ calculates the “available” solar power for the house now.
2/ run through a sorted list of rooms in my house (different sorting based on time of the day) and check:

Case I: power is available and is sent back to the grid
a/ if the temperature or the humidity of the room is within range or not
b/ if not in range, if HVAC is off and if available power allows, start the HVAC in this room with the relevant mode (heat, cool, dry)
c/ if one HVAC was just started, stop there and leave for the next automation cycle, so that the HVAC has time to reach its consumption level before doing another pass
d/ if an HVAC was not started, move to the next room and loop to a/

Case II: power is not available and energy is consumed from the grid
go though the same list backwards and stop the least prioritised HVAC and reloop.

I have managed to get for each room a temp/hygro sensor entities, as well as a HVAC climate entity.
I have a sensor for the solar power and the grid power (in and out).

I just don’t have a clue where to start to make such programmatic automation. How to build a list of rooms for the morning (bedroom priority), and another for the afternoon (living room priority)?
How to use a list as a looping parameter in an automation?
How to have safety checks so that I don’t stop an HVAC that I just started in the previous iteration?
Is it via templates and automation? Is is better via NodeRed? Or maybe it needs a full programming language?
I’m lost, maybe it’s too ambitious?

thanks for any help to get me started!

Hello, thank you, i’m doing the same and i can calculate the “net energy”.
My problem is that i want to set this to the “back to grid” parameter in the energy dashboard but the sensor is not shown. can you help me? sure it’s some error on variable