2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
20 namespace: "smartthings",
21 author: "SmartThings",
22 description: "Turns on an outlet when the user is present and off after a period of time",
23 category: "Convenience",
24 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
25 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png"
29 section("When someone's around because of...") {
30 input name: "motionSensors", title: "Motion here", type: "capability.motionSensor", multiple: true, required: false
31 input name: "presenceSensors", title: "And (optionally) these sensors being present", type: "capability.presenceSensor", multiple: true, required: false
33 section("Turn on these outlet(s)") {
34 input name: "outlets", title: "Which?", type: "capability.switch", multiple: true
36 section("For this amount of time") {
37 input name: "minutes", title: "Minutes?", type: "number", multiple: false
50 def subscribeToEvents() {
51 subscribe(motionSensors, "motion.active", motionActive)
52 subscribe(motionSensors, "motion.inactive", motionInactive)
53 subscribe(presenceSensors, "presence.not present", notPresent)
56 def motionActive(evt) {
57 log.debug "$evt.name: $evt.value"
63 def motionInactive(evt) {
64 log.debug "$evt.name: $evt.value"
71 log.debug "$evt.name: $evt.value"
79 for (it in motionSensors) {
80 if (it.currentMotion == "active") {
90 for (it in presenceSensors) {
91 if (it.currentPresence == "not present") {
101 unschedule("scheduledTurnOff")
105 def delay = minutes * 60
106 runIn(delay, "scheduledTurnOff")
109 def scheduledTurnOff() {
111 unschedule("scheduledTurnOff") // Temporary work-around to scheduling bug