Motion and door switch controlling light


#1

My bathroom has a door contact and a motion contact and a smart switch controlling a dumb light.

The switch is sort of annoying to switch on - it’s around a corner in the bathroom. There’s a motion sensor that will change state to Motion Detected when you walk into the bathroom even before you can turn the switch on.

What I’d like:

If Motion is detected with the door opened (someone walks into the bathroom, does not shut door. Getting a tissue? Checking their look in the mirror?): Light goes on for 2 minutes then shuts off, or can be turned off sooner with switch. Motion sensor would need to ignore motion for that full 2 minutes? The person may be moving around, or moving to leave. So maybe turning the switch OFF will reactivate the motion sensor after… 10 seconds? Enough time to leave the bathroom…

If Motion is detected and the door is shut within 20(?) seconds (means someone went into the bathroom and HEY! SOMEONE’S BUSY!): Light stays on until after door is opened again then turns off, or can be shut off with switch. This prevents the light shutting off and having to wave. Maybe opening the door, or shutting off the switch (both?) can reactivate the motion sensor after 10 seconds, enough time to leave the bathroom.

Light Switch turned on overrides any control until the switch is turned off (plus that 10 second bathroom leave time?)

I made a few false starts with some of the forum examples, but… None were pretty. Help please?


#2

I am thinking outloud here… (IE: Rough draft)

IF Sensor's motion changes to active
Then 
    Turn on light
    WAIT 20 seconds
    IF Door is open
    Then
        Disable Motion Sensor
        Wait 2 minutes
        Turn off light
    ELSE
        Disable Motion Sensor
    END IF
END IF

IF Door opens
Then 
    Turn on light
    Enable Motion Sensor
END IF

Hmmm, now that I see it written out, I think the main focus should be on the mandatory disabling of the motion sensor. (since that happens in both of your scenarios)

It might be as simple as:

IF Sensor's motion stays active 20 seconds
    Then Disable motion sensor
END IF

IF Door's contact opens
    Then Enable motion sensor
END IF

I would definitely keep the motion trigger in a separate piston.

IF Sensor's motion changes to active
    Then Turn on light
END IF

IF Sensor's motion stays inactive for 22 secs
    Then Turn off light
END IF

#3

One challenge I see with this is:
What if someone grabs that tissue in 15 seconds… They pop in, grab it, and close the door on the way out. At the 20 second mark, the door will be closed, so the program will think the toilet is currently being used. AKA, Leave the light on until the door opens next.

It almost sounds like you want the motion sensor to be disabled the instant motion is detected.
(and ironically, re-enabled the instant the room is empty)


The trick though, will be in “guesstimating” the times used to determine whether the room is occupied or not. Unfortunately, I do not see a 100% success rate for all users & cases. You are going to have to choose a cutoff time at some point.

  • If the delay is too long, then the quick pop-ins may leave the light on for hours at a time.
  • If the delay is too short, then means slow walkers may be in the dark at the 2 min mark (until they wave their hand)

#4

Well thinking about it - the door should never be shut, unless someone is in the bathroom… Um… Needing privacy! LOL and it’s just two of us here - we both know it. If we have guests we can tell them.


#5

And I mean - worst case, and would be written in the piston, is if somehow, someone’s in the bathroom and the light turns off - they can just turn on the switch (which has a small green LED) and the light stays on until it’s turned off with the switch.


#6

This is a key component, and will make the coding much easier!!!

I am tied up at the moment though…


Starting thoughts?

IF Door opens, Then Turn on Motion Sensor
IF Door closes, Then Turn off Motion Sensor


#7

ok I have to ask,
without using some sort of a variable and/or sim switch, how do you turn ON/OFF a motion sensor???


#8

Yea, those were my starting thoughts… but I also have a taboo idea on the back burner… Honestly, I’d rather not spend time elaborating that complexity though, unless @withay likes this structure:

  • IF Door opens, Then Turn on Motion Sensor
  • IF Door closes, Then Turn off Motion Sensor

If not, then we keep brainstorming…

If so, then I will likely elaborate in another 36 hours…
(Wednesdays are a bit crazy for me here)

Feel free to step in anyone…


#9

Maybe have one piston watching the motion sensor and a separate piston watching the door. to ‘turn off’ the motion sensor, pause the piston. to ‘turn on’ the motion sensor, resume the piston.


#10

That makes perfect sense but I know @WCmore and he normally doesn’t like pausing and resuming a piston :)) That’s why I was curious.


#11

Well, if she wants to go that route, I have a “secret weapon” that can resolve that…
but it will increase from two pistons into three.

I am waiting on feedback before elaborating…


#12

Greets! Sorry - busy 'round these here parts! Ok, so:

IF door IS sensor IS open, Motion Sensor is On
IF door IS sensor IS closed, Motion Sensor is OFF

Is what you’re saying, yes? Mmmm… I’m not in love with it. May I (I’m “he” btw) see your secret weapon? That didn’t at ALL sound risque. :slight_smile:


#13

It will take three pistons, and a bit of time to explain, with warnings etc.

Honestly, if you do not like the core concept:

  • IF Door opens, Then Turn on Motion Sensor
  • IF Door closes, Then Turn off Motion Sensor

Then I would rather not put this out there.


#14

Let me mull this over a bit and I’ll come back. I have to lay out in my head how it would affect what I want to do.


#15

For what it’s worth, I usually do not ever recommend “Disabling” a motion sensor… The only reason I have even considered it is because your original post sounds like you want the motion sensor to be 100% dumb when the door is closed.

Of course, you know your long term goals better than I do… so I may be way off


#16

Multiple pistons are sometimes necessary.

I have 5 separate pistons for my garage lights: Garage Door Opens; Garage Motion, Back Hall Door Opens (which leads into the garage); Garage Lights Automation and Garage Lights Control.

The first 3 will trigger something in the “Garage Lights Automation”. Then, the Garage Lights Automation will trigger something in the “Garage Lights Control”.

This is because when a Door Opens, or Motion is Active, the lights come on. When a Door Closes, or Motion becomes Inactive, a 10 minute timer is set for the lights to go off. But, if another even happens (lets say the Back Hall Door opens or there is motion), the 10 minute timer is interrupted (using Cancel All Pending Tasks), until another Close or Inactive event happens.

This was necessary, because too many times the lights would turn off on me at night as I was still in the garage.

I may post these 5 somewhere if anyone seems interested.

This worked so well, that I ended creating a “Lights Control” piston for each room (Living Room Lights Control, Rec Room Lights Control…etc). Then, certain events can trigger something already setup in the Lights Control.


#17

I would love to see them…


#18

Yeah at this point, going back to what I originally put as my goals, I’d like to see them too! :slight_smile:


#19

While we wait for @dejavux2
I’m going to draft you a piston(s)
but let me ask you first, do you mind doing this with variables??? and/or 2-3 pistons???


#20

LOL Honestly, if it does all that I said I wanted it to do, I don’t mind what it takes as long as it’s not precarious, and I can learn from it.