Door 1 OR 2 open turn on light; door 1 AND 2 closed turn off?

Ok, so this sounds simple enough, but I was wondering if someone already did this in a smartapp somewhere? I have two garage doors and want to turn on the garage lights if either one is opened and then turn them back off when both are closed.
I’m kinda new to ST, and haven’t really coded anything but would give it a try if there was something I could possibly work from to learn. Any help greatly appreciated.


1 Like

I have two doors into a single closet and wrote exactly this app. It’s quite simple, but does the job pretty well. Here’s the code:

 *  Light Turn On Any Open
 *  Copyright 2014 Reed Taylor
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
    name: "Light On while Any Open",
    namespace: "schmedlock",
    author: "Reed Taylor",
    description: "Turn a light on using a logical OR of some sensors being open",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "")

preferences {
	section("When any of these are open...") {
		input "contact1", "capability.contactSensor", title: "Doors", multiple: true
	section("Turn these on:") {
		input "switch1", "capability.switch", title: "Switches", multiple: true

def installed() {
	log.debug "Installed with settings: ${settings}"


def updated() {
	log.debug "Updated with settings: ${settings}"


def initialize() {
	subscribe(contact1, "contact", contactHandler)

def contactHandler(evt) {
	log.trace "contactHandler: $evt ${evt.value}"
    def openSensor = contact1.find{it.currentValue("contact") == "open"}
    if (openSensor != null) {
    	log.debug "At least one sensor (${openSensor.label}) is open, switch on"
    } else {
    	log.debug "No sensors are open, switch off"

Fantastic! I just installed your app, and it works perfectly! Thank you so much.
Now I just need to learn how to write code like this. :smile:


1 Like

Glad to hear it worked well for you! :smile:


This is fantastic, thank you! I only wish there was one other thing: “Turn off after __ minutes.” What do I need to add for this?

That’s an easy one, just use the built-in smart-app under Lights & Switches called power allowance to turn off off after a certain amount of time :slight_smile:

That doesn’t quite work because this app immediately turns off the light as soon as one of the doors is closed.

Here’s what I’m doing:

I open door from garage, which should turn on the light at the basement steps. Those lights should stay on while I shut the door and climb the steps to open the kitchen door and go inside. The same should happen in reverse.

This app works exactly as it should, except I’m looking for a delay before the light is shut off so I can get from one door to the next without climbing the steps in darkness. :smiley:

You can do this easily with Smart Lighting. Once I get some cell signal I’ll take a screen shot and upload it.

1 Like

Aha! Didn’t realize you could include multiple sensors there. Problem solved, thanks!

@prjct92eh2 you have mentioned 5 minutes but there might be instance when can I cannot reach second door in 5 minutes. I want my garage light to open when Garage door is opened and garage entry door is closed. And vice versa.