Rules after power outage

Hello Friends,
I’m using OpenHAB 3.1 on Raspberry Pi 4 4GB running Raspberry Pi OS.
I have a question concerning rules.

Is there a way to make sure rules continue after a power outage?
I have a Zwave wall switch that I use to control a water boiler.
For that switch I set up an OpenHAB rule to automatically turn off the switch after 1 hour.

However, if, by chance, there is a power outage while the water boiler is set to ON and the rule is timing the auto shutoff, after the power comes back the switch will still be ON, but the rule timer would be reset and will not send the OFF command.

Is there a way to continue the rule after the power outage from it’s time state prior the outage?
If not, is there a way to automatically send an OFF command to particular devices after OpenHAB reboots from a power outage?

This way I’m not stuck with a water boiler that inadvertently works for hours.

hope someone can help.

There are ‘system started’ rules triggers. All a rule then has to do is examine the heater to see if it is ON, and if so set up a timer, half-hour or hour, to turn it OFF. It’s not like remembering unexpired time across the outage, as its only a precaution.

Harder to do is to ensure your system restarts properly.

Does the water boiler really resume after a power outage?

1 Like

Hi @rossko57 ,
Thank you for your answer.
The zwave switch I use to control the water boiler resumes its previous state after an outage. This behavior is not related to OpenHAB, it’s just how the switch is setup from the factory.
So if the switch was ON before an outage, when the power returns, the switch returns to ON state. If the switch was OFF prior to an outage, when the power returns the switch returns to the OFF state.

Another way to approach this that gets around any issues where the external device has not yet reported state when ‘system started’ rules run (so the rule cannot determine if it is ON).
Make sure the Item is excluded from any persist/restore-on-startup. (There’s not much point in that here anyway). Then you can add a second rule trigger for NULL to ON change event, which is what a “late” device report would look like.

1 Like

Another way I could think of would be to store the remaining time as an item. This gives you the opportunity to show the remaining time in the UI and to restore the remaining time on Startup via the persistence Provider.

The code however would need to be changed. I use this pattern to switch off lights after a certain time. I use a rule that starts a one minute timer to reduce the remaining time every minute until it is zero and then switch off the light.

1 Like

As you are seeing there:

  • is no way to continue a rule when the system restarts
  • are many ways to handle you use case in other ways.

Yet another would be to have a rule that triggers when the Switch changes to ON (maybe received command ON would be better but it’s not clear if the switch behaves like that). In that rule update a DateTime Item that is configured with restoreOnStartup with the time where you want to turn the switch off.

In another rule that triggers on changes to that DateTime Item and at System Started (or is in the UI System reaches a runlevel) create a timer to go off at the DateTime Item’s time to turn off the switch.

That way any time that passed while OH was offline would still be accounted for. If that DateTime is in the past, the Timer should expire and run immediately so if more than an hour has passed while OH was offline the switch will immediately be turned off.


Yeah that’s even better of course. I did not design my pattern with power outages in mind

1 Like

Thanks everyone. I appreciate your feedback and will try to implement in my system.

For water boiler another variant that I use that is not impacted by a restart is to control my boiler based on temperature and a state engine.

The water heater is only on for as long as it takes to heat to a target temperature and only between certain events. The state engine is based on @rlkoshak time of day but all of the triggers are not times of day.

I’m really happy to see someone use that example for what it was intended, as an example to build upon, instead of just copying it as is. :smiley:


@rlkoshak it is a good basis for many things.

Many thanks for the inspiration and all of your work.

Thank you all :pray:
I think I managed to achieve my goal by creating a rule to automatically change the Water Boiler’s Item state to OFF, when the Water Boiler Thing state is updated to ONLINE.

If anyone has a suggestion about my solution, or reasons I shouldn’t use this method, I would highly appreciate your knowledge :pray:

What happens if your Thing goes online before your rules are ready? (This is routine during boot up)

1 Like

I tested the rule twice and it worked ok after rebooting the Raspberry Pi.
It took about 2.5 minutes from boot for the Water Boiler Item to switch OFF, but it worked.
Do you think there might be occasions my Rules might not load before my zwave Things turns ONLINE after a reboot?

Yes. The design intention is to have the Things and Items infrastructure up and running before rules become active.
Of course, that doesn’t always happen because we can’t control external technologies and devices, which can “check in” at any random time.

Have to say I’m not sure why you’re fiddling around with Things, the Item represents what you really want to know. Maybe it’s to avoid persistence configuring.

Does the zwave switch not have a parameter to define what state it should resume to off after a power interruption if that is what you want to achieve?

1 Like

Water heaters are no joke are you just turning the control system on that came with the heater or is a grow your own?

What turns the heater on?

1 Like

Unfortunately, no.
The switch comes pre-set from the factory to resume the last state the device was in prior to an outage.

Yup. It’s not safe to let a water boiler run for hours. That’s why I’m looking for a solution to automatically disable it after an outage.
The boiler itself is not a “smart” device. I have it connected to a zwave wall switch that controls when the device turns on/off based on specific hours in the day.

If using a persistence configuration would be better, I would like to use it.
The problem is, I don’t know how to set it up.
I’m quite a noob in this matter.