4 * Copyright 2015 Michael Struck
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 mode 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 mode.
18 * Connect the switch to an IFTTT action, and the mode will fire with the switch state change.
23 name: "Switch Changes Mode",
24 namespace: "MichaelStruck",
25 author: "Michael Struck",
26 description: "Ties a 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")
33 page(name: "getPref", title: "Choose Switch and Modes", install:true, uninstall: true) {
34 section("Choose a switch to use...") {
35 input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
37 section("Change to a new mode when...") {
38 input "onMode", "mode", title: "Switch is on", required: false
39 input "offMode", "mode", title: "Switch is off", required: false
45 log.debug "Installed with settings: ${settings}"
47 subscribe(controlSwitch, "switch", "switchHandler")
51 log.debug "Updated with settings: ${settings}"
54 subscribe(controlSwitch, "switch", "switchHandler")
57 def switchHandler(evt) {
58 if (evt.value == "on") {
65 def changeMode(newMode) {
67 if (newMode && location.mode != newMode) {
68 if (location.modes?.find{it.name == newMode}) {
69 setLocationMode(newMode)
72 log.debug "Unable to change to undefined mode '${newMode}'"