Controling light with contact sensors (door sensor)


#1
  1. Give a description of the problem
    I’m not sure how to write a code to control the light with 4 contact sensors.

  2. What is the expected behavior?
    I have 4 doors with contact sensors on 4 different doors I’d like to turn on the lights when any of the contacts sensors is open and keep the lights on until another contact sensor is opened and closed then turn off the light. ( 1 sensor on the main door and 1 sensor on every apartment door in the building ).

thank you in advance.


#2

Quick mockup:

IF any of SensorA, SensorB or SensorC's contact changes to open
Then
    Turn on light
END IF

IF ALL of SensorA, SensorB or SensorC's contact stays closed for 5 minutes
Then
    Turn off light
END IF

It is not 100% perfect though, because someone could linger for 6 minutes in the hall (with all the doors shut), and the lights would go out on them… but maybe this is a good thing. :wink:

*said in an authoritative voice*
Move along… Nothing to see here… LOL


#3

thanks for the replay, but I’m looking for code that could wait until another event happen like:

If any of SensorA, SensorB, SensorC or SensorD contact changes to open
Then
Turn on light
Then 
wait for sensor SensorA, SensorB, SensorC or SensorD (other than the one opened) contact changes to closed
Then
Turn off light

#4

Unfortunately, there is no suspension of triggers with SmartThings.
(IE: a WAIT will not stop a new trigger from coming in)

In a nutshell, if you subscribe to a device (IE: DoorA’s contact), then each time it opens or closes, the piston will run from top to bottom, and execute anything not blocked by conditions.

For example, both of our pistons have these for triggers:

ContactA opens = Piston runs top to bottom
ContactA closes = Piston runs top to bottom
ContactB opens = Piston runs top to bottom
ContactB closes = Piston runs top to bottom
ContactC opens = Piston runs top to bottom
ContactC closes = Piston runs top to bottom
ContactD opens = Piston runs top to bottom
ContactD closes = Piston runs top to bottom


Some advance coding using variables may be able to circumvent around this a bit, but the code will be MUCH more complex, with greater chance of errors… and yet, all of the above triggers will still be true.


Side Note:

Also keep in mind that your original goal will break if someone opens their door (to sweep, for example), and then shuts it. With your logic, the light could potentially stay on for hours(since they did not open a second door)


#5

yea that’s right. when I know how to do this code I’ll add to it motion sensor detection to turn the light off if someone open the door then closed the same door without opening another door.


#6

I can’t wait to see that monstrosity… :grin:


Don’t forget to take into account people making 2-3 trips to the car unloading groceries…

Yeah, sorry… I am not touching this one unless I am on-the-clock…
I’m in no rush for grey hair, LOL


#7

:grin:


#8

Once you add motion to the mix, this becomes very manageable. For instance, my patio light comes on if (the back door is open) OR (motion is sensed). Either may trigger, but it only turns off after both have been cleared for a period of time. In fact, that is how I found out that my wife sometimes forgets to close the door all of the way :smile:


#9

That what I have right now but using the contact sensor is more reliable than motion sensor, especially for elderly that might move slowly so the motion sensor might not detect the motion. So i want the main skeleton of the code is the contact sensor.


#10

I was taking a drink of coffee when I read this… and well… let’s just say that I now have a mess to clean up, LOL


#11

Hehehe, sorry about the mess.


#12

Hi,

I created a solution to keep the lights on until another door opens.

first I create a piston to turn on the light when any doors open.

then I made a variable for each door, I have 5 doors and I just have 4 contact sensor, so I used 1 motion sensor to act when door open.

I made 5 of the above piston. each door has one.

then I made a huge piston to turn off the lights when doors closed after targeted opening ways and there is no motion.

I believe there is a better way to do that or at least to decrease the number of pistons used, I’m open to any suggestions to make it better.

hope it helps.