RM actions based on hub systemStart

Is there a way to base if/then statements in RM on last systemStart time?

The RM command I am trying to achieve is

IF last systemStart < 1:00:00 THEN cancel delayed actions

From Rule Machine, all you can do is subscribe to the systemStart event, which you could do by adding it as a trigger. I'm not really sure what your intent is with the pseudocode above (if the last system start happened before 1:00 AM? if the last system start was less than an hour ago?), nor am I sure why you'd want to do a "Cancel Delayed Actions" in that case, but this is one example of how you could effectively check whether the hub was restarted within the last hour. This uses a variable, but you could also use a virtual switch, Private Boolean on one or more rules (set from another rule, all assuming you aren't using PB for anything else in those rules), or lots of other things that might better suit your use case:

image

3 Likes

I am embattled with lock issues since switching to HE. Not 100% sure why, but this has been going on for months, have repeaters, USB extension cable for the stick/hub, they have helped but no silver bullet.

I'm getting close to victory with the help of Reliable Locks and Device Watchdog. I now have it to a point where the locks work fine until they drop off, and stop responding. When that happens a reboot fixes it immediately, and 100% of the time.

Using the apps above to refresh/monitor them, and then trigger a virtual switch if one stops responding.

I then have this rule setup in RM.

While testing it, I pulled the batteries of one unit so it stopped responding, and it worked. However I was off doing something else, and it rebooted every ten minutes (what I have the Watchdog refresh set for) until I replace the batteries, since the lock did not check in.

I want to limit that by using some kinda of timer (1 hour maybe more) between reboots.

Thank you for posting your idea, that helps get me started. I'm not great with RM so help from you gurus, and any other insights are always appreciated.

EDIT: With @bertabcd1234's helpful insight I think I have it worked out. I had to break it into 2 rules to get my head around it. If there's a better way anyone can feel free to interject.

Still having some minor issue with this rule. Here is what I have seen using the rules above.

Reboot this morning at 6:36am

delayed ended after 3+ hours?

The Rule for PB settings.

Rule after reboot for several hours. I think the (F) should be (T) right? Otherwise statement would be TRUE.

3+ hours later after the "delay" ends, shouldn't the (T) be (F)?

I rule works (aside from the extended delay), but it doesn;t seem right

also @bertabcd1234 how di you create the variable, and would it be better done that way insteed of PB?

Something seems a little odd there: the rule's PB should be set to True on (or shortly after) hub restart, then false an hour later. If you recently loaded or refreshed the rule, that is indeed what you should see with "T" or "F" next to this condition. Technically, if you reboot your hub more than once within an hour, that old "set PB to false" action will still be scheduled, which you could handle by adding a "Cancel Delayed Actions" action to the beginning of the first rule and choosing the "Cancel?" flag on your delayed action (the one that sets PB to false), but otherwise that shouldn't matter.

It looks like you have action logging turned on for this rule; if not, you could, and then see what the rule runs when. The variable in my rule above was technically a local variable I created for demonstration purposes because I was too lazy to create a global variable, but a global variable is what I'd do in your case (you can use that in any rule, and you'd need to if you set it it from one rule but check the value in another). Those can be created in the "parent" Rule Machine app, then actions in any rule can set them. However, the outcome should be the same as what you're doing with PB, so I can't imagine that making a difference here. :thinking:

1 Like

I switched it to GV and the IF statement at least make sense.

sysemState as a trigger does not seem to log any action on reboot. I turned on logging for everything and it does not display any results when rebooted. However it does change the GV from False to True. (maybe rule hit before logging starts?)

For testing I set the timer to 10 minutes and it seems to be working fine with GV in place of PB (and the rule action setting it back to false was logged). Not sure why it acts differently, but it works now. Prefer to use GV anyway, so I can set the name, and use it elsewhere as needed. Thanks