2 * Hall Light: Welcome Home
4 * Author: brian@bevey.org
7 * Turn on the hall light if someone comes home (presence) and the door opens.
11 name: "Hall Light: Welcome Home",
12 namespace: "imbrianj",
13 author: "brian@bevey.org",
14 description: "Turn on the hall light if someone comes home (presence) and the door opens.",
15 category: "Convenience",
16 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
17 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
21 section("People to watch for?") {
22 input "people", "capability.presenceSensor", multiple: true
25 section("Front Door?") {
26 input "sensors", "capability.contactSensor", multiple: true
29 section("Hall Light?") {
30 input "lights", "capability.switch", title: "Switch Turned On", multilple: true
33 section("Presence Delay (defaults to 30s)?") {
34 input name: "presenceDelay", type: "number", title: "How Long?", required: false
37 section("Door Contact Delay (defaults to 10s)?") {
38 input name: "contactDelay", type: "number", title: "How Long?", required: false
52 state.lastClosed = now()
53 subscribe(people, "presence.present", presence)
54 subscribe(sensors, "contact.open", doorOpened)
58 def delay = contactDelay ?: 10
60 state.lastPresence = now()
62 if(now() - (delay * 1000) < state.lastContact) {
63 log.info('Presence was delayed, but you probably still want the light on.')
69 def delay = presenceDelay ?: 30
71 state.lastContact = now()
73 if(now() - (delay * 1000) < state.lastPresence) {
74 log.info('Welcome home! Let me get that light for you.')