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.
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:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
*/
definition(
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: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
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}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
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"
switch1.on()
} else {
log.debug "No sensors are open, switch off"
switch1.off()
}
}
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.
@Automated_House 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.