Update smart-light-timer-x-minutes-unless-already-on.groovy
[smartapps.git] / official / good-night-house.groovy
1 /**
2  *  Good Night House
3  *
4  *  Copyright 2014 Joseph Charette
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  *  in compliance with the License. You may obtain a copy of the License at:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13  *  for the specific language governing permissions and limitations under the License.
14  *
15  */
16 definition(
17     name: "Good Night House",
18     namespace: "charette.joseph@gmail.com",
19     author: "Joseph Charette",
20     description: "Some on, some off with delay for bedtime, Lock The Doors",
21     category: "Convenience",
22     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
24 /**
25 *  Borrowed code from
26 *  Walk Gentle Into That Good Night
27 *
28 *  Author: oneaccttorulethehouse@gmail.com
29 *  Date: 2014-02-01
30  */
31  )
32 preferences {
33         section("When I touch the app turn these lights off…"){
34                 input "switchesoff", "capability.switch", multiple: true, required:true
35         }
36     section("When I touch the app turn these lights on…"){
37                 input "switcheson", "capability.switch", multiple: true, required:false
38         }
39     section("Lock theses locks...") {
40                 input "lock1","capability.lock", multiple: true
41     }
42         section("And change to this mode...") {
43                 input "newMode", "mode", title: "Mode?"
44         }
45    section("After so many seconds (optional)"){
46                 input "waitfor", "number", title: "Off after (default 120)", required: true
47         }
48 }
49
50
51 def installed()
52 {
53         log.debug "Installed with settings: ${settings}"
54         log.debug "Current mode = ${location.mode}"
55         subscribe(app, appTouch)
56 }
57
58
59 def updated()
60 {
61         log.debug "Updated with settings: ${settings}"
62         log.debug "Current mode = ${location.mode}"
63         unsubscribe()
64         subscribe(app, appTouch)
65 }
66
67 def appTouch(evt) {
68         log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
69     if (location.mode != newMode) {
70                         setLocationMode(newMode)
71                         log.debug "Changed the mode to '${newMode}'"
72     }   else {
73         log.debug "New mode is the same as the old mode, leaving it be"
74         }
75     log.debug "appTouch: $evt"
76     lock1.lock()
77     switcheson.on()
78     def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000
79         switchesoff.off(delay: delay)
80 }