Power / heating load balancing full automation (solved with pyscript)

Hello,
after enjoying several blackout while failing to create a reliable load balancing with HA automation, I have moved to pyscrypt and created a working solution which might interest other people.

The need
I have restored a flat in an old building where available electricity power is restricted to 6kW on a single phase. Changing that old configuration would cost a lot (rewiring the feed over 11 floors). As the flat isolation is now very good, I have replaced the gas heating system by electric radiators in order to reduce installation and maintenance cost.
The issue is that seven 1100W radiators, plus induction cooker, oven, washing machine, … can go up to more than 20kw at peak.
A serious load balancing solution was required to avoid blackout.

** Demo**
A demo video can be seen here:
powerLoadBalance-2023-03-15_13.05.34.ogg on Vimeo

The concept
I created 2 Python script using pyscript (see Installation β€” hacs-pyscript 1.3.3 documentation).
One (powersavingmode.py) is in charge of estimating the available power to heat the house and to set up a power_saving indicator which goes up from 0 (no saving) up to a user defined limit.
For each power saving level, corresponds a maximum number of active radiators. The last one being no heating.
The estimation is done by reading the power taken by the entire house reduced by the number of active radiator_energy.
The available power can only be an estimation, because radiators have their own embedded thermostat that I cannot control (even if set high). In order to live with an estimation rather that an actual value, the configuration allows for a safe factor.

The second script (roundrobin.py) scans the power_saving indicator and which radiators the thermostat(s) would like to be β€˜on’. With this information it will switch the actual radiators on and off in line with the available power. When all radiators cannot be on, it will distribute heat over the one desiring being on, using a roundrobin scan.

An Away mode switch allows to switch all heating to off and a booster mode allows to force radiator(s) to stay on assuming that enough power is available whatever is commanded by the thermostat or the roundrobin.

The limitation
If the safe factor is to high, max possible heating is never achieved, if it’s too low blackout will quickly happen.
Log and a dedicated reporting state variable are here to help to define the right compromise.
The good news is: less radiators on, the more accurate is the estimation, so the system works surprisingly well during power surge.
The time to react before a blackout is short, so your overall energy reading must be fast (every second). Forget anything reported over the net by your provider. You need a direct reading.

Playing with power
The system play with high energy and must be electricity safe. Such level of energy, if miss managed, can start a fire in less than a minute. Best and safer is to control your radiator indirectly (e.g. by control wire). The reaction to a stop request must be fast. I use the control wire with a diode to force a stop rather than requesting a comfort mode setting which can be done without a diode.
Note: Your radiator control wires must be powered with the same live and neutral wire than the actual heating electric feed. If you use an APS for your HA system and relays carefully think about the right wiring.

My code
My code is available under Apache License V2 on github.

Bug and feature request
Please report any issue on github.

My hardware



2 Likes