Using Motion Sensor to turn on a light, and contact sensor to turn off a light after door is opened

Yes, but.

With motion lighting you would setup a motion time out period. So if your motion sensor goes active and 30 secs later goes inactive you would setup a timeout in motion lighting of 5 mins or so. If motion becomes active again inside of that 5 mins the timer will get reset for another 5 mins. The lights will only turn off after the timeout period has expired. If your on the can for more than 5 mins not moving the lights could go off. In that case you may have to wave at the motion sensor. You could set you timeout to 30 mins if you wanted to.

Edit: I have a separate motion sensor in the shower. I use the Motion Zone app to aggregate multiple motion sensors so they appear as one. You can also use this app to minimize false motion detection as well.

I have multiple sensors in every room where motion lighting is used.. But I donā€™t aggregate them.. Works great for my purposes.. Lights come on with a 5 minute inactivity timeout.. Itā€™s extremely rare for a light to turn off while still occupied..

1 Like

You absolutely don't need to to this but in my opinion it makes management easier. For example if you also want to leverage the same motion sensors in Rule Machine all you have to do is change the motion sensors that are in the motion zone which is much easier than editing a rule.

I can't recall a single time that the lights went off because of motion inactivity using motion zones.

I would just suggest looking into the Motion Zone app and decide if it is something that would benefit you. I actually use the app more for false motion detection than motion aggregation.

I use a recessed door sensor to do this with the motion lighting app.

My timeout is set to 30 seconds and the lights never turn off on anyone as long as they close the door.

Thanks, I will try replicating what you have, using my sensors and see what it gets me.

If you're going to do this in RM I don't see a need for a private boolean. You would use 'cancel delayed actions' on the light going off.

If you want some rule machine examples here is a thread that discusses this. There are a whole bunch of other discussions regarding this as well.

This should work

Trigger: Motion Active

Cancel Delay Actions
On Light
Wait for condition:  Motion Inactive
IF(Door Open) Off Light - delayed 00:00:30 (cancel)

The light will stay on as long as the door is close. I've added a 30-second off delay to match gassgs example.

3 Likes

I was thinking of something like this

Triggers: Door contact change

Actions:
If Light is OFF Turn On lights
set private boolean true
If light ON and door is open, then
set private boolean false
If Light is On and Private Boolean is False, Then
turn light off
set Private Boolean false
End-IF

So basically when you first trigger it by opening the door it will turn the lights on, then when you close it it will set the private boolean to true, when you open the door to leave it will set the private boolean to false and when you close the door again, it will turn the light off.

Edit: just added the if block at then end
Edit 2: another edit. I havenā€™t tried it yet but I think this will work

I have 6 motions in a room and they shut off when they go inactive. No delay and my lights rarely shut off when they're not supposed to. I only use a 3 second delay in my rules. I like living on the edge a bit. :smile:

Something like this should work...
Screen Shot 2020-03-02 at 9.27.45 PM

That is such a cool rule. I love seeing highly efficient rules like this. I'm sure if I'd done this it would have been 2 rules or 30 lines long. Bravo!

1 Like

This worked for me, but the girlfriend did not like it, as she often will apply her makeup with the door open, so the light is always turning off for her. I would rather not just set the delay higher, and was trying to do it a little smarter... I tried adding in a conditional statement at the start that checked if the light was off, but it would then never turn off the light?

Trigger: Motion Active

IF (Bathroom Light) is off THEN
Cancel Delay Actions
On Light
Wait for condition:  Motion Inactive
IF(Door Open) Off Light - delayed 00:00:30 (cancel)

Any ideas?

trigger motion active

if motion active
then
turn on light
cancel delayed action
else if
motion inactive
then turn off light delay 00:00:30 (cancel)

One way would be to use a virtual switch to prevent the light from turning off. If you control your light with a physical switch then you can use Button Controller to set the virtual switch. Let me know how your system is setup and we can figure out what to do.

I have this setup for my toilet closet via two rules: one for contact on the door via Simple Lighting and another rule for situations where the light may be turned in while the door is open. We only close the door when we are in there so primary rule to manage the light turning off is door open and close. But sometimes the light may be turned on while door is open so I wanted to make sure it turns off after 5 minutes.

Hi Pseudonym,

Pretty simple setup, a Lutron Caseta dimmer for the light, and a dome motion sensor above the door threshold to capture motion as soon as someone walks in, but not capture motion from the hallway.

Thanks,
Joe

I don't have any Caseta dimmers but assuming they can act as a scene switch I would use two rules.

First rule modified

Trigger: Motion Active -or- VirtualSwitch On

Cancel Delay Actions
On Light
Wait for condition: VirtualSwith Off
Wait for condition: Motion Inactive
IF(Door Open) Off Light - delayed 00:00:30 (cancel)

The second rule will control the virtual switch. Button 1 double tap to turn on VirtualSwitch, button 2 double tap to turn it off. I put a one hour timeout just in case someone forgets to turn off the VirtualSwitch.

Trigger: Caseta button 1 doubleTapped

On: VirtualSwitch
Wait for event: Caseta button 2 doubleTapped --> timeout: 01:00:00
Off: VirtualSwitch
1 Like

Hi Pseudonym,

This seems to work for all of my tests ( about 6 cases with different combos of door open/closed, switch/dimmer levels set, motion active/inactive)

I used your logic, but updated it a little for some different times to set levels of brightness, and so that the virtual switch overrides setting the light level.

Trigger: Motion Active -or- Bathroom Virtual Switch On

Cancel Delay Actions
 IF ( Bathroom Virtual Switch is Off) THEN
     IF (Time Between 2:30 AM PDT and 6:30 AM PDT) THEN
          Dim: Bathroom Light: 10 --> fade:1
     ELSE
          Dim: Bathroom Light: 40 --> fade:1
    END-IF
END-IF    
Wait for condition: Bathroom Virtual Switch is Off
Wait for condition: Bathroom Motion Inactive
IF (Bathroom Door Open) 
         Off Light - delayed 00:00:30 (cancel)

Glad to see this working for you!

Using the information in this thread I setup two rules.

One rule that turns off the light when the door is opened using simple automation.

The second rule uses motion lighting and is setup to not turn off the lights when the door is closed.

The problem I am running in to is where the light gets turned on by motion and the door gets closed but because no one is in there it then stays on. I am struggling with how to address turning off the light in that scenario.