Automation - PV and thermal storage heaters

My essential question for tl;dr is: Hasn’t someone done this already?

Yes, I did google. But the only thing I find is the “PV Excess Control” on github, which doesn’t fit my needs.

I made a pictogram of the problem:

house setup

so: there’s this house with old thermal storage heaters and a brand-new PV array (11kWp), an inverter and a 6.6kWh battery.

Turns out, if you can use google and throw a lot of money at electicians, you can make a 40 year old box of bricks with a heating coil (that’s a thermal storage heaters for those who’re not from Europe) semi-intelligent, as in “there’s now three high-Voltage high-Ampere actuators I can switch on and off with my phone”.

The inverter also talks to my phone. And there’s a lot of stuff made in China that also talks to my phone, and I’ve managed to have all of that talk to my HA, which was the single cheapest part by large.

The heaters are switched in 3 groups, market in blue: (1) is the main living room “upstairs”, that will prevent the house from freezing in winter. 8kW, needs up to 5 hours of charging time at -20°. (2) is the study and the master bedroom, 3kW each, 4 hours a day. (3) is the downstairs studio and the hallway, none of which can freeze as the house is buildt into a mountain (the brownish squiggly line).

I’ve so far created 142 automations to make the house heat itself based on the fact that the sun peaks at noon and if someone is there or not, and already average 90% PV usage, but that’s not an “intelligent” solution.

I’ve made a decision tree:

The brown parts are what I want leftover. The green parts are already done. The blue parts are essentially the same graphic, again. I’m confident I can solve every single problem here by myself and create halb a billion automations so that, for the future, I only need to set the three brown variables, but since this is the internet: Hasn’t someone done that already and made a script that automates the creating process? And ideally, make it look nice in the end? I know I’m not the only one with that problem

Essentially, I need a really fancy DIY thermostat.