Created
September 22, 2014 18:07
-
-
Save mager/b3410788712cd45ab6d4 to your computer and use it in GitHub Desktop.
SmartThings SmartApp for 3-Way Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 3-Way Switch | |
* | |
* Copyright 2014 Andrew Mager | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
* in compliance with the License. You may obtain a copy of the License at: | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | |
* for the specific language governing permissions and limitations under the License. | |
* | |
*/ | |
definition( | |
name: "3-Way Switch", | |
namespace: "co.mager", | |
author: "Andrew Mager", | |
description: "Turn a switch on and off, three-way style", | |
category: "", | |
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", | |
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", | |
oauth: true) | |
preferences { | |
section("Select device") { | |
input "switch1", "capability.switch", title: "Select switch #1", multiple: false | |
input "switch2", "capability.switch", title: "Select switch #2", multiple: false | |
input "outlet", "capability.switch", title: "Select an outlet to control", multiple: false | |
} | |
} | |
def installed() { | |
log.debug "Installed with settings: ${settings}" | |
initialize() | |
} | |
def updated() { | |
log.debug "Updated with settings: ${settings}" | |
initialize() | |
} | |
def initialize() { | |
subscribe switch1, "switch", main | |
subscribe switch2, "switch", main | |
} | |
def main(evt) { | |
log.debug "Switch action: $evt.value" | |
if (outlet.currentValue("switch") == "on") { | |
log.debug "Switch is currently on" | |
outlet.off() | |
log.debug outlet.currentValue("switch") | |
} else { | |
log.debug "Switch is currently off" | |
outlet.on() | |
log.debug outlet.currentValue("switch") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment