Combine open and close notification from contact sensor if they happen back to back

Currently, I have my Hubitat sending me a notification when a contact sensor on a door is open and when it is closed. The problem is, I get constant back to back notifications every time the door is open and then immediately closed.

What I would like to do is have a single notification go out letting me know the door was opened and then closed if the open and closed event happen within a 5 second period of time, otherwise, I would like to get notifications from both individual events.

I know there are probably several ways to tackle this problem, but what is the simplest way to go about it?

Update: I got it working. This is how I did it

  1. I created a boolean Hub Variable 'FrontDoorOpen' and gave it a connector type of switch.
  2. I created a Front Door Opened rule that triggers when the contact sensor is open and sets the FrontDoorOpen variable to true.
  3. I created a Front Door Opened Notification rule that triggers when the FrontDoorOpen variable has been set to true for 5 seconds and then sends me a notification that the front door was opened. It then sets the FrontDoorOpen variable to false.
  4. I created a Front Door Closed rule that triggers when the contact sensor is closed. It then either sends me a front door was opened and then closed notification if the FrontDoorOpen variable is set to true or just a front door was closed notification if the FrontDoorOpen variable is set to false. It then sets the FrontDoorOpen variable to false.

I wish there was a way to put multiple rules in a group and treat them as a set.

What are you using now? The Notifications app? If so, many binary sensor options have a "for how long?" option you can fill in, though I haven't tested a contact sensor specifically...

Rule Machine, of course, can also do this, just a bit more work to set the whole thing up.

Here's an option that should work in one rule

Trigger Events
Front Door contact opened

Actions to Run
Wait for elapsed time: --> 0:00:05
IF (Front Door contact is open) THEN
    Notify 'Front Door is opened'
    Wait for event: Front Door contact closed
    Notify 'Front Door is closed'
ELSE
    Notify 'Front Door was opened and closed'
END IF
3 Likes

Wow, this is great. I haven't dug too deep into the functionality of the Rule Machine yet. This example will help me consolidate a bunch of my rules.

You may be interested in this...