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")
32 page(name: "pageAbout", title: "About ${textAppName()}") {
34 paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
36 section("Instructions") {
46 dynamicPage(name: "getPref", install:true, uninstall: true) {
47 section("Choose a switch to use...") {
48 input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
51 def phrases = location.helloHome?.getPhrases()*.label
54 section("Perform which phrase when...") {
55 input "phrase_on", "enum", title: "Switch is on", options: phrases, required: false
56 input "phrase_off", "enum", title: "Switch is off", options: phrases, required: false
59 section("Change to which mode when...") {
60 input "onMode", "mode", title: "Switch is on", required: false
61 input "offMode", "mode", title: "Switch is off", required: false
63 section([mobileOnly:true], "Options") {
64 label(title: "Assign a name", required: false)
65 mode title: "Set for specific mode(s)", required: false
66 href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
72 log.debug "Installed with settings: ${settings}"
73 subscribe(controlSwitch, "switch", "switchHandler")
77 log.debug "Updated with settings: ${settings}"
79 subscribe(controlSwitch, "switch", "switchHandler")
82 def switchHandler(evt) {
83 if (evt.value == "on" && (phrase_on || onMode)) {
85 location.helloHome.execute(settings.phrase_on)
91 else if (evt.value == "off" && (phrase_off || offMode)) {
93 location.helloHome.execute(settings.phrase_off)
101 def changeMode(newMode) {
102 if (location.mode != newMode) {
103 if (location.modes?.find{it.name == newMode}) {
104 setLocationMode(newMode)
106 log.debug "Unable to change to undefined mode '${newMode}'"
111 //Version/Copyright/Information/Help
113 private def textAppName() {
114 def text = "Switch Activates Home Phrase or Mode"
117 private def textVersion() {
118 def text = "Version 1.0.1 (06/20/2015)"
121 private def textCopyright() {
122 def text = "Copyright © 2015 Michael Struck"
125 private def textLicense() {
127 "Licensed under the Apache License, Version 2.0 (the 'License'); "+
128 "you may not use this file except in compliance with the License. "+
129 "You may obtain a copy of the License at"+
131 " http://www.apache.org/licenses/LICENSE-2.0"+
133 "Unless required by applicable law or agreed to in writing, software "+
134 "distributed under the License is distributed on an 'AS IS' BASIS, "+
135 "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. "+
136 "See the License for the specific language governing permissions and "+
137 "limitations under the License."
140 private def textHelp() {
142 "Ties a Hello, Home phrase or mode to a switch's (virtual or real) on/off state. Perfect for use with IFTTT. "+
143 "Simple define a switch to be used, then tie the on/off state of the switch to a specific Hello, Home phrases or mode. "+
144 "Connect the switch to an IFTTT action, and the Hello, Home phrase or mode will fire with the switch state change."