Scheduled Events at hub start? Some may have been missed

I had a couple of RM legacy rules that I wanted to make changes to and instead of just editing I moved them to RM. I only want these rules to run between sunset+30 and sunrise-30.

I noticed when looking through my logs today that the rules were running in the middle of the day. The problem was, when I rebooted my hubs this morning to rollback the firmware it now reset all the predicates. I thought no big deal, I added a trigger to fire at system restart. With these rules that wasn't just a matter of adding a trigger, as the rules turned on outside lights. So I had to add something to exit the rule if the trigger was a restart.

This got me thinking anytime I reboot my hub all predicates are now invalid until the rule runs or I manually update them. I went and looked and found a couple other rules where the predicate should have been false but was not since the predicate was not re-evaluated at startup. There are probably more. It seems maybe an option to re-evaluate all predicates at startup would be handy. Without such an option I need to go back and look at all rules with predicates and re-evaluate it's usefulness.

Regarding predicates, they are constantly evaluated (well, more accurately, as I understand it, each time a potential trigger event fires). If, at that time, the predicate is true, the trigger happens and the rule fires. If, at that time, the predicate is false, the trigger event is dropped.

Bruce (@bravenel) discussed startup issues before, and, after a lot of thought, I came to understand and agree with his position.

If you think about it, with the variety of configurations of hubs, there's no way that a standard under-the-hood operation works for startup. You have to think about how you have your Rules designed, and just run through an appropriate set of actions in a systemStart rule. If you design the systemStart rule appropriately, it can handle the case of restart or reboot at any time of day.

For example, I do a refresh on all the Ring Extender Gen 2 devices because the "switch to mains from battery" event has probably been dropped if it's a reboot after extended whole home power fail. The Ring Extenders will come up before the Hub reboots. While the Hub is on a UPS, you really don't know in advance how long the power fail will be, and, at least in our city, the power may flap up and down several times while it is going down, and the same may happen when it comes back on. So, I've got a shutdown rule (triggered as Ring Extenders switch from mains to battery) that waits a few minutes before deciding to shut the hub down cleanly. In addition, occasionally someone (not me) might knock a Ring Extender out of the socket while cleaning or moving furniture. To handle this, I've got a voting rule that only starts the shutdown process when at least 5 of the 6 Ring Extenders have seen power failure, and which recovers when Ring Extenders come back online. If you think about the concurrency issues, designing such a set of rules is a bit complex because you can have multiple "fail / power up" triggers happening at near the same time. The only thing you can count on (hopefully) is that the events are queued in the order they occur. So, another thing my systemStart rule does is to initialize all the variables in this voting set of rules.

Another thing that my systemStart rule has to do is to get the Mode in the correct state. Basically, you have to run through all the ways that your Mode might be set.

Then, you have to replicate the actions, as you note, of turning lights, etc., on/off if they are controlled by time events or sunset/sunrise.

Then, I've got a complex set of rules that monitor our Litter Robot (controlled by Dominick Meglio's (@dman2306's excellent driver port)), turning the Under Vanity lights green, yellow, red depending on the level of litter in the Litter Robot drawer (using the concept outlined in Jared Zimmerman's (@jared.zimmerman's) post in the forum), and that starts flashing the Under Vanity lights when the Litter Drawer Full indicator is triggered. All of that state information has to be reset correctly because the cats might have been pooping while the power was off, etc.

I just don't see how this could be done any other way than have your systemStart rule make no assumptions and run down how your home should be configured on a restart or power up.

This is not true. Reboot does nothing to event subscriptions and scheduled jobs (other than missing a scheduled event that would have happened during reboot).

And, it does not affect in any way a rule's understanding of the state of the Predicate (which it maintains in state).

1 Like

Yep, but, because a reboot really isn't different from a power up restart, no assumptions can be made about which or whether scheduled events have been missed. I couldn't figure out any other way than just to make no assumptions and run a complete configuration of everything. Events may have been dropped, and there's just no way to know. But setting of lights, etc., based on time of day events, well, you just have to have appropriate tests in the systemStart, canceling appropriate rule actions (repeating rules, etc., and re-running the rule actions, etc.).

Yeah it seemed to be just the two timed predicate rule and one other. I went through my other rules and as you say seemed ok. So that could have been it, I may have just rebooted at the time of the event.

I know it's not officially supported, but I have a webCoRE piston that is scheduled to run every minute. It won't run after a reboot unless I "bump" the piston by hitting the test button or with a System Restart event trigger. It essentially does nothing when triggered except write to a log, but that's enough to schedule the 'execute every n minutes' part of the piston to run. It just needed a trigger to set it in motion.

webCore must not be scheduling it properly.

Well, yes, but user awareness helps! I know from long experience that if I update the hub while a Motion Lighting turn off is pending, one for a minute or two, odds are pretty good those lights won't turn off. On the other hand, scheduled events for outside that 3 minute window are still scheduled.

Imo, trying to chase startup events into complex things is a waste of time. I set the mode, and that's all. But, to each their own.

So this thread topic is misleading. These scheduling issues at reboot apply across the entire platform, with nothing special about Predicate rules at all.

Understood. But I was able to design a set of rules that works reliably for reboots or power up. I have gotten things to the point where I don’t have to fool with it. Power fails do happen to us occasionally, and my wife wants the home to come back up when I am away. The alternative is to rip out all the smart home stuff and return to dumb home.

I did put a question mark on it as I wasn't sure I was interrupting things correctly.

It was me though, when I first saw the post about rolling back I did a restore instead of a rollback. I then did the rollback. I had forgotten about that till I started looking though my logs trying to see if the timing of the reboot coincided with the event time. That explains why predicates were wrong, as they went back to the state of the restore.

Nevermind. :grimacing:

1 Like

So this happened again this weekend. This time it was due to a hub crash. For some reason my new C7 crashed sometime after midnight. When I woke up Sunday morning, I could not access the hub. This is the hub that I moved all my rules to. I did a reboot from the diagnostic page(8081).

The predicate on my outside lighting rule is from sunset to sunrise. Since the hub crashed after the expression became true the rule remained true at hub startup. I was walking back and forth from my shop to the house and I noticed the flood lights on both kept coming on. I had added a trigger to run the rule at startup, so it should have re-evaluated the predicate correct? Is a reboot from the 8081 page the same as a reboot from the settings page? The reboot was after sunrise, so the required expression should have re-envaulted to false?

See rule below.