Logic in Rule Machine

Let me know if you think Rule Machine is not the best app for this.

I have a lock and contact sensor on a walk-through door in the garage. If that door or lock is open at 7 PM or if the state changes between 7 PM - 6:45 AM I want to send a notification to my phone and log it to a file.

I think I have the action part figured out. Now I am struggling with the triggers and required expressions.

This would alert me at 7 PM or Lock or Contact change during my timeframe but only if the Contact is open or the Lock is unlocked so I would miss the notification if the door is closed or locked.

Do I need to split this into two rules or can one rule cover it?

The easiest thing to do would be to split this out into two separate rules.

Rule 1

Trigger: Time is 7:00 PM

Actions to run:

IF (Garage person door is open) THEN
  Notify: "Garage person door is open."

Rule 2:

Required expression: Time between 7:00 PM and 6:45 AM

Trigger events: Garage person door *changed*

Actions to run:

Notify: "%device% is %value%"

That being said, if you wanted this all in one rule for some reason, what you have above should more or less work. You have a duplicate trigger event that I'd recommend removing (the second or third), and your actions to run would need to be a little different (to account for the 7 PM thing vs. door events within the rest of the time), but you can probably figure that part out. The Notifications app could also work for the second setup rather than Rule Machine--just add a restriction.

I think the "duplicate" is the door and the lock - both named the same.

My take, however, is that the Required Expression "door unlocked" will end up filtering so you get the undesired events, when the door changes to locked. Likewise with open/closed, as these are evaluated with the state as the event happens.

I'd remove those from the Required Expressions, and update your triggers simply to door opens and door unlocked

This is correct. With the required expression and trigger setup you have, this rule will only run when the door status changes from closed to open or unlocked to locked. The other changes will not trigger the rule because the required expression checks the initial condition of the device... at least that's what I read somewhere.

Thanks. I have split it into a rule that triggers at 7 PM if it is open or unlocked and two notifications to check for the status to change between 7 PM - 6:45 AM.

Download the Hubitat app