Load balancing heaters to avoid overloading the fuse

I am quite new to HA and have an issue which I haven’t found a solution to. I have a cabin with limited electrical supply and I want to load balance the electric load. I have several panel heaters and a water heater that I can control through HA. I also have the realtime electric consumption in the house. I want to limit so that once the load go over 25A I want to turn off devices in a certain order. I want to use the following logic:

  1. If the load goes over 25A and all three devices (panel heater 1, panel heater 2, and water heater) are on: Turn off panel heater 1 or 2 (at random to prevent one of the rooms to always be the cold room)
  2. If the load goes over 25A and one of the panel heaters are off: Turn off both panel heaters.
  3. If the load goes over 25A and both the panel heaters are off: Turn off the water heater

Step 1, 2, and 3 needs to be carried out with e.g. a 15 seconds delay between each of them if the realtime consumption continues to stay above the threshold.

Similarly I would want to turn them on in the reverse order with some delays.

I could think of some ways to set this up with many different automations. However, I feel like there should be a more elegant way of solving this.

Anyone that has any recommendation on how to do this?

There’s amazingly little information about load balancing principles / algorithms anywhere on the internet.

Have you found any solution that is more elegant than a case-specific logic?

I’m thinking about putting heaters in a loop; to switch them on for 15 minutes, one at a time. More specifically, to swich on/off the thermostat entities which control the heaters.

I have just finished my load balancing for my heating system.
Having failed to do it via regular automations, I ended creating a python script using pyscript.
A great solution once you master the limitation of the implementation.
My code supports a dynamic allocation of power for a heating system. I use a round robin to distribute the available power to the radiators that are commanded to be ‘on’ by their thermostat.
I command the radiators via the control wire (fil pilot for French speakers) in order to avoid to manage switching on/off large electric energy.
You can have several radiators per thermostat by using the HA Helper Groups.
I have also implemented an AwayMode that stops the heating when the house is empty.

In my case the power limitation comes from the old wiring of the building that limits the power available to the meeter, so I use the instant energy consumption to control my Power Saving Mode variable. I will soon add the detection of the the washing machine and dish washer start.
The same variable could be controlled by other input (e.g. time of the day or activation of heavy equipment).
What I have not done is to manage different power weight for item. In my case I control radiators which are all of about the same power (1kW).
The attached photo, shows the electric wiring to which you must pay a serious attention.
My code is available on github