Update vacation-lighting-director.groovy
[smartapps.git] / official / switch-activates-home-phrase.groovy
1 /**
2  *  Switch Activates Hello, Home Phrase
3  *
4  *  Copyright 2015 Michael Struck
5  *  Version 1.01 3/8/15
6  *
7  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  *  in compliance with the License. You may obtain a copy of the License at:
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
13  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
14  *  for the specific language governing permissions and limitations under the License.
15  *
16  *  Ties a Hello, Home phrase to a switch's (virtual or real) on/off state. Perfect for use with IFTTT.
17  *  Simple define a switch to be used, then tie the on/off state of the switch to a specific Hello, Home phrases.
18  *  Connect the switch to an IFTTT action, and the Hello, Home phrase will fire with the switch state change.
19  *
20  *
21  */
22 definition(
23     name: "Switch Activates Home Phrase",
24     namespace: "MichaelStruck",
25     author: "Michael Struck",
26     description: "Ties a Hello, Home phrase to a switch's state. Perfect for use with IFTTT.",
27     category: "Convenience",
28     iconUrl: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1.png",
29     iconX2Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1@2x.png",
30     iconX3Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1@2x.png")
31
32
33 preferences {
34         page(name: "getPref")
35 }
36         
37 def getPref() {    
38     dynamicPage(name: "getPref", title: "Choose Switch and Phrases", install:true, uninstall: true) {
39     section("Choose a switch to use...") {
40                 input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
41     }
42     def phrases = location.helloHome?.getPhrases()*.label
43                 if (phrases) {
44                 phrases.sort()
45                         section("Perform the following phrase when...") {
46                                 log.trace phrases
47                                 input "phrase_on", "enum", title: "Switch is on", required: true, options: phrases
48                                 input "phrase_off", "enum", title: "Switch is off", required: true, options: phrases
49                         }
50                 }
51         }
52 }
53
54 def installed() {
55         log.debug "Installed with settings: ${settings}"
56         subscribe(controlSwitch, "switch", "switchHandler")
57 }
58
59 def updated() {
60         log.debug "Updated with settings: ${settings}"
61         unsubscribe()
62         subscribe(controlSwitch, "switch", "switchHandler")
63 }
64
65 def switchHandler(evt) {
66         if (evt.value == "on") {
67         location.helloHome.execute(settings.phrase_on)
68     } else {
69         location.helloHome.execute(settings.phrase_off)
70     }
71 }
72