Last active
April 25, 2016 20:44
-
-
Save mitchpond/90b44455cb5a210215b0d00908391721 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Kudled ZigBee Remote | |
* | |
* Copyright 2016 Mitch Pond | |
* | |
* 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. | |
* | |
*/ | |
metadata { | |
definition (name: "Kudled ZigBee Remote", namespace: "mitchpond", author: "Mitch Pond") { | |
capability "Actuator" | |
capability "Button" | |
capability "Configuration" | |
fingerprint endpointId: "0B", profileId: "0104", deviceId: "0800", inClusters: "0000,1000", outClusters: "0003,0004,0005,0006,0008,0300,1000" | |
} | |
simulator { | |
// TODO: define status and reply messages here | |
} | |
preferences{ | |
input "logging", "bool", title: "Enable debug logging", | |
defaultValue: true, displayDuringSetup: false | |
} | |
tiles(scale: 2) { | |
standardTile("button", "device.button", decoration: "flat", width: 2, height: 2) { | |
state "default", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff" | |
} | |
main ("button") | |
details("button") | |
} | |
} | |
// parse events into attributes | |
def parse(String description) { | |
log.debug "Parsing '${description}'" | |
def descMap = zigbee.parseDescriptionAsMap(description) | |
def results = [] | |
if (description?.startsWith('catchall:')) | |
results = parseCatchAllMessage(descMap) | |
else logIt(descMap, "trace") | |
return results | |
} | |
def configure() { | |
logIt "Configuring Kudled Remote..." | |
[ | |
"zdo bind 0x${device.deviceNetworkId} 0x0B 1 4 {${device.zigbeeId}} {}", "delay 200", | |
"zdo bind 0x${device.deviceNetworkId} 0x0B 1 5 {${device.zigbeeId}} {}", "delay 200", | |
"zdo bind 0x${device.deviceNetworkId} 0x0B 1 8 {${device.zigbeeId}} {}", "delay 200", | |
"zdo bind 0x${device.deviceNetworkId} 0x0B 1 0x0300 {${device.zigbeeId}} {}", "delay 200" | |
] + | |
zigbee.onOffConfig() | |
} | |
def updated() { | |
configure() | |
} | |
def parseCatchAllMessage(descMap) { | |
if (descMap?.clusterId == "0006" && descMap?.command == "01") //on button pressed | |
createButtonEvent(1,"pressed") | |
else if (descMap?.clusterId == "0006" && descMap?.command == "00") //off button pressed | |
createButtonEvent(2,"pressed") | |
else logIt("Parse - catchall: Unhandled message: ${descMap}","trace") | |
} | |
private createButtonEvent(button,action) { | |
logIt "Button ${button} ${action}" | |
return createEvent([ | |
name: "button", | |
value: action, | |
data:[buttonNumber: button], | |
descriptionText: "${device.displayName} button ${button} was ${action}", | |
isStateChange: true, | |
displayed: true]) | |
} | |
// ****** Utility functions ****** | |
private logIt(str, logLevel = 'debug') {if (settings.logging) log."$logLevel"(str) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment