Preventing overload: Dynamic device control based on energy usage

Hi everyone,

(If relevant, I’m using openHAB 4.1.2.)

Recently, I blew a 63A fuse in my house because too many high-power devices (heaters, car chargers, cooktop, etc.) were turned on simultaneously.

Now, to monitor house consumption, I bought an energy meter that provides real-time (well,
with a 10 seconds delay) power usage data. I’ve already set up a rule that sends an alert when consumption exceeds a certain threshold.

Now, I don’t want an alert, I want this stuff to work by itself.

I’d like to automate power management by turning off certain devices when a threshold is reached. Specifically, if the current exceeds 55A, the system should shut off devices in the following order (example):

  1. Spa heater
  2. Floor heater 1
  3. Floor heater 2
  4. Car charger
  5. Room heater 1
  6. Room heater 2
  7. Room heater 3
  8. Room heater 4

Additionally, if the load is above 40A, I want to prevent some items (probably a different list) from turning on automatically (for example, heaters that are turned on automatically based on the temperature). This is to be sure that manually operated devices (chargers, oven, cooktop, etc.) can still be used safely.

It it was a ‘programming language’, I would use some kind of ‘wrapper’ around each controllable item. This wrapper would:

  • Allow the item to be turned off externally (e.g., sending a command to turn off the car charger).
  • Prevent the item from turning on if certain conditions are met. (some rule sends a command to the item, however the wrapper prevents this item from turning on)

For the shutdown logic, I can write a rule that iterates over a predefined list (possibly a group, but I need it to be in a specific order), turning off devices one by one. It could wait 10–15 seconds after each shutdown and check if the current is still above the threshold before proceeding to the next device.

However, I have no idea how to implement the 40A “yellow” threshold rule, which prevents items from turning on without rewriting all the rules I have and introducing a complex logic to the system.

How can I achieve this in openHAB?
Any advice would be greatly appreciated!

Thanks!

If the devices you want to prevent turning on is automated using OH rules, it should be possible to add a Condition (“But only if”) to those rules that prevents them from running if the load is > 40A.

It gets tricky though if you want some priority between the devices, e.g. device A should be prioritized before device B, but B happened to turn on first, causing the load to exceed the threshold. That would probably be possible to solve, but require more complex logic. Can’t say more than that without knowing your specific requirements though.

Oh, yes. Thanks for the idea. I forgot about “but only if” as I was too concentrated on the items, not the things that control them.
I can add the condition “if switch PowerConsumptionWithinLimits is ON” to all the rules that control the temperature.
In this case

  • I can control the logic when to turn off this ‘control’ switch in one place.
  • I can easily override the logic and turn this switch permanently, if I need to get rid of it.
    I don’t think prioritizing this devices is necessary as if the high limit reached, the system will start to shutdown everything else.

Depending on the how all these are controlled and the full extent to which you want to make sure they cannot turn on there are several other approaches you can pursue.

If you just need to keep rules from turning stuff ON @pacive has probably the best approach. You could also have a rule that disables/enables these rules instead of using the rule condition. That could be a little easier to maintain since all the logic is in one place instead of spread across a bunch of rules.

If you also want to disable being able to manually turn then ON from the UI things get a little more complicated. The most straight forward would probably be to create proxy Items and a rule that only forwards commands to these proxy Items to the linked Item when the limits Item is ON.

You might be able to do something cleaver using a Script profile instead. For example:

JS: | (items.PowerConsumptionWithinLimits.state == ON) ? input : items.CurrentItemName.state

That’s not foolproof though and probably needs a bunch of error checking and dealing with edge cases. And the Items will still receive a command, they just will be commanded with the current state of the Item.

You’ll probably want a rule to turn stuff off automatically when the limit Item goes to OFF. Be careful of timing here if you use either of these approaches as that OFF command may be blocked too. So make sure to turn off the devices first before setting the liimits Item to OFF.

Thank you for your input.
That’s a great concept - enabling and disabling rules helps separate the logic without adding more conditions to the original rules.

Also, do you know if it’s possible to enable/disable rules using Tags? That would be even better!

As for proxy items - yes, I did not find any other solutions rather than separating current logic from using UI or physical switches.

Not through the helper library. The raw Java API Rule registry I think supports a getRulesWithTags() and getAllRules() which could then be filtered down to specific rules. I think you can access the role registry through rules. But you’ll be dealing with the raw Java so will need to look to the Java doc for details.