Control Lights w/ Contact Sensor w/o leaving door open


#1

1) Give a description of the problem
Sorry if this has been asked before, but I can’t find it. Whenever I let my dog out at night, I want the backyard lights to turn on. I want the lights to turn off when I open the door open again to let him back in. To complicate matters, I want the piston to ignore the command if a virtual switch (Backyard Time) is turned on.

2) What is the expected behavior?
If between sunset and sunrise and kitchen sliding door changes to open, turn on backyard lights.
If between sunset and sunrise and kitchen sliding door door changes to open again, turn off backyard lights.
Ignore all if Backyard Time is on

3) What is happening/not happening?
I can’t figure figure out how to execute the “off” action. I don’t think I can tie both “on” and “off” to “open”. And if I tie “off” to “close”, the lights will turn off the first time I close the door. I haven’t bothered to add the time of day restriction until I solve for on/off action.

4) Post a Green Snapshot of the pistonimage


#2

I’m assuming Switch 33 is the Virtual (Back Yard Time) switch, and Switch 13 is your actual switch.

Without a log, I’m guessing at what is happening, but based on the logic, I assume the light turns on, but never turns off, that is because, (assuming Backyard Time is off), every time you open the door the first condition becomes true, and it turns the light (Switch 13) on.

I think all you need to do is modify your first if condition to include “and Switch 13’ switch is off”, that way once the light is on from the first open, then 2nd open can actually make it down to the else if case and turn the light off. Ie. Only try to turn the outside light on, if its not Backyard Time, and the light is not already on.


#3

A simplified version that can more than likely be optimized…

Switch 11 is your virtual Backyard Time switch
Contact Sensor 3 is your door sensor to detect open close state
Switch 4 is your light switch

J


#4

I decided to create one for myself just for fun…

I have not tested it yet, however it should work (not sure why it called switches keypads…).
Keypad 3 is your virtual BackyardTime Switch
ContactSensor 3 is your Kitchen Sliding Door
Keypad 1 is your Backyard Lights Switch

This will (Assuming its not Backyard Time and is Nighttime [Before Sunrise, or After Sunset]) turn on the light when the door is opened, and then turn the light off when the door closes for the 2nd time. I did it that why for myself so that the lights don’t actually turn off till I have closed the door after letting the dogs back in, instead of when I open the door to let them back in. ( Sometimes I have to go outside to call / get one of them to come in, and I want the lights to stay on during that time :slight_smile: )

I will be testing it myself tonight.


#6

Thanks for the suggestion! I gave this a try. Upon opening, the lights came on but then turned off once shut. I’ll need to give it some more thought.


#7

Thanks for the advice. Unfortunately the lights immediately turned off once I closed the door (and the dog was still outside). I’m going to keep thinking through the logic.


#8

Yeah, that makes since now that I went and made a version for myself, what you are wanting to do requires something else to help keep track of the state, a bool, a time stamp, a count, something. Otherwise it can’t tell the difference between the first close and the second close.

If you look at the Example I posted you will see I have a bool ‘JustOn’, that allows me to understand and ignore the first close. I tested a minor variation of the one I posted above tonight with my dogs and it worked as I expected.

I will continue to think of a way to do it without a variable, but I do not think its possible.


#9

If you don’t mind, I’d love to give the variation that worked for you a try. I’m guessing it has a different import code.


#10

This one I also added a extra timeout check, so if you open the door again within 10 minutes ( like to let a 2nd dog in that does not come back to the door as fast) it wont re turn the light on. If this does not work, grab a full log for me to compare to mine.

Outlet 1: Backyard Play
Contact Sensor: Kitchen Door Sensor
Keypad: Backyard Light Switch


#11

If back door changes to open
Then
Using light
Turn on
End if
If back door changes to closed
And
Light was on for at least xx seconds
Then
Using light
Turn off
End if

Change xx to a sweet spot where the light turns on and the door closes that the second if will be false. Once you get that working as expected then start adding your other restrictions.


#12

Thanks! Your tip led me to a solution that works the most reliably so far. And thanks to everyone else for your help. This is my most advance piston so far and you all taught me a lot.

Below is the winning piston.
Switch 33 is my virtual switch
Contact Sensor 7 is the sliding door contact sensor
Switch 13 is the outdoor switch for my lights
Updated 10.26.17