Compare commits

...

1 Commits

Author SHA1 Message Date
Brian Warner
55081dd486 MSA-726: I wrote this app to add some garage-door-specific smarts to my outside lighting. I wasn't able to find anything that was aware of multiple garage door sensors, and that would keep the lights on for a certain amount of time after the last door was closed. The use case is as follows:
A garage door goes up while it's dark.  All lights turn on and stay on as long as the door is open, which is useful if you're working outside at night.  If you were actually pulling a car out to leave, you'd want the lights on as you pull out of the driveway, so there is an option to keep them on for a certain time after the door closes.
2015-12-03 19:51:55 -06:00

View File

@@ -0,0 +1,105 @@
/**
* Light Up The Night
*
* Copyright 2015 Brian Warner
*
* 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 Up The Night",
namespace: "brianwarner",
author: "Brian Warner",
description: "Turn on certain lights when a door opens at night, and turn them off a certain time after the last door closes. Great for garage doors and driveway lights.",
category: "Convenience",
iconUrl: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn.png",
iconX2Url: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn@2x.png",
iconX3Url: "http://cdn.device-icons.smartthings.com/Lighting/light9-icn@3x.png")
preferences {
section() {
input "contactsensors", "capability.contactSensor", multiple: true, title: "When these doors open:"
}
section() {
input "lights", "capability.switch", required: true, multiple: true, title: "Turn on these lights:"
}
section() {
input "timer", "number", required: true, title: "Keep them on until all doors are closed for this many minutes:", range: "0..240"
}
section() {
input "sunriseoffset", "number", required: true, title: "Start turning on the lights this many minutes before sunset:", range: "0..360"
}
section() {
input "sunsetoffset", "number", required: true, title: "Stop turning on the lights this many minutes after sunrise:", range: "0..360"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(garagedoors, "door.open", doorOpenHandler)
subscribe(garagedoors, "door.closed", doorClosedHandler)
subscribe(contactsensors, "contact.open", doorOpenHandler)
subscribe(contactsensors, "contact.closed", doorClosedHandler)
}
def doorOpenHandler(evt) {
// log.debug "Door opened."
def now = new Date()
def sunTime = getSunriseAndSunset(sunriseOffset: "00:$sunriseoffset", sunsetOffset: "-00:$sunsetoffset")
if (now > sunTime.sunset || now < sunTime.sunrise) {
// log.debug "Turning lights on."
lights.on()
}
}
def doorClosedHandler(evt) {
// log.debug "A door closed."
runIn(60 * timer, checkClosed)
}
def checkClosed() {
// log.debug "Checking to ensure all doors are still closed."
def contactSensorState = contactsensors.currentState("contact")
def anyContactSensorsOpen = contactSensorState.value.findAll {it == "open"}
if (!anyContactSensorsOpen) {
def elapsed = now() - contactSensorState.date.time.max()
def timeout = 1000 * 60 * timer
if (elapsed >= timeout) {
// log.debug "Doors have stayed closed. Turning off the lights."
lights.off()
} else {
// log.debug "Doors were opened. Wait a little longer."
}
} else {
// log.debug "It appears a door is still open."
}
}