Add constraints to Rule Machine

Hey everyone,

I've tried searching how to accomplish my goal, but still unable to figure it out. So if this is posted elsewhere I apologize and would appreciate being pointed in the right direction.

Here's the deal:

I have a conditional action that turns my lights on when the front door opens if the lights are off. However, if the lights are on and the front door opens it turns them off (one with a 3-minute delay). I would like to add a constraint so that if the door opens a second time in under a set time (3 minutes) this will cancel previous actions and revert to the state before the trigger (door opening).

This is all done with a conditional action in Rule Machine as well as a contact sensor on the door and some smart lights.

Below is a screenshot of the rule I described above.

TIA, Rhis

First, I'd recommend reading the Rule 4.0 docs. There's nothing glaringly wrong with your rule, but there are some oddities (a do-nothing "Exit Rule," for example) that probably wouldn't be there if you had seen more examples and based yours off one of them. I know it sounds boring, but it's good reading. :slight_smile: A lot of that doc is geared towards Rule 3.0 upgraders, so you can ignore that, but the examples are good.

For your specific rule, it might be easier to think of if you did something like this. I might be wrong, but it doesn't look like you have a reason to check whether the lights are on or off since you're turning them all on or off anyway:

IF (Front Door Sensor open) THEN
  Off: Bed Light, Couch Light
  Off: Ceiling Lights ---> delayed 0:03:00 (cancelable)
ELSE
  Cancel Delayed Actions
  On: Ceiling Lights, Bed Light, Couch Light
END-IF

This solves a few issues:

  • Notably, the "Cancel Delayed Actions" step here is what makes the "cancelable?" flag on your delayed "Off" action do anything. If the sensor closes, that delay is now cancelled. I think that answers your big question.
  • Less clicking: contact sensors have only two states, opeen or closed. The ELSE will cover anything not matched by the IF. Sine the IF catches when it's open, the ELSE will catch when it's closed. (I eliminated the lights from consideration here, so if I missed something and you did have a reason to include them, you may actually need an ELSE-IF.)
  • Any IF THEN (non-simple conditional) should be politely closed with an END-IF, which I did (technically doesn't matter for you since it's the last action and RM would infer it, but it's a good habit and would matter if you had more actions afterwards)

However, it ignores the question about restoring the states. I'm not 100% sure what your goal there is, but Rule Machine does have "Capture" and "Restore" actions you can use on bulbs, which might suit your needs here (it behaves in more or less expected ways with on/off devices; some people find its behavior with level or color odd if those are manipulated between the capture and restore, though that's more or less a function of how most of these devices and their drivers work).

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.