2 * Example: Control a switch with a contact sensor
4 * Copyright 2014 Andrew Mager
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "Example: Control a switch and lock with a contact sensor",
18 namespace: "com.smarthings.developers",
19 author: "Andrew Mager & Kris Schaller",
20 description: "Using a contact sensor, control a switch and a lock.",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
26 // This is where a user will select devices to be used by this SmartApp
28 // You can create multiple sections to organize the configuration fields of your SmartApp
29 section(title: "Select Devices") {
30 // Inputs assign variables to a group of physical devices
31 input "contact", "capability.contactSensor", title: "Select a contact sensor", multiple: false
32 input "light", "capability.switch", title: "Select a light or outlet", required: true
36 // This function runs when the SmartApp is installed
38 // This is a standard debug statement in Groovy
39 log.debug "Installed with settings: ${settings}"
43 // This function runs when the SmartApp has been updated
45 log.debug "Updated with settings: ${settings}"
46 // Notice that all event subscriptions are removed when a SmartApp is updated
51 // This function is where you initialize callbacks for event listeners
53 // The subscribe function takes a input, a state, and a callback method
54 subscribe(contact, "contact.open", openHandler)
55 subscribe(contact, "contact.closed", closedHandler)
58 // These are our callback methods
59 def openHandler(evt) {
60 log.debug "$evt.name: $evt.value"
65 def closedHandler(evt) {
66 log.debug "$evt.name: $evt.value"
67 // Turn the light off and lock the lock