Closet light rule


So needing some assistance in this one. I have a linen closet with a light outside of it that I want to control with the closet door. I have a contact sensor on the door and can make it turn the light on or off with the door being opened or closed, easy enough in RM4. Here is what I would like it to do - if the light is off, turn light on when door opened, turn light off when door shut. If the light is already on when the door is opened, do nothing and do not turn the light off when the door shuts (basically the rule would not run).


Capture and Restore are your friend:

Trigger: Door **changed**

IF door open THEN
   Capture: Light
   On: Light
   Restore: Light

This will restore the light to the state as it was previously. If it was off, it will be turned off, if it was on, it will stay on


Or a condition on the whole rule that it only runs if the light is off. Because why would you run the rule if the light is on anyway.


That won't work because it won't turn the light off.

What you need to do is this.

Trigger:  Door Changed


If Door open
      If light on  
             Set PB to false
             Set PB to true
              turn on Light
       End if
Else If Door closed and PB True
       Turn off light


Ryan is right. Ignore my stupid reply. :joy:


This worked very well! I am liking this capture / restore functionality. I am slowly advancing my automation rules and once I have a certain set down, I start move to the next level of control. I set this up with a set dimmer per mode instead of just on, but works well. Thanks for all the suggestions!

I feel there should be wiki or repository of example RM rules, not only to help new users or people trying to learn RM, but also for ideas on how to implement.


I would love to have the ability to export or import rules. I do think there needs to be more examples of good vs failed rules in the documentation.


Maybe have a vote system as to whether community added examples work or not.

  • Option a works best
  • Option b works best

0 voters

Like this?


Well, each post already has a checkbox that the OP can use to identify if a post was the solution.

I really have a problem with a “voting system”. There is not one way to achieve the goal. Rule machine is powerful. And for some it might be more logical to go one way over another and neither way is wrong.
I think a short list of examples (as Bruce has done this in a post) is helpful. Maybe it could be more prominent on the wiki. But where should it stop? All of us have different use case, wishes and environment factors that we need to consider. We would all be using Simple Lighting if we all would need the same solution.

Again, I think a nice list of examples is good but don’t go too far, it can be more confusing in the end


I agree. I was thinking about the voting system, and the possibility of wrong votes due to user error and such. I think a list that has a description of what the rule does and is clickable to go to an example of the rule. I really like the idea of having more complex rule examples, as it opens up ideas for others, and helps teach RM logic. I am absolutely sure that I could be doing a lot more cool stuff with HE and RM, but I am learning as I go, and the ideas start to show up of things to try. I do read the forums a lot and look over what others ask questions about, but a "master list" of examples could be very useful.