How do I restrict a rule based on time since another event?

I've got two sensors and a light switch I'm trying to automate:

  • A presence sensor that indicates whether my car is in my garage or not.
  • A Zooz ZSE41 contact sensor connected to the door that leads from my garage to my entryway.
  • A Inovelli Red Series (LZW31-SN) dimmer switch connected to the lights in my entryway.

I'd like to write a rule that turns on the lights in the entryway when the door between the garage and the entryway opens, but only if the following conditions are met:

  • It is between sunset and sunrise.
  • It has been less than 10 minutes since the car last entered the garage.

I've got everything except the last bullet implemented. I've got a "Basic Rule" that says when the contact sensor opens turn on the lights, with a time restriction so it only happens between sunset and sunrise. This was pretty straightforward and easy to implement.

The idea is that the rule only applies when I've just arrived home, but as currently implemented it can't distinguish whether I'm on my way out of the house or whether I'm on my way back into the house, so I'd like to further restrict the rule so it only applies within a few minutes of my returning home.

My question: What do people recommend to implement this rule?

I'm relatively new to Hubitat (and home automation in general), so I'm not sure of the best way to restrict a rule based on the time since another event occurred. The best I can think of is some setup that involves a variable, and maybe three rules:

  • When the car is detected in the garage, set variable to true.
  • 10 minutes after the car is detected in the garage, set the variable to false.
  • A rule that checks the value of the variable, and only fires if the variable is true.

Are there any other recommendations? Is there a more built-in approach to combine the first two rules (i.e. have a single rule that sets a variable and then sets the variable back after a few minutes)?

I was poking around and saw that you can have variables that store dates and times, but I couldn't tell if there was a way to do math on dates/times, for example: If date is more than 10 minutes past the date/time stored in this variable.

This is harder to do right now than it will be in the upcoming 2.3.1 release, now in beta testing.

In Rule Machine, there is a condition called Time Since Event. In the new release this can be selected for time since a very specific event, such as 'car arrives'.

The trigger for this rule would be that door opens. It would have a Required Expression that it be Between Sunset and Sunrise.

The very first action of the rule would be to check the Time Since Event for the car arriving, and only if it is less than 10 minutes, turn on the lights.

1 Like

Thanks! I think I've got it. I added an additional required expression that the car actually be in the garage, but it is looking good (to me).

How does this look?

1 Like