Add constraints to Rule Machine

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