I see the battery reports, so we’re getting somewhere.
/**
* PetSafe Smart Door
*
* Copyright 2015 Scott Gibson
*
* 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 {
// Automatically generated. Make future change here.
definition (name: "PetSafe Smart Door", namespace: "sticks18", author: "Scott Gibson") {
capability "Battery"
capability "Polling"
capability "Actuator"
capability "Refresh"
capability "Lock"
fingerprint profileId: "0104", inClusters: "0000 0001 0003 0009 000A 0101", outClusters: "0000 0001 0003 0009 000A 0101"
}
simulator {
/* // status "locked": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
// status "unlocked": "command: 9881, payload: 00 62 03 00 00 00 FE FE"
// reply "9881006201FF,delay 4200,9881006202": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
// reply "988100620100,delay 4200,9881006202": "command: 9881, payload: 00 62 03 00 00 00 FE FE" */
}
tiles {
standardTile("toggle", "device.lock", width: 2, height: 2) {
state "locked", label:'locked', action:"lock.unlock", icon:"st.locks.lock.locked", backgroundColor:"#79b821", nextState:"unlocking"
state "unlocked", label:'unlocked', action:"lock.lock", icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff", nextState:"locking"
state "unknown", label:"unknown", action:"lock.lock", icon:"st.locks.lock.unknown", backgroundColor:"#ffffff", nextState:"locking"
state "locking", label:'locking', icon:"st.locks.lock.locked", backgroundColor:"#79b821"
state "unlocking", label:'unlocking', icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff"
}
standardTile("lock", "device.lock", inactiveLabel: false, decoration: "flat") {
state "default", label:'lock', action:"lock.lock", icon:"st.locks.lock.locked", nextState:"locking"
}
standardTile("unlock", "device.lock", inactiveLabel: false, decoration: "flat") {
state "default", label:'unlock', action:"lock.unlock", icon:"st.locks.lock.unlocked", nextState:"unlocking"
}
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat") {
state "battery", label:'${currentValue}% battery', unit:""
}
standardTile("refresh", "device.lock", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "toggle"
details(["toggle", "lock", "unlock", "battery", "refresh"])
}
}
// parse events into attributes
def parse(String description) {
log.trace description
def msg = zigbee.parse(description)
log.trace msg
// TODO: handle 'battery' attribute
// TODO: handle 'lock' attribute
}
// handle commands
def poll() {
log.debug "Executing 'poll'"
refresh()
}
def refresh() {
[
"st rattr 0x${device.deviceNetworkId} 0x0C 0x0101 0", "delay 500",
"st rattr 0x${device.deviceNetworkId} 0x0C 1 0x20"
]
}
def updated() {
configure()
}
def lock() {
log.debug "Executing 'lock'"
sendEvent(name: "lock", value: "locked")
"st cmd 0x${device.deviceNetworkId} 0x0C 0x0101 0 {}"
}
def unlock() {
log.debug "Executing 'unlock'"
sendEvent(name: "lock", value: "unlocked")
"st cmd 0x${device.deviceNetworkId} 0x0C 0x0101 1 {}"
}
def configure() {
String zigbeeId = swapEndianHex(device.hub.zigbeeId)
log.debug "Confuguring Reporting and Bindings."
def configCmds = [
//Lock Reporting
"zcl global send-me-a-report 0101 0 0x30 0 3600 {01}", "delay 500",
"send 0x${device.deviceNetworkId} 1 1", "delay 1000",
//Battery Reporting
"zcl global send-me-a-report 1 0x20 0x20 5 3600 {}", "delay 200",
"send 0x${device.deviceNetworkId} 1 1", "delay 1500",
"zdo bind 0x${device.deviceNetworkId} 1 1 0101 {${device.zigbeeId}} {}", "delay 500",
"zdo bind 0x${device.deviceNetworkId} 1 1 1 {${device.zigbeeId}} {}"
]
return configCmds + refresh() // send refresh cmds as part of config
}
private hex(value, width=2) {
def s = new BigInteger(Math.round(value).toString()).toString(16)
while (s.size() < width) {
s = "0" + s
}
s
}
private Integer convertHexToInt(hex) {
Integer.parseInt(hex,16)
}
private String swapEndianHex(String hex) {
reverseArray(hex.decodeHex()).encodeHex()
}
private byte[] reverseArray(byte[] array) {
int i = 0;
int j = array.length - 1;
byte tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
return array
}
private getEndpointId() {
new BigInteger(device.endpointId, 16).toString()
}