Rule for closet door

I have a door contact on my sliding closet doors. What I’m trying to do is setup a rule for lights to turn the on once the closet doors are open and then turn off once the closet door closes the 2nd time.

Perhaps I am missing something in your problem description. Wouldn’t a Simple Automation app, similar to the one I have on all of our closet doors with recessed door sensors, work?

He doesn’t want the lights to turn off the first time the closet door is shut (because the closet is occupied). Hence the need to turn the lights off only when the door is shut for a second time.

I have the sliding doors that auto close, so I need the rule to turn off the lights once the door reads closed the second time.

1 Like

Ok, well, I believe that a reliable solution then might require a motion sensor in the closet. Otherwise, whatever state machine you design with a rule can eventually lose track of the number of door open/closes. It might work for a while, but will eventually mess up.

1 Like

I was hoping there was an easier solution but thats what I was thinking. Thank you

Well, I think it might be possible.

Edit: I think this does it. Note that the ELSE-IF is only executed on each close, and the last two actions are only executed on the second close.

Use a variable as a counter for door open events,
i.e. increment this variable when door opens.
Check this variable when door closes.
If variable is equal to the desired number of evens
reset it to 0 and turn light off.
(I am sorry but I am too lazy to write an example rule.)

I agree, that’s a simpler approach.

It does assume, though, that the contact sensor is fully debounced and doesn’t do multiple opens between each close. What your algorithm does is turn the light off on the first close after two opens, and assumes that there Is a close following every open. That’s not quite the same as turning the light off on the second close.

1 Like

Thank you guys, I’m going to give this a try.

1 Like

I had a similar rule (on a bathroom door). FRUSTRATING!!!
I would enter bathroom - light goes on. Wife enters (while I'm in there), light goes off.
Or I would be busy in there, telephone rings, i open door and answer phone, go back in and close the door behind me - light turns off...

I changed the rule to turn the light on when contact opens and turn it off 10 minutes after contact closes. That worked fine - but the light burning for 10 minutes after I left the room drove me crazy.

I then added a motion sensor as @672southmain suggests. Never looked back since...


For Buthroom this simple counter will not work.
I have few MSs and even toilet lid status detection.
But for the closet it may work.
Also I would add a timeout protection for the case
when door opens only once.

Exit rule statement is redundant. Rule will exit automatically.

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