2 * Switch Activates Home Phrase or Mode
4 * Copyright 2015 Michael Struck
5 * Version 1.0.1 6/20/15
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
23 name: "Switch Activates Home Phrase or Mode",
24 namespace: "MichaelStruck",
25 author: "Michael Struck",
26 description: "Ties a Hello, Home phrase or mode 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")
38 dynamicPage(name: "getPref", install:true, uninstall: true) {
39 section("Choose a switch to use...") {
40 input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
43 def phrases = location.helloHome?.getPhrases()*.label
46 section("Perform which phrase when...") {
47 input "phrase_on", "enum", title: "Switch is on", options: phrases, required: false
48 input "phrase_off", "enum", title: "Switch is off", options: phrases, required: false
51 section("Change to which mode when...") {
52 input "onMode", "mode", title: "Switch is on", required: false
53 input "offMode", "mode", title: "Switch is off", required: false
55 section([mobileOnly:true], "Options") {
56 label(title: "Assign a name", required: false)
57 mode title: "Set for specific mode(s)", required: false
58 href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
63 page(name: "pageAbout", title: "About ${textAppName()}") {
65 paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
67 section("Instructions") {
73 log.debug "Installed with settings: ${settings}"
74 subscribe(controlSwitch, "switch", "switchHandler")
78 log.debug "Updated with settings: ${settings}"
80 subscribe(controlSwitch, "switch", "switchHandler")
83 def switchHandler(evt) {
84 if (evt.value == "on" && (phrase_on || onMode)) {
86 location.helloHome.execute(settings.phrase_on)
92 else if (evt.value == "off" && (phrase_off || offMode)) {
94 location.helloHome.execute(settings.phrase_off)
102 def changeMode(newMode) {
103 if (location.mode != newMode) {
104 if (location.modes?.find{it.name == newMode}) {
105 setLocationMode(newMode)
107 log.debug "Unable to change to undefined mode '${newMode}'"
112 //Version/Copyright/Information/Help
114 private def textAppName() {
115 def text = "Switch Activates Home Phrase or Mode"
118 private def textVersion() {
119 def text = "Version 1.0.1 (06/20/2015)"
122 private def textCopyright() {
123 def text = "Copyright © 2015 Michael Struck"
126 private def textLicense() {
128 "Licensed under the Apache License, Version 2.0 (the 'License'); "+
129 "you may not use this file except in compliance with the License. "+
130 "You may obtain a copy of the License at"+
132 " http://www.apache.org/licenses/LICENSE-2.0"+
134 "Unless required by applicable law or agreed to in writing, software "+
135 "distributed under the License is distributed on an 'AS IS' BASIS, "+
136 "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. "+
137 "See the License for the specific language governing permissions and "+
138 "limitations under the License."
141 private def textHelp() {
143 "Ties a Hello, Home phrase or mode to a switch's (virtual or real) on/off state. Perfect for use with IFTTT. "+
144 "Simple define a switch to be used, then tie the on/off state of the switch to a specific Hello, Home phrases or mode. "+
145 "Connect the switch to an IFTTT action, and the Hello, Home phrase or mode will fire with the switch state change."