Single rule to turn on and off lights based on action

Hello, I'm new to this group so forgive me if my question sounds odd, or maybe there's an easier way to perform it. My kids have a their play area in the basement. They will open the door and shut the door behind them immediately to keep the cat out. Rule to turn the lights on when the door is open is fine, but I don't have a rule to turn off the lights, since closing the door would just leave them in the dark basement (creepy).

I want to have a rule that does this, but can't wrap my head around the login.

  • Open door, turns basement lights on.
  • Close door, do nothing for now.

If they open and shut the door twice is rapid succession (under 5 seconds), then I want that to trigger a lights out. Since this would be a deliberate action to trigger the lights out.

I'm been trying to use the wait condition with timeouts, but don't think 'm doing it right.

Alternatively, maybe a basic rule that just turns the light on, and a Rule Machine rule to recognize the open close sequence. Any help would be appreciated. Thanks.

This is commonly discussed under different headings, but comes back to room presence. Common examples also include bathroom presence or when is someone taking a shower.

You are right that to use the contact sensor alone it is almost impossible to reliably determine when the room becomes vacant, you could even throw in the situation of you coming down to check on them as an added xompkexity.

My suggestion would be continue to use the contact sensor to turn the lights on, then use a motion sensor to keep them on or some other detection mechanism. You may even use a combination of the motion sensor and contact sensor for this purpose.

Oh, and welcome aboard :slightly_smiling_face:

3 Likes

I agree with @sburke781 - the best way to do this is to use Room Lighting and a combination of contact and motion sensors.

2 Likes

Welcome to Hubitat!

Just an initial thought or two.

  • I would do two rules. It will be much easier to set up, at least for now. The on part via Basic Rules would be the easiest.

  • Why not a motion sensor, you could do that plus door status to get a better idea of occupancy. (sburke781 beat me to that, typing slow here) but I will second that suggestion.

  • Alternatively, a button would be a great way to turn the light on and off or determine presence.

  • Overall, the two rapid closing sequence would have to be near exact to get this to run. It is going to be frustrating for users.

3 Likes

In addition to @sburke781's suggestions, take a look at the new "room lighting" app. Though the door double-tap logic definitely won't be in there, it's a great app for working with lights, contact sensors, and motion sensors.

If you want to do the double-tap thing it can be done with RM but it would take a fair amount of playing around to get it to work reliably. I think I would try using a variable that counts the number of times the door has been opened and closed within 5 seconds, and when it hits two, turn out the lights and reset the variable. But there might be a more elegant way, too.

3 Likes

Thanks for the quick responses. I think occupancy sensors will be my last resort if this doesn't work. Sometimes they read very still or hide inside spaces so the light would turn off and freak them out and they'll never want to go down again. I like brad5's suggestion with the variable count option. I'll have to play around with it.

For now, I'll stick to a basic rule to turn the lights on, then figure out how to incorporate a counter to manage the double tap to close door.

This is a concept we generally refer to as WAF* or SPAF*... low WAF or SPAF is the number one killer of home automation projects.

(Wife/Spouse/Partner Acceptance Factor)

2 Likes

I hate that term, not just for home automation purposes, but in general. Every time someone comes up with a silly excuse why they can't do something, or how things aren't working right, they blame it on the spouse/kids. Example: "I painted the bathroom purple and now WAF is at an all time low".

1 Like

Try this... I think it comes close to doing what you want. I managed to do it with a lot less aggravation than I anticipated!

If I'm following this correctly, it might now work. Because the timeout would just result in the rule executing after 5 seconds, even if the door wasn't re-opened or closed. But I think i'm getting the idea. I think I'm close to a solution. Will share once it's working...

Nevermind. Flaw in my logic. Gimme a few.

I think this one should work better. The required expression means the rule will only run if the light is already on. If it is on, and the door closes, the rule is triggered. It will then wait for another open indefinitely. Once the open comes, it waits either for the contact sensor to be closed or the 5 second timer to time out. The last conditional makes sure the door really did close within that 5 seconds, and if it did, it shuts off the light.

OK thanks everybody for the feedback. Here's the winner. Looks like I just placed an if condition to check to see if the door has opened in a loop that repeats every second, 5 times. Pretty proud of myself for a n00b.