2 * Alert on Power Consumption
4 * Copyright 2014 George Sudarkoff
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.
20 name: "Better Laundry Monitor",
21 namespace: "com.sudarkoff",
22 author: "George Sudarkoff",
23 description: "Using a switch with powerMonitor capability, monitor the laundry cycle and alert when it's done.",
24 category: "Green Living",
25 iconUrl: "https://s3.amazonaws.com/smartthings-device-icons/Appliances/appliances8-icn.png",
26 iconX2Url: "https://s3.amazonaws.com/smartthings-device-icons/Appliances/appliances8-icn@2x.png")
30 section ("When this device stops drawing power") {
31 input "meter", "capability.powerMeter", multiple: false, required: true
32 input "cycle_start_power_threshold", "number", title: "Start cycle when power consumption goes above (W)", required: true
33 input "cycle_end_power_threshold", "number", title: "Stop cycle when power consumption drops below (W) ...", required: true
34 input "cycle_end_wait", "number", title: "... for at least this long (min)", required: true
37 section ("Send this message") {
38 input "message", "text", title: "Notification message", description: "Laudry is done!", required: true
41 section ("Notification method") {
42 input "sendPushMessage", "bool", title: "Send a push notification?"
45 section ("Additionally", hidden: hideOptionsSection(), hideable: true) {
46 input "phone", "phone", title: "Send a text message to:", required: false
47 input "switches", "capability.switch", title: "Turn on this switch", required:false, multiple:true
48 input "hues", "capability.colorControl", title: "Turn these hue bulbs", required:false, multiple:true
49 input "color", "enum", title: "This color", required: false, multiple:false, options: ["White", "Red","Green","Blue","Yellow","Orange","Purple","Pink"]
50 input "lightLevel", "enum", title: "This light Level", required: false, options: [10,20,30,40,50,60,70,80,90,100]
51 input "speech", "capability.speechSynthesis", title:"Speak message via: ", multiple: true, required: false
56 log.debug "Installed with settings: ${settings}"
62 log.debug "Updated with settings: ${settings}"
69 subscribe(meter, "power", handler)
73 def latestPower = meter.currentValue("power")
74 log.trace "Power: ${latestPower}W"
76 if (!state.cycleOn && latestPower > cycle_start_power_threshold) {
79 // If power drops below threshold, wait for a few minutes.
80 else if (state.cycleOn && latestPower <= cycle_end_power_threshold) {
81 runIn(cycle_end_wait * 60, cycleOff)
85 private cycleOn(evc) {
87 log.trace "Cycle started."
90 private cycleOff(evt) {
91 def latestPower = meter.currentValue("power")
92 log.trace "Power: ${latestPower}W"
94 // If power is still below threshold, end cycle.
95 if (state.cycleOn && latestPower <= cycle_end_power_threshold) {
97 log.trace "Cycle ended."
105 private lightAlert(evt) {
153 state.previous[it.id] = [
154 "switch": it.currentValue("switch"),
155 "level" : it.currentValue("level"),
156 "hue": it.currentValue("hue"),
157 "saturation": it.currentValue("saturation")
161 log.debug "current values = $state.previous"
163 def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
164 log.debug "new value = $newValue"
169 hues*.setColor(newValue)
173 private speechAlert(msg) {
178 if (sendPushMessage) {
189 private hideOptionsSection() {