Rules Machine capture bulb state and restore

I am trying to set a rule that turns a bulb red when a contact sensor is open and rest the bulb to the status it was in before it turned red when the contact is closed.

I have one rule to capture the state of my RopeLights but struggling to figure out the Restore bit

Hi @Zamily84. The command is Restore.
So it would be Restore: RopeLights with whatever delay you want the light to stay red.
Here is my rule. I have used a local variable (DoorOpen) in case my door is opened twice within the 8 second delay time.
image

Thanks @Wounded
So would I use one rule that manages open and close? Or two seperate rules, one for open one for close?

As an addition to the above, note that if the bulb was off before you started, the "Restore" action will only restore the on/off state (and that much will be correct). But if you turn it on in the future by issuing a plain "on" command, it will return to red (or whatever its last state was--red if this rule was the last thing that touched it) unless you explicitly turn it on by setting color or CT or something instead. This can be confusing, but it's more or less a result of the way most bulbs work, and the capture/restore actions are designed around that (and are indeed accurate in terms of visibly restoring the old state at the time of restore; it just might not be exactly like nothing happened in the meantime in future automations). Someone was once so confused by this that two or three threads were started for the same issue, and I wrote a rule that accommodated this behavior by adding a bit of a manual element on top of the capture/restore if this is a concern for you: [SOLVED] Community Rocks!

Since I'm here already, I'll take a stab at your other question, too. :slight_smile: I'd use a "Front door changed" trigger ("changed" instead of "opened"), so the rule would look like:

Trigger: Contact *changed*

Actions:

IF (Front door open) THEN
  // capture, turn on, etc.
ELSE
  // restore or turn off, etc.
END-IF

...filling in what you actually want, of course. This is similar to motion-lighting examples you can find in the Rule 4.0 docs, which I'd recommend reading. Lately, staff have been suggesting a paradigm ike this instead:

Trigger: Contact opened

Actions:

// Capture, turn on, etc.
Wait for event: contact closed
// Restore or turn off, etc.

Either should produce the same outcome.

1 Like

worked great.. Thank You!

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