Skip to content

Commit

Permalink
Merge pull request SmartThingsCommunity#14 from larsfinander/echoInte…
Browse files Browse the repository at this point in the history
…gration

Updated heartbeat for OSRAM bulb and Smartpower Outlet
  • Loading branch information
workingmonk committed Aug 7, 2015
2 parents 0a9a86e + b1368af commit e2570e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ metadata {
capability "Switch"
capability "Switch Level"
capability "Configuration"
capability "Polling"
capability "Refresh"
capability "Sensor"

attribute "colorName", "string"
// heartbeat is updated at every poll

// indicates that device keeps track of heartbeat (in state.heartbeat)
attribute "heartbeat", "string"


Expand Down Expand Up @@ -75,6 +75,10 @@ metadata {
// Parse incoming device messages to generate events
def parse(String description) {
//log.trace description

// save heartbeat (i.e. last time we got a message from device)
state.heartbeat = Calendar.getInstance().getTimeInMillis()

if (description?.startsWith("catchall:")) {
if(description?.endsWith("0100") ||description?.endsWith("1001") || description?.matches("on/off\\s*:\\s*1"))
{
Expand All @@ -95,21 +99,16 @@ def parse(String description) {
log.trace "descMap : $descMap"

if (descMap.cluster == "0300") {
// trigger heartbeat
def hb = createEvent(name: "heartbeat", value: "alive", isStateChange: true, displayed:false)

log.debug descMap.value
def tempInMired = convertHexToInt(descMap.value)
def tempInKelvin = Math.round(1000000/tempInMired)
log.trace "temp in kelvin: $tempInKelvin"
def result = createEvent(name: "colorTemperature", value: tempInKelvin, displayed:false)
return [result, hb]
sendEvent(name: "colorTemperature", value: tempInKelvin, displayed:false)
}
else if(descMap.cluster == "0008"){
def dimmerValue = Math.round(convertHexToInt(descMap.value) * 100 / 255)
log.debug "dimmer value is $dimmerValue"
def result = createEvent(name: "level", value: dimmerValue)
return result
sendEvent(name: "level", value: dimmerValue)
}
}
else {
Expand All @@ -119,8 +118,6 @@ def parse(String description) {
log.debug "Parse returned ${result?.descriptionText}"
return result
}


}

def on() {
Expand All @@ -136,6 +133,7 @@ def off() {
}

def refresh() {
sendEvent(name: "heartbeat", value: "alive", displayed:false)
[
"st rattr 0x${device.deviceNetworkId} ${endpointId} 6 0", "delay 500",
"st rattr 0x${device.deviceNetworkId} ${endpointId} 8 0", "delay 500",
Expand All @@ -146,22 +144,29 @@ def refresh() {

def configure() {
state.levelValue = 100
log.debug "Confuguring Reporting and Bindings."
log.debug "Configuring Reporting and Bindings."
def configCmds = [
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 0x0300 {${device.zigbeeId}} {}", "delay 500"
]
return onOffConfig() + levelConfig() + configCmds + refresh() // send refresh cmds as part of config
}

//Switch Reporting
"zcl global send-me-a-report 6 0 0x10 0 3600 {01}", "delay 500",
"send 0x${device.deviceNetworkId} ${endpointId} 1", "delay 1000",

//Level Control Reporting
"zcl global send-me-a-report 8 0 0x20 5 3600 {0010}", "delay 200",
"send 0x${device.deviceNetworkId} ${endpointId} 1", "delay 1500",
def onOffConfig() {
[
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 6 {${device.zigbeeId}} {}", "delay 200",
"zcl global send-me-a-report 6 0 0x10 0 300 {01}",
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 1500"
]
}

"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 6 {${device.zigbeeId}} {}", "delay 1000",
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 8 {${device.zigbeeId}} {}", "delay 500",
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 0x0300 {${device.zigbeeId}} {}", "delay 500"
//level config for devices with min reporting interval as 5 seconds and reporting interval if no activity as 1hour (3600s)
//min level change is 01
def levelConfig() {
[
"zdo bind 0x${device.deviceNetworkId} ${endpointId} 1 8 {${device.zigbeeId}} {}", "delay 200",
"zcl global send-me-a-report 8 0 0x20 5 3600 {01}",
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 1500"
]
return configCmds + refresh() // send refresh cmds as part of config
}

def setColorTemperature(value) {
Expand Down Expand Up @@ -190,11 +195,6 @@ def parseDescriptionAsMap(description) {
}
}

def poll(){
log.debug "Poll is calling refresh"
refresh()
}

def setLevel(value) {
state.levelValue = (value==null) ? 100 : value
log.trace "setLevel($value)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata {
capability "Refresh"
capability "Sensor"

// heartbeat is updated every time device checks in
// indicates that device keeps track of heartbeat (in state.heartbeat)
attribute "heartbeat", "string"

fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0B04,0B05", outClusters: "0019"
Expand Down Expand Up @@ -54,6 +54,10 @@ def parse(String description) {
log.debug "Parse description $description"
def name = null
def value = null

// save heartbeat (i.e. last time we got a message from device)
state.heartbeat = Calendar.getInstance().getTimeInMillis()

if (description?.startsWith("read attr -")) {
def descMap = parseDescriptionAsMap(description)
log.debug "Read attr: $description"
Expand All @@ -63,11 +67,8 @@ def parse(String description) {
} else if (descMap.cluster.equalsIgnoreCase("0B04") && descMap.attrId.equalsIgnoreCase("050b")) {
def reportValue = descMap.value
name = "power"
// assume 16 bit signed for encoding and power divisor is 10
//power divisor is 10
value = Integer.parseInt(reportValue, 16) / 10

// trigger heartbeat
sendEvent(name: "heartbeat", value: "alive", isStateChange: true, displayed:false)
}
} else if (description?.startsWith("on/off:")) {
log.debug "Switch command"
Expand Down Expand Up @@ -101,12 +102,16 @@ def meter() {
}

def refresh() {
"st rattr 0x${device.deviceNetworkId} 1 0xB04 0x50B"
sendEvent(name: "heartbeat", value: "alive", displayed:false)
[
"st rattr 0x${device.deviceNetworkId} 1 0xB04 0x50B"
]
}

def configure() {
[
def configCmds = [
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}", "delay 200",
"zdo bind 0x${device.deviceNetworkId} 1 1 0xB04 {${device.zigbeeId}} {}"
"zdo bind 0x${device.deviceNetworkId} 1 1 0xB04 {${device.zigbeeId}} {}", "delay 200"
]
return configCmds + refresh() // send refresh cmds as part of config
}

0 comments on commit e2570e4

Please sign in to comment.