Compare commits

...

1 Commits

Author SHA1 Message Date
Kumar Balabhadra
15fd775d5b null: To enable the Aeotec Smart Dimmer 6 plug on Smart Thinfs 2019-01-11 15:22:23 -08:00

View File

@@ -0,0 +1,462 @@
/*
* V 0.1 of Aeon Smart Dimmer 6 code 10/6/2015
* 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.
*
* some code used from various SmartThings device type and metering code from ElasticDev
*
*/
metadata {
definition (name: "Aeon Smart Dimmer 6 - RV v0.1", namespace: "robertvandervoort", author: "Robert Vandervoort") {
capability "Energy Meter"
capability "Power Meter"
capability "Actuator"
capability "Switch"
capability "Switch Level"
capability "Color Control"
capability "Configuration"
capability "Polling"
capability "Refresh"
capability "Sensor"
command "reset"
/* Capability notes
0x26 COMMAND_CLASS_SWITCH_MULTILEVEL 2
0x27 COMMAND_CLASS_SWITCH_ALL 1
0x32 COMMAND_CLASS_METER 3
0x33 COMMAND_CLASS_COLOR_SWITCH 3
0x59 COMMAND_CLASS_ASSOCIATION_GRP_INFO 1
0x5A COMMAND_CLASS_DEVICE_RESET_LOCALLY 1
0x5E COMMAND_CLASS_ZWAVE_PLUS_INFO 2
0x60 Multi Channel Command Class (V3)
0x70 COMMAND_CLASS_CONFIGURATION 1
0x72 COMMAND_CLASS_MANUFACTURER_SPECIFIC 2
0x73 COMMAND_CLASS_POWERLEVEL 1
0x7A COMMAND_CLASS_FIRMWARE_UPDATE_MD 2
0x81 COMMAND_CLASS_CLOCK 1
0x82 COMMAND_CLASS_HAIL 1
0x8E COMMAND_CLASS_MULTI_INSTANCE_ASSOCIATION 2
0x85 COMMAND_CLASS_ASSOCIATION 2
0x86 COMMAND_CLASS_VERSION 2
0xEF COMMAND_CLASS_MARK 1
*/
fingerprint deviceId: "0x1101", inClusters: "0x98"
fingerprint inClusters: "0x26,0x27,0x32,0x33,0x59,0x5A,0x5E,0x60,0x70,0x72,0x73,0x7A,0x81,0x8E,0x85,0x86,0xEF", outClusters: "0x82"
}
// simulator metadata
simulator {
status "on": "command: 2603, payload: FF"
status "off": "command: 2603, payload: 00"
status "09%": "command: 2603, payload: 09"
status "10%": "command: 2603, payload: 0A"
status "33%": "command: 2603, payload: 21"
status "66%": "command: 2603, payload: 42"
status "99%": "command: 2603, payload: 63"
for (int i = 0; i <= 10000; i += 1000) {
status "power ${i} W":
new physicalgraph.zwave.Zwave().meterV3.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().meterV3.meterReport(scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage()
}
// reply messages
["FF", "00", "09", "0A", "21", "42", "63"].each { val -> reply "2001$val,delay 100,2602": "command: 2603, payload: $val" }
}
// tile definitions
tiles (scale: 2) {
multiAttributeTile(name:"main", type:"lighting", width:6, height:4, canChangeIcon: true) {
tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00a0dc"
attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
tileAttribute("device.power", key: "SECONDARY_CONTROL") {
attributeState "default",label:'${currentValue} W'
}
}
valueTile("energy", "device.energy", decoration: "flat", width: 2, height: 2) {
state "default", label:'${currentValue} kWh', action:"poll"
}
valueTile("current", "device.current", decoration: "flat", width: 2, height: 2) {
state "default", label:'${currentValue} A', action:"poll"
}
valueTile("voltage", "device.voltage", decoration: "flat", width: 2, height: 2) {
state "default", label:'${currentValue} V', action:"poll"
}
controlTile("rgbSelector", "device.color", "color", height: 2, width: 2, inactiveLabel: false) {
state "color", action:"setColor"
}
standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:'reset kWh', action:"reset"
}
standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
}
standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "main","energy","current","voltage"
details(["main","energy","current","voltage","rgbSelector","reset","refresh","configure"])
}
preferences {
input "ledBehavior", "integer",
title: "LED Behavior",
description: "0=energy tracking, 1=momentary status, 2=night light",
defaultValue: 0,
displayDuringSetup: true,
range: "0..2"
input "monitorInterval", "integer",
title: "Monitoring Interval",
description: "The time interval in seconds for sending device reports",
defaultValue: 60,
range: "1..4294967295",
required: false,
displayDuringSetup: true
input "ledBrightness", "integer",
title: "LED Brightness",
description: "Set the % brightness of indicator LEDs",
defaultValue: 50,
range: "0..100",
required: false,
displayduringSetup: true
input "debugOutput", "boolean",
title: "Enable debug logging?",
defaultValue: false,
displayDuringSetup: true
}
}
def updated()
{
state.debug = ("true" == debugOutput)
if (state.sec && !isConfigured()) {
// in case we miss the SCSR
response(configure())
}
}
def parse(String description)
{
def result = null
if (description.startsWith("Err 106")) {
state.sec = 0
result = createEvent( name: "secureInclusion", value: "failed", isStateChange: true,
descriptionText: "This sensor failed to complete the network security key exchange. If you are unable to control it via SmartThings, you must remove it from your network and add it again.")
} else if (description != "updated") {
def cmd = zwave.parse(description, [0x25: 1, 0x26: 1, 0x27: 1, 0x32: 3, 0x33: 3, 0x59: 1, 0x70: 1, 0x72: 2, 0x73: 1, 0x82: 1, 0x85: 2, 0x86: 2])
if (cmd) {
result = zwaveEvent(cmd)
}
}
// if (state.debug) log.debug "Parsed '${description}' to ${result.inspect()}"
return result
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand([0x25: 1, 0x26: 1, 0x27: 1, 0x32: 3, 0x33: 3, 0x59: 1, 0x70: 1, 0x72: 2, 0x73: 1, 0x82: 1, 0x85: 2, 0x86: 2])
state.sec = 1
if (state.debug) log.debug "encapsulated: ${encapsulatedCommand}"
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
} else {
log.warn "Unable to extract encapsulated cmd from $cmd"
createEvent(descriptionText: cmd.toString())
}
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
response(configure())
}
def zwaveEvent(physicalgraph.zwave.commands.powerlevelv1.PowerlevelTestNodeReport cmd) {
if (state.debug) log.debug "===Power level test node report received=== ${device.displayName}: statusOfOperation: ${cmd.statusOfOperation} testFrameCount: ${cmd.testFrameCount} testNodeid: ${cmd.testNodeid}"
def request = [
physicalgraph.zwave.commands.powerlevelv1.PowerlevelGet()
]
response(commands(request))
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationReport cmd) {
if (state.debug) log.debug "---CONFIGURATION REPORT V2--- ${device.displayName} parameter ${cmd.parameterNumber} with a byte size of ${cmd.size} is set to ${cmd.configurationValue}"
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
if (state.debug) log.debug "---CONFIGURATION REPORT V1--- ${device.displayName} parameter ${cmd.parameterNumber} with a byte size of ${cmd.size} is set to ${cmd.configurationValue}"
}
def zwaveEvent(physicalgraph.zwave.commands.meterv3.MeterReport cmd) {
def meterTypes = ["Unknown", "Electric", "Gas", "Water"]
def electricNames = ["energy", "energy", "power", "count", "voltage", "current", "powerFactor", "unknown"]
def electricUnits = ["kWh", "kVAh", "W", "pulses", "V", "A", "Power Factor", ""]
//NOTE ScaledPreviousMeterValue does not always contain a value
def previousValue = cmd.scaledPreviousMeterValue ?: 0
def map = [ name: electricNames[cmd.scale], unit: electricUnits[cmd.scale], displayed: state.display]
switch(cmd.scale) {
case 0: //kWh
previousValue = device.currentValue("energy") ?: cmd.scaledPreviousMeterValue ?: 0
map.value = cmd.scaledMeterValue
break;
case 1: //kVAh
map.value = cmd.scaledMeterValue
break;
case 2: //Watts
previousValue = device.currentValue("power") ?: cmd.scaledPreviousMeterValue ?: 0
map.value = Math.round(cmd.scaledMeterValue)
break;
case 3: //pulses
map.value = Math.round(cmd.scaledMeterValue)
break;
case 4: //Volts
previousValue = device.currentValue("voltage") ?: cmd.scaledPreviousMeterValue ?: 0
map.value = cmd.scaledMeterValue
break;
case 5: //Amps
previousValue = device.currentValue("current") ?: cmd.scaledPreviousMeterValue ?: 0
map.value = cmd.scaledMeterValue
break;
case 6: //Power Factor
previousValue = device.currentValue("powerFactor") ?: cmd.scaledPreviousMeterValue ?: 0
map.value = cmd.scaledMeterValue
break;
case 7: //Unknown
map.value = cmd.scaledMeterValue
break;
default:
break;
}
//Check if the value has changed by more than 5%, if so mark as a stateChange
//map.isStateChange = ((cmd.scaledMeterValue - previousValue).abs() > (cmd.scaledMeterValue * 0.05))
createEvent(map)
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd)
{
[name: "switch", value: cmd.value ? "on" : "off", type: "physical", displayed: true, isStateChange: true]
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd)
{
[name: "switch", value: cmd.value ? "on" : "off", type: "physical", displayed: true, isStateChange: true]
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
{
[name: "switch", value: cmd.value ? "on" : "off", type: "digital", displayed: true, isStateChange: true]
}
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd)
{
[name: "level", value: cmd.value, type: "digital", displayed: true, isStateChange: true]
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinarySet cmd)
{
[name: "switch", value: cmd.value ? "on" : "off", type: "digital", displayed: true, isStateChange: true]
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
if (state.debug) log.debug "Unhandled: $cmd sent to ${device.displayName}"
createEvent(descriptionText: cmd.toString(), isStateChange: false)
}
def on() {
if (state.debug) log.debug "turning on ${device.displayName}"
def request = [
zwave.basicV1.basicSet(value: 0xFF),
zwave.basicV1.basicGet(),
zwave.switchBinaryV1.switchBinaryGet(),
zwave.switchMultilevelV1.switchMultilevelGet()
]
commands(request)
}
def off() {
if (state.debug) log.debug "turning off ${device.displayName}"
def request = [
zwave.basicV1.basicSet(value: 0x00),
zwave.basicV1.basicGet(),
zwave.switchBinaryV1.switchBinaryGet(),
zwave.switchMultilevelV1.switchMultilevelGet()
]
commands(request)
}
def setLevel(value) {
if (state.debug) log.debug "setting level to ${value} on ${device.displayName}"
def valueaux = value as Integer
def level = Math.min(valueaux, 99)
def request = [
zwave.basicV1.basicSet(value: level),
zwave.switchMultilevelV1.switchMultilevelGet()
]
commands(request)
}
def setLevel(value, duration) {
def valueaux = value as Integer
def level = Math.min(valueaux, 99)
def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
def request = [
zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: dimmingDuration)
]
commands(request)
}
def setColor(value) {
def result = []
if (state.debug) log.debug "setColor: ${value}"
if (value.hex) {
def c = value.hex.findAll(/[0-9a-fA-F]{2}/).collect { Integer.parseInt(it, 16) }
result << zwave.configurationV1.configurationSet(parameterNumber: 83, size: 3, configurationValue: [c[0], c[1], c[2]])
}
if(value.hex) sendEvent(name: "color", value: value.hex)
commands(result)
}
def poll() {
if (state.debug) log.debug "poll request sent to ${device.displayName}"
def request = [
zwave.switchBinaryV1.switchBinaryGet(),
zwave.basicV1.basicGet(),
zwave.switchMultilevelV1.switchMultilevelGet(),
zwave.meterV3.meterGet(scale: 0), //kWh
zwave.meterV3.meterGet(scale: 1), //kVAh
zwave.meterV3.meterGet(scale: 2), //Wattage
zwave.meterV3.meterGet(scale: 4), //Volts
zwave.meterV3.meterGet(scale: 5), //Amps
zwave.meterV3.meterGet(scale: 6) //Power Factor
]
commands(request)
}
def refresh() {
if (state.debug) log.debug "refresh request sent to ${device.displayName}"
def request = [
zwave.basicV1.basicGet(),
zwave.switchMultilevelV1.switchMultilevelGet(),
zwave.switchBinaryV1.switchBinaryGet()
]
commands(request)
}
def reset() {
if (state.debug) log.debug "reset request sent to ${device.displayName}"
def request = [
zwave.meterV3.meterReset(),
zwave.meterV3.meterGet(scale: 0), //kWh
zwave.meterV3.meterGet(scale: 1), //kVAh
zwave.meterV3.meterGet(scale: 2), //Wattage
zwave.meterV3.meterGet(scale: 4), //Volts
zwave.meterV3.meterGet(scale: 5), //Amps
zwave.meterV3.meterGet(scale: 6) //Power Factor
]
commands(request)
}
def configure() {
if (state.debug) {
if (state.sec) {
log.debug "secure configuration being sent to ${device.displayName}"
}
else
if (state.debug) log.debug "configuration being sent to ${device.displayName}"
}
def monitorInt = 60
if (monitorInterval) {
monitorInt=monitorInterval.toInteger()
}
def ledBehave = 0
if (ledBehavior) {
ledBehave=ledBehavior.toInteger()
}
def ledBright = 50
if (ledBrightness) {
ledBright=ledBrightness.toInteger()
}
if (state.debug) log.debug "Sending configure commands - monitorInterval '${monitorInt}', ledBehavior '${ledBehave}'"
def request = [
// Reset switch configuration to defaults
// zwave.configurationV1.configurationSet(parameterNumber: 255, size: 1, scaledConfigurationValue: 1),
// Enable to send notifications to associated devices (Group 1) when the state of Micro Switchs load changed (0=nothing, 1=hail CC, 2=basic CC report)
zwave.configurationV1.configurationSet(parameterNumber: 80, size: 1, configurationValue: [2]),
// set LED behavior 0 energy mode 1 momentary display 2 night light
zwave.configurationV1.configurationSet(parameterNumber: 81, size: 1, scaledConfigurationValue: ledBehave),
// Set LED brightness
zwave.configurationV1.configurationSet(parameterNumber: 84, size: 3, configurationValue: [ledBright,ledBright,ledBright]),
// Which reports need to send in Report group 1
zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 4|2|1),
// Which reports need to send in Report group 2
zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 8),
// Which reports need to send in Report group 3
zwave.configurationV1.configurationSet(parameterNumber: 103, size: 4, scaledConfigurationValue: 0),
// Interval to send Report group 1
zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue: monitorInt),
// Interval to send Report group 2
zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue: 60),
// Interval to send Report group 3
zwave.configurationV1.configurationSet(parameterNumber: 113, size: 4, scaledConfigurationValue: 0),
// get notification behavior
zwave.configurationV1.configurationGet(parameterNumber: 80),
// get LED behavior
zwave.configurationV1.configurationGet(parameterNumber: 81),
// get night light RGB value
zwave.configurationV1.configurationGet(parameterNumber: 83),
// get Energy Mode/momentary indicate LED brightness value
zwave.configurationV1.configurationGet(parameterNumber: 84),
// Which reports need to send in Report group 1
zwave.configurationV1.configurationGet(parameterNumber: 101),
// Which reports need to send in Report group 2
zwave.configurationV1.configurationGet(parameterNumber: 102),
// Which reports need to send in Report group 3
zwave.configurationV1.configurationGet(parameterNumber: 103),
// Interval to send Report group 1
zwave.configurationV1.configurationGet(parameterNumber: 111),
// Interval to send Report group 2
zwave.configurationV1.configurationGet(parameterNumber: 112),
// Interval to send Report group 3
zwave.configurationV1.configurationGet(parameterNumber: 113),
// Can use the zwaveHubNodeId variable to add the hub to the device's associations:
zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId)
]
commands(request)
}
private setConfigured() {
updateDataValue("configured", "true")
}
private isConfigured() {
getDataValue("configured") == "true"
}
private command(physicalgraph.zwave.Command cmd) {
if (state.sec) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}
private commands(commands, delay=500) {
delayBetween(commands.collect{ command(it) }, delay)
}