Limit peak energy usage

Hi all,

I’m working on a proof of concept to limit peak energy usage. (Reason: Off-grid battery capacity is limited to ±3000W but could also be useful since in Belgium we now get charged based on energy peaks.)

Ideal setup

  • Energy is monitored for every device
  • When the total energy used is higher then a specified value, devices should be turned off based on a priority list.
  • When the total energy is lower then a specified value, devices should be turned on again.

When I turn on the water heater, the electric shower boiler should turn off. When the water heater is done, the electric boiler can be turned on again.

Where I got so far

  • I connected 4 loads (Water heater, Microwave, Coffee machine, Dryer) to a Shelly Pro 4PM into HA.
  • I created a custom sensor “Shelly total power” combining the total power off all 4 devices.
  • I created an input number “Total available AC power” which is set to 2500W (will change this later based on Victron battery + solar sensors)
  • I created an automation when the “Shelly total power” sensor is higher than the “Total available AC power”, all relays are turned off.

My question
My next step would be to update the automation so that it automatically disables all devices using too much energy based on a priority list. The automation should also re-enable those devices when the device that triggered the initial shutdown stopped using power.

While I understand I can build this using lots of if/else statements. I wonder what the best approach is for my goal and how you guys would do it. How dynamic can I create this considering I might add up to 20 devices?

  • Can I add priorities to devices without hardcoding this with if/else?
  • Can I remember the device that was last turned on to give it temporarily a higher priority?

I’m an experienced developer but a HA beginner. Big fan so far btw.

Many thanks!

A few thoughts from another (former) dev…

I’ll be following your developments here for when I do a similar thing.

For your priority list, I think you could use an input select or input text helper by storing the entity IDs. The latter would need a bit more coding to parse it where you use it. Basically, you want something that respects order. You could also check whether groups respect the order in which entities are set.

For the memory part, you could just save the second last entity in a helper, but maybe what you want is to emulate a stack where you can push and pop.

A mutable stack might be overkill since I feel the order should be based on the average duration a device runs. E.g. from water kettle to washing machine. It doesn’t matter that the washing machine is turned off for 3 minutes (using water kettle) but it does matter if you can’t use the water kettle for 4 hours (washing).
I think this logic is applied to all devices: Water kettle > coffee machine > microwave > dryer > washing machine. However sometimes the washing machine only uses ±500W, while it’s state would still be “On”, it’s fine to combine it with the water heater (total ±2500W).
So I’m really looking for a ‘smart’ system. I guess I’ll need to improve my knowledge on what can be programmed in HA because the most automations I saw are pretty basic.

Ok, that’s fine, but sounds different from what I originally understood.

You said:


which is why I suggested some kind of stack.

I suppose, at a high level you need to decide between a proactive (prevention) vs a reactive approach. Given the runtime of some appliances (can’t really stop the dishwasher halfway), you can’t really interrupt it, so if you can forecast someone’s going to want to boil the kettle in the next 2 hours then don’t turn on the dishwasher in the first place.

Note that you can add any attribute you like to any entity via customize.yaml, so if you devise a scheme, e.g. labels “high”, “medium” and “low”, you can set it in an attribute called “energy_requirement” which you can then access in templates.

Have a look at this blueprint: