Hot water with PV system

Hello,

How can you implement an automation that controls a three-phase heating element depending on the power of the PV system.

A 4.5kW (3x1.5kW) heating element is to be installed in the domestic hot water boiler.
As soon as the PV system has a power surplus of 1550W, one phase should be switched, the surplus is 3050W for the second phase, and at 4650W all phases should be switched.

If the excess electricity drops, the heating strands should be switched off depending on the output.
As soon as the target temperature is reached, everything should be switched off.

I have the following entities:
sensor.grid_active_power = PV excess power (feed-in power)
switch.bww-st_1 = 1st heating coil
swtich.bww-st_2 = 2nd heating coil
switch.bww-st_3 = 3rd heating coil
sensor.bww = temperature sensor

My goal would be an automation that does the switching on and off, if I split it it works.

Is there a ready-made blueprint for this?

Greetings Gerald

Did you make any progress on this? I would like to do the same thing (with 3x2kW elements), with the addition of two more DPDT relays, which allow me to connect heating elements in series (the neutral star point of the heating elements can be separated). That means I can select 667W, 1kW, 2kW, 3kW, 4kW and 6kW, which should be granular enough so I don’t need any other means of element control, like phase angle or burst control.
Essentially this:

The electrical/electronic part isn’t the problem, but I just don’t know where to even start in Home Assistant. What hardware do you use to control the heating elements (or rather the relays that control the heating elements)? Is it an ESP32? Some commercial controller? Did you need to write your own integration?