4 * Copyright 2016 Tim Slagle
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.
18 namespace: "tslagle13",
20 description: "Light rule child app for \"Motion Activated Light\"",
21 category: "Convenience",
22 parent: "tslagle13:Contact Activated Lighting",
23 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
24 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
25 iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
29 page name: "mainPage", title: "Automate Lights & Switches", install: false, uninstall: true, nextPage: "namePage"
30 page name: "namePage", title: "Automate Lights & Switches", install: true, uninstall: true
34 dynamicPage(name: "mainPage") {
35 section("Which contact sensor?") {
36 input "contactSensor", "capability.contactSensor", title: "Which contact sensor(s)?", multiple: true
38 section("Which light would you like to turn on?") {
39 input "light", "capability.switch", title: "Which light?", multiple: true
42 input "contactInactive", "bool", title: "Turn off if contacts closes?", submitOnChange: true
43 if (contactInactive) {
44 input "delay", "number", title: "After how many seconds?", required: false
52 input "overrideLabel", "bool", title: "Edit automation name", defaultValue: "false", required: "false", submitOnChange: true
55 // if the user selects to not change the label, give a default label
56 def l = "$contactSensor turns on $light"
57 log.debug "will set default label of $l"
59 dynamicPage(name: "namePage") {
61 section("Automation name") {
62 label title: "Enter custom name", required: false
69 log.debug "Installed with settings: ${settings}"
75 log.debug "Updated with settings: ${settings}"
82 subscribe (contactSensor, "contact" , contactHandler)
85 def contactHandler(evt){
89 //log.debug evt.isStateChange()
91 if (evt.value == "open") {
94 else if (contactInactive) {
95 runIn(delay , turnLightOff)