Elapsed Time Since Event

Losing my mind. Two scenarios:

First is theoretically simple. I want to be able to trigger an event (contact sensor or button) that started an elapsed time counter that I can then display on a dashboard.

Example use: I have 2 litter boxes. I want to trigger event when both lids are removed to indicate cleaning. Then display the elapsed time on a tile to show how long since they were cleaned.

I was looking at the Hub Variables and Connectors and have made an elapsedTime variable and associated connector and set it to start with the time I created it. I think I saw how to trigger the connector to set the time to the time when triggered, but Now how do I get an attribute in the connector to show some form of currentTime-triggerTime? If it’s an attribute then I can display on dash.

Second elapsedTime issue which I think if I knew the answer to the above it wouldn’t be an issue.

Our presence sensors (phone app, Life360 etc) never work correctly and consistently so I put a button next to each door to trigger a shift into away mode. Set rule to kill lights with a delay and to set an elapsedawayTime variable to the button press. Ok.

Now I want to trigger a shift into Day/Evening/Night mode when the door contact sensors trigger as opened but ONLY if the away mode has been set for more than say 5 minutes. That way if we forget something and come back in the lights don’t all go out on us etc.

I know a wait in the Away rule would kill the process if I set it correctly but I’m not sure I want that. Typing this I just thought of another way of dealing with it possibly but I still want to know how to set a rule that only triggers IF X amount of time has elapsed from an event.


1 Like

I haven't tried this, just know that it exists:

I use a series of rules for the litter box.

I use a button we press when the litter boxes are cleaned. Then I have a rule that triggers every day at the time of the cleaning to count the number of days. Both the clean time and number of days since cleaning are stored in a hub variable. No need for any fancy math I just increase a counter every 24 hours.

I have another rule that makes an announcement through all the Echos in the house every day at 10:00am, once it goes more than 2 days and another rule that makes an announcement every time someone walks in the laundry room, that is where the litter boxes are.

1 Like

@672southmain is there somewhere that explains being able to use things like time() like you have in the rule? Those kinds of “shortcuts” (I’m blanking on the programming nomenclature) are one of the things I’m never sure where can be used and exactly how. Nor am I sure which ones. Is it a factor of the use of groovy? Different language? Something Hubitat just added in for our use (if so I’ve apparently missed the documentation)

I have also never seen anything on the use of math operators in the making of rules and would love to find out more about when and where it can be done but again I don’t know where to look.


The only built-in function that I use in the rule is now(). Everything else is local variables in the Rule, and you can see the local variables defined at the bottom of the screenshot. I use local variables to avoid namespace clash.

Whenever you are editing or adding a "Set Variable" action, an appropriate list of choices appears depending on the type of the variable. The "now()" item appears in the finished action when you choose "current time".

The Rule Machine 5.0 documentation can be found by clicking the "Documentation" link at the top of each of the forum pages. Here is the direct link to the Rule Machine 5.0 documentation: