Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / Extractor / App2 / App2.groovy
1 /////
2 definition(
3     name: "Good Night House",
4     namespace: "charette.joseph@gmail.com",
5     author: "Joseph Charette",
6     description: "Some on, some off with delay for bedtime, Lock The Doors",
7     category: "Convenience",
8     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
9     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
10 /**
11 *  Borrowed code from
12 *  Walk Gentle Into That Good Night
13 *
14 *  Author: oneaccttorulethehouse@gmail.com
15 *  Date: 2014-02-01
16  */
17  )
18 preferences {
19         section("When I touch the app turn these lights off…"){
20                 input "switchesoff", "capability.switch", multiple: true, required:true
21         }
22     section("When I touch the app turn these lights on…"){
23                 input "switcheson", "capability.switch", multiple: true, required:false
24         }
25     section("Lock theses locks...") {
26                 input "lock1","capability.lock", multiple: true
27     }
28         section("And change to this mode...") {
29                 input "newMode", "mode", title: "Mode?"
30         }
31    section("After so many seconds (optional)"){
32                 input "waitfor", "number", title: "Off after (default 120)", required: true
33         }
34 }
35
36
37 def installed()
38 {
39         log.debug "Installed with settings: ${settings}"
40         log.debug "Current mode = ${location.mode}"
41         subscribe(app, appTouch)
42 }
43
44
45 def updated()
46 {
47         log.debug "Updated with settings: ${settings}"
48         log.debug "Current mode = ${location.mode}"
49         unsubscribe()
50         subscribe(app, appTouch)
51 }
52
53 def appTouch(evt) {
54         log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
55     if (location.mode != newMode) {
56                         setLocationMode(newMode)
57                         log.debug "Changed the mode to '${newMode}'"
58     }   else {
59         log.debug "New mode is the same as the old mode, leaving it be"
60         }
61     log.debug "appTouch: $evt"
62     lock1.lock()
63     switcheson.on()
64     def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000
65         switchesoff.off(delay: delay)
66 }