Compare commits

...

1 Commits

Author SHA1 Message Date
Marco
0a5c8c75a3 MSA-1947: . 2017-05-02 13:45:01 -07:00

View File

@@ -1,57 +1,57 @@
/** /**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * 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: * in compliance with the License. You may obtain a copy of the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * for the specific language governing permissions and limitations under the License.
* *
* Power Allowance * Power Allowance
* *
* Author: SmartThings * Author: SmartThings
*/ */
definition( definition(
name: "Power Allowance", name: "Power Allowance",
namespace: "smartthings", namespace: "smartthings",
author: "SmartThings", author: "SmartThings",
description: "Save energy or restrict total time an appliance (like a curling iron or TV) can be in use. When a switch turns on, automatically turn it back off after a set number of minutes you specify.", description: "Save energy or restrict total time an appliance (like a curling iron or TV) can be in use. When a switch turns on, automatically turn it back off after a set number of minutes you specify.",
category: "Green Living", category: "Green Living",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png", iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png" iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
) )
preferences { preferences {
section("When a switch turns on...") { section("When a switch turns on...") {
input "theSwitch", "capability.switch" input "theSwitch", "capability.switch"
} }
section("Turn it off how many minutes later?") { section("Turn it off how many minutes later?") {
input "minutesLater", "number", title: "When?" input "minutesLater", "number", title: "When?"
} }
} }
def installed() { def installed() {
log.debug "Installed with settings: ${settings}" log.debug "Installed with settings: ${settings}"
subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false]) subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
} }
def updated() { def updated() {
log.debug "Updated with settings: ${settings}" log.debug "Updated with settings: ${settings}"
unsubscribe() unsubscribe()
subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false]) subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
} }
def switchOnHandler(evt) { def switchOnHandler(evt) {
log.debug "Switch ${theSwitch} turned: ${evt.value}" log.debug "Switch ${theSwitch} turned: ${evt.value}"
def delay = minutesLater * 60 def delay = minutesLater * 60
log.debug "Turning off in ${minutesLater} minutes (${delay}seconds)" log.debug "Turning off in ${minutesLater} minutes (${delay}seconds)"
runIn(delay, turnOffSwitch) runIn(delay, turnOffSwitch)
} }
def turnOffSwitch() { def turnOffSwitch() {
theSwitch.off() theSwitch.off()
} }