From a27ca03eddde53401721321548acba509a3c48e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=ED=98=84=EC=88=98?= Date: Sun, 17 Apr 2016 19:33:41 -0500 Subject: [PATCH] MSA-1189: test --- .../aeon-home-energy-meter.groovy | 236 +++++++------- .../the-flasher.src/the-flasher.groovy | 299 +++++++++--------- 2 files changed, 267 insertions(+), 268 deletions(-) diff --git a/devicetypes/smartthings/aeon-home-energy-meter.src/aeon-home-energy-meter.groovy b/devicetypes/smartthings/aeon-home-energy-meter.src/aeon-home-energy-meter.groovy index 8d3abbd..a87655a 100644 --- a/devicetypes/smartthings/aeon-home-energy-meter.src/aeon-home-energy-meter.groovy +++ b/devicetypes/smartthings/aeon-home-energy-meter.src/aeon-home-energy-meter.groovy @@ -1,118 +1,118 @@ -/** - * Copyright 2015 SmartThings - * - * 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: - * - * 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 - * 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. - * - * Aeon Home Energy Meter - * - * Author: SmartThings - * - * Date: 2013-05-30 - */ -metadata { - definition (name: "Aeon Home Energy Meter", namespace: "smartthings", author: "SmartThings") { - capability "Energy Meter" - capability "Power Meter" - capability "Configuration" - capability "Sensor" - - command "reset" - - fingerprint deviceId: "0x2101", inClusters: " 0x70,0x31,0x72,0x86,0x32,0x80,0x85,0x60" - } - - // simulator metadata - simulator { - for (int i = 0; i <= 10000; i += 1000) { - status "power ${i} W": new physicalgraph.zwave.Zwave().meterV1.meterReport( - scaledMeterValue: i, precision: 3, meterType: 4, scale: 2, size: 4).incomingMessage() - } - for (int i = 0; i <= 100; i += 10) { - status "energy ${i} kWh": new physicalgraph.zwave.Zwave().meterV1.meterReport( - scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage() - } - } - - // tile definitions - tiles { - valueTile("power", "device.power", decoration: "flat") { - state "default", label:'${currentValue} W' - } - valueTile("energy", "device.energy", decoration: "flat") { - state "default", label:'${currentValue} kWh' - } - standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat") { - state "default", label:'reset kWh', action:"reset" - } - standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat") { - state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh" - } - standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat") { - state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure" - } - - main (["power","energy"]) - details(["power","energy", "reset","refresh", "configure"]) - } -} - -def parse(String description) { - def result = null - def cmd = zwave.parse(description, [0x31: 1, 0x32: 1, 0x60: 3]) - if (cmd) { - result = createEvent(zwaveEvent(cmd)) - } - log.debug "Parse returned ${result?.descriptionText}" - return result -} - -def zwaveEvent(physicalgraph.zwave.commands.meterv1.MeterReport cmd) { - if (cmd.scale == 0) { - [name: "energy", value: cmd.scaledMeterValue, unit: "kWh"] - } else if (cmd.scale == 1) { - [name: "energy", value: cmd.scaledMeterValue, unit: "kVAh"] - } - else { - [name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W"] - } -} - -def zwaveEvent(physicalgraph.zwave.Command cmd) { - // Handles all Z-Wave commands we aren't interested in - [:] -} - -def refresh() { - delayBetween([ - zwave.meterV2.meterGet(scale: 0).format(), - zwave.meterV2.meterGet(scale: 2).format() - ]) -} - -def reset() { - // No V1 available - return [ - zwave.meterV2.meterReset().format(), - zwave.meterV2.meterGet(scale: 0).format() - ] -} - -def configure() { - def cmd = delayBetween([ - zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 4).format(), // combined power in watts - zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue: 300).format(), // every 5 min - zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 8).format(), // combined energy in kWh - zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue: 300).format(), // every 5 min - zwave.configurationV1.configurationSet(parameterNumber: 103, size: 4, scaledConfigurationValue: 0).format(), // no third report - zwave.configurationV1.configurationSet(parameterNumber: 113, size: 4, scaledConfigurationValue: 300).format() // every 5 min - ]) - log.debug cmd - cmd -} +/** + * Copyright 2015 SmartThings + * + * 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: + * + * 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 + * 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. + * + * Aeon Home Energy Meter + * + * Author: SmartThings + * + * Date: 2013-05-30 + */ +metadata { + definition (name: "Aeon Home Energy Meter", namespace: "smartthings", author: "SmartThings") { + capability "Energy Meter" + capability "Power Meter" + capability "Configuration" + capability "Sensor" + + command "reset" + + fingerprint deviceId: "0x2101", inClusters: " 0x70,0x31,0x72,0x86,0x32,0x80,0x85,0x60" + } + + // simulator metadata + simulator { + for (int i = 0; i <= 10000; i += 1000) { + status "power ${i} W": new physicalgraph.zwave.Zwave().meterV1.meterReport( + scaledMeterValue: i, precision: 3, meterType: 4, scale: 2, size: 4).incomingMessage() + } + for (int i = 0; i <= 100; i += 10) { + status "energy ${i} kWh": new physicalgraph.zwave.Zwave().meterV1.meterReport( + scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage() + } + } + + // tile definitions + tiles { + valueTile("power", "device.power", decoration: "flat") { + state "default", label:'${currentValue} W' + } + valueTile("energy", "device.energy", decoration: "flat") { + state "default", label:'${currentValue} kWh' + } + standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat") { + state "default", label:'reset kWh', action:"reset" + } + standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat") { + state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh" + } + standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat") { + state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure" + } + + main (["power","energy"]) + details(["power","energy", "reset","refresh", "configure"]) + } +} + +def parse(String description) { + def result = null + def cmd = zwave.parse(description, [0x31: 1, 0x32: 1, 0x60: 3]) + if (cmd) { + result = createEvent(zwaveEvent(cmd)) + } + log.debug "Parse returned ${result?.descriptionText}" + return result +} + +def zwaveEvent(physicalgraph.zwave.commands.meterv1.MeterReport cmd) { + if (cmd.scale == 0) { + [name: "energy", value: cmd.scaledMeterValue, unit: "kWh"] + } else if (cmd.scale == 1) { + [name: "energy", value: cmd.scaledMeterValue, unit: "kVAh"] + } + else { + [name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W"] + } +} + +def zwaveEvent(physicalgraph.zwave.Command cmd) { + // Handles all Z-Wave commands we aren't interested in + [:] +} + +def refresh() { + delayBetween([ + zwave.meterV2.meterGet(scale: 0).format(), + zwave.meterV2.meterGet(scale: 2).format() + ]) +} + +def reset() { + // No V1 available + return [ + zwave.meterV2.meterReset().format(), + zwave.meterV2.meterGet(scale: 0).format() + ] +} + +def configure() { + def cmd = delayBetween([ + zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 4).format(), // combined power in watts + zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue: 300).format(), // every 5 min + zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 8).format(), // combined energy in kWh + zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue: 300).format(), // every 5 min + zwave.configurationV1.configurationSet(parameterNumber: 103, size: 4, scaledConfigurationValue: 0).format(), // no third report + zwave.configurationV1.configurationSet(parameterNumber: 113, size: 4, scaledConfigurationValue: 300).format() // every 5 min + ]) + log.debug cmd + cmd +} \ No newline at end of file diff --git a/smartapps/smartthings/the-flasher.src/the-flasher.groovy b/smartapps/smartthings/the-flasher.src/the-flasher.groovy index 60feb4c..d5bba77 100644 --- a/smartapps/smartthings/the-flasher.src/the-flasher.groovy +++ b/smartapps/smartthings/the-flasher.src/the-flasher.groovy @@ -1,150 +1,149 @@ -/** - * Copyright 2015 SmartThings - * - * 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: - * - * 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 - * 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. - * - * The Flasher - * - * Author: bob - * Date: 2013-02-06 - */ -definition( - name: "The Flasher", - namespace: "smartthings", - author: "SmartThings", - description: "Flashes a set of lights in response to motion, an open/close event, or a switch.", - category: "Convenience", - iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-contact.png", - iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-contact@2x.png" -) - -preferences { - section("When any of the following devices trigger..."){ - input "motion", "capability.motionSensor", title: "Motion Sensor?", required: false - input "contact", "capability.contactSensor", title: "Contact Sensor?", required: false - input "acceleration", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false - input "mySwitch", "capability.switch", title: "Switch?", required: false - input "myPresence", "capability.presenceSensor", title: "Presence Sensor?", required: false - } - section("Then flash..."){ - input "switches", "capability.switch", title: "These lights", multiple: true - input "numFlashes", "number", title: "This number of times (default 3)", required: false - } - section("Time settings in milliseconds (optional)..."){ - input "onFor", "number", title: "On for (default 1000)", required: false - input "offFor", "number", title: "Off for (default 1000)", required: false - } -} - -def installed() { - log.debug "Installed with settings: ${settings}" - - subscribe() -} - -def updated() { - log.debug "Updated with settings: ${settings}" - - unsubscribe() - subscribe() -} - -def subscribe() { - if (contact) { - subscribe(contact, "contact.open", contactOpenHandler) - } - if (acceleration) { - subscribe(acceleration, "acceleration.active", accelerationActiveHandler) - } - if (motion) { - subscribe(motion, "motion.active", motionActiveHandler) - } - if (mySwitch) { - subscribe(mySwitch, "switch.on", switchOnHandler) - } - if (myPresence) { - subscribe(myPresence, "presence", presenceHandler) - } -} - -def motionActiveHandler(evt) { - log.debug "motion $evt.value" - flashLights() -} - -def contactOpenHandler(evt) { - log.debug "contact $evt.value" - flashLights() -} - -def accelerationActiveHandler(evt) { - log.debug "acceleration $evt.value" - flashLights() -} - -def switchOnHandler(evt) { - log.debug "switch $evt.value" - flashLights() -} - -def presenceHandler(evt) { - log.debug "presence $evt.value" - if (evt.value == "present") { - flashLights() - } else if (evt.value == "not present") { - flashLights() - } -} - -private flashLights() { - def doFlash = true - def onFor = onFor ?: 1000 - def offFor = offFor ?: 1000 - def numFlashes = numFlashes ?: 3 - - log.debug "LAST ACTIVATED IS: ${state.lastActivated}" - if (state.lastActivated) { - def elapsed = now() - state.lastActivated - def sequenceTime = (numFlashes + 1) * (onFor + offFor) - doFlash = elapsed > sequenceTime - log.debug "DO FLASH: $doFlash, ELAPSED: $elapsed, LAST ACTIVATED: ${state.lastActivated}" - } - - if (doFlash) { - log.debug "FLASHING $numFlashes times" - state.lastActivated = now() - log.debug "LAST ACTIVATED SET TO: ${state.lastActivated}" - def initialActionOn = switches.collect{it.currentSwitch != "on"} - def delay = 0L - numFlashes.times { - log.trace "Switch on after $delay msec" - switches.eachWithIndex {s, i -> - if (initialActionOn[i]) { - s.on(delay: delay) - } - else { - s.off(delay:delay) - } - } - delay += onFor - log.trace "Switch off after $delay msec" - switches.eachWithIndex {s, i -> - if (initialActionOn[i]) { - s.off(delay: delay) - } - else { - s.on(delay:delay) - } - } - delay += offFor - } - } -} - +/** + * Copyright 2015 SmartThings + * + * 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: + * + * 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 + * 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. + * + * The Flasher + * + * Author: bob + * Date: 2013-02-06 + */ +definition( + name: "The Flasher", + namespace: "smartthings", + author: "SmartThings", + description: "Flashes a set of lights in response to motion, an open/close event, or a switch.", + category: "Convenience", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-contact.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-contact@2x.png" +) + +preferences { + section("When any of the following devices trigger..."){ + input "motion", "capability.motionSensor", title: "Motion Sensor?", required: false + input "contact", "capability.contactSensor", title: "Contact Sensor?", required: false + input "acceleration", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false + input "mySwitch", "capability.switch", title: "Switch?", required: false + input "myPresence", "capability.presenceSensor", title: "Presence Sensor?", required: false + } + section("Then flash..."){ + input "switches", "capability.switch", title: "These lights", multiple: true + input "numFlashes", "number", title: "This number of times (default 3)", required: false + } + section("Time settings in milliseconds (optional)..."){ + input "onFor", "number", title: "On for (default 1000)", required: false + input "offFor", "number", title: "Off for (default 1000)", required: false + } +} + +def installed() { + log.debug "Installed with settings: ${settings}" + + subscribe() +} + +def updated() { + log.debug "Updated with settings: ${settings}" + + unsubscribe() + subscribe() +} + +def subscribe() { + if (contact) { + subscribe(contact, "contact.open", contactOpenHandler) + } + if (acceleration) { + subscribe(acceleration, "acceleration.active", accelerationActiveHandler) + } + if (motion) { + subscribe(motion, "motion.active", motionActiveHandler) + } + if (mySwitch) { + subscribe(mySwitch, "switch.on", switchOnHandler) + } + if (myPresence) { + subscribe(myPresence, "presence", presenceHandler) + } +} + +def motionActiveHandler(evt) { + log.debug "motion $evt.value" + flashLights() +} + +def contactOpenHandler(evt) { + log.debug "contact $evt.value" + flashLights() +} + +def accelerationActiveHandler(evt) { + log.debug "acceleration $evt.value" + flashLights() +} + +def switchOnHandler(evt) { + log.debug "switch $evt.value" + flashLights() +} + +def presenceHandler(evt) { + log.debug "presence $evt.value" + if (evt.value == "present") { + flashLights() + } else if (evt.value == "not present") { + flashLights() + } +} + +private flashLights() { + def doFlash = true + def onFor = onFor ?: 1000 + def offFor = offFor ?: 1000 + def numFlashes = numFlashes ?: 3 + + log.debug "LAST ACTIVATED IS: ${state.lastActivated}" + if (state.lastActivated) { + def elapsed = now() - state.lastActivated + def sequenceTime = (numFlashes + 1) * (onFor + offFor) + doFlash = elapsed > sequenceTime + log.debug "DO FLASH: $doFlash, ELAPSED: $elapsed, LAST ACTIVATED: ${state.lastActivated}" + } + + if (doFlash) { + log.debug "FLASHING $numFlashes times" + state.lastActivated = now() + log.debug "LAST ACTIVATED SET TO: ${state.lastActivated}" + def initialActionOn = switches.collect{it.currentSwitch != "on"} + def delay = 0L + numFlashes.times { + log.trace "Switch on after $delay msec" + switches.eachWithIndex {s, i -> + if (initialActionOn[i]) { + s.on(delay: delay) + } + else { + s.off(delay:delay) + } + } + delay += onFor + log.trace "Switch off after $delay msec" + switches.eachWithIndex {s, i -> + if (initialActionOn[i]) { + s.off(delay: delay) + } + else { + s.on(delay:delay) + } + } + delay += offFor + } + } +} \ No newline at end of file