after a power outage I came up with some questions to myself:
How to verify that the rules — which were missed — need to run after a power outage?
Challenges:
Rules triggered by time (cron/scheduler-based) will simply not run during a power outage.
Rules triggered by item updates/changes will also be missed if the update happens while OpenHAB is down.
one idea would be to use a timestamp for each scheduled rule and check after startup, then trigger the rule by a dedicated rule-switch - that could work for time triggered rules.
regarding whether important items changed state while OpenHAB was offline, I though about a re-trigger logic running after system startup.
Therefore I would use a Group to track important items, and persist their state before shutdown.
On startup, compare current state vs. last persisted state. If different, then toggle a dedicated rule switch
What would be a creative way to find all the (important) rules which were missed? Are there better ideas or solutions out there?
When OH first comes up, for those technologies that support it, OH will request the current state of the service. So OH will reflect the most recent information available about your devices. There’s no need to do anything special for those. Of course any state changes that happens while OH was offline are gone, but there’s really nothing you can do about that anyway. If the technology doesn’t support that, there’s nothing you can do but wait anyway.
For rules you have several options.
Just run them every time OH starts. You can add some logic to make sure anything needs to be done in the rule. What that is will depend on the rule.
Run the rule every x minutes all day long. Again, add some logic to see if anything needs to be done before doing anything.
Do nothing. If OH was down, that rule doesn’t run today or it will run when ever the items that normally trigger it change our are updated.
If you have rules that are this critical, you should do everything you can to keep OH running 24/7. When it does go offline it’s because you are doing maintenance in which case you can manually run the rules that need to be run when you are done, or something very big that impacts the whole house has happened, like a power outage. In that case, OH almost certainly didn’t miss any events (except time based ones) because everything was offline. And it may not be appropriate to run the rules that should have run while OH was offline anyway.
Ideally, you should avoid these sorts of rules as much as possible.
But I do have one example I can share. I use Time Based State Machine [4.0.0.0;4.9.9.9] - #130 by brianlay to control all the time based rules in my home. This rule triggers at system started and at midnight. It creates timers and commands a TimeOfDay Item with the current time of day (e g MORNING). When the rule runs, it calculates the current time if day and if that’s different from TimeOfDay’s state it commands that with the current state. So even if TimeOfDay should have changed while OH was off, it will change as soon as OH comes back online.
All the time based rules trigger off of changes to TomeOfDay. So, if OH was offline when time changes from MORNING to AFTERNOON to EVENING, when OH comes back out will trigger all the EVENING rules.