mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 21:03:00 +00:00
Compare commits
7 Commits
PROD_2016.
...
MSA-1436-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
554ff50ec8 | ||
|
|
ad50582e92 | ||
|
|
6de6704502 | ||
|
|
a5bc475cc1 | ||
|
|
c7396349f1 | ||
|
|
089cc1a5dd | ||
|
|
ef29820fa1 |
@@ -1,8 +1,7 @@
|
||||
/**
|
||||
* Iris Smart Fob
|
||||
* ZigBee Button
|
||||
*
|
||||
* Copyright 2015 Mitch Pond
|
||||
* Presence code adapted from SmartThings Arrival Sensor HA device type
|
||||
*
|
||||
* 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:
|
||||
@@ -14,181 +13,235 @@
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
metadata {
|
||||
definition (name: "ZigBee Button", namespace: "smartthings", author: "Mitch Pond") {
|
||||
capability "Battery"
|
||||
capability "Button"
|
||||
definition (name: "ZigBee Button", namespace: "smartthings", author: "Mitch Pond") {
|
||||
capability "Actuator"
|
||||
capability "Battery"
|
||||
capability "Button"
|
||||
capability "Configuration"
|
||||
capability "Presence Sensor"
|
||||
capability "Sensor"
|
||||
|
||||
//fingerprint endpointId: "01", profileId: "0104", inClusters: "0000,0001,0003,0007,0020,0B05", outClusters: "0003,0006,0019", model:"3450-L", manufacturer: "CentraLite"
|
||||
}
|
||||
|
||||
preferences{
|
||||
input ("holdTime", "number", title: "Minimum time in seconds for a press to count as \"held\"",
|
||||
defaultValue: 3, displayDuringSetup: false)
|
||||
input "checkInterval", "enum", title: "Presence timeout (minutes)",
|
||||
defaultValue:"2", options: ["2", "3", "5"], displayDuringSetup: false
|
||||
input "logging", "bool", title: "Enable debug logging",
|
||||
defaultValue: false, displayDuringSetup: false
|
||||
capability "Refresh"
|
||||
capability "Sensor"
|
||||
|
||||
command "enrollResponse"
|
||||
|
||||
fingerprint inClusters: "0000, 0001, 0003, 0020, 0402, 0B05", outClusters: "0003, 0006, 0008, 0019", manufacturer: "OSRAM", model: "LIGHTIFY Dimming Switch", deviceJoinName: "OSRAM LIGHTIFY Dimming Switch"
|
||||
//fingerprint inClusters: "0000, 0001, 0003, 0020, 0500", outClusters: "0003,0019", manufacturer: "CentraLite", model: "3455-L", deviceJoinName: "Iris Care Pendant"
|
||||
//fingerprint inClusters: "0000, 0001, 0003, 0007, 0020, 0402, 0B05", outClusters: "0003, 0006, 0019", manufacturer: "CentraLite", model: "3460-L", deviceJoinName: "Iris Smart Button"
|
||||
//fingerprint inClusters: "0000, 0001, 0003, 0007, 0020, 0B05", outClusters: "0003, 0006, 0019", manufacturer: "CentraLite", model:"3450-L", deviceJoinName: "Iris KeyFob"
|
||||
}
|
||||
|
||||
tiles(scale: 2) {
|
||||
standardTile("presence", "device.presence", width: 4, height: 4, canChangeBackground: true) {
|
||||
state "present", label: "Present", labelIcon:"st.presence.tile.present", backgroundColor:"#53a7c0"
|
||||
state "not present", labelIcon:"st.presence.tile.not-present", backgroundColor:"#ffffff"
|
||||
}
|
||||
standardTile("button", "device.button", decoration: "flat", width: 2, height: 2) {
|
||||
state "default", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
|
||||
}
|
||||
valueTile("battery", "device.battery", decoration: "flat", width: 2, height: 2) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
simulator {}
|
||||
|
||||
main (["presence"])
|
||||
details(["presence","button","battery"])
|
||||
}
|
||||
preferences {
|
||||
section {
|
||||
input ("holdTime", "number", title: "Minimum time in seconds for a press to count as \"held\"", defaultValue: 1, displayDuringSetup: false)
|
||||
}
|
||||
}
|
||||
|
||||
tiles {
|
||||
standardTile("button", "device.button", width: 2, height: 2) {
|
||||
state "default", label: "", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
|
||||
state "button 1 pushed", label: "pushed #1", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#79b821"
|
||||
}
|
||||
|
||||
valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
|
||||
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat") {
|
||||
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||
}
|
||||
main (["button"])
|
||||
details(["button", "battery", "refresh"])
|
||||
}
|
||||
}
|
||||
|
||||
def parse(String description) {
|
||||
def descMap = zigbee.parseDescriptionAsMap(description)
|
||||
logIt descMap
|
||||
state.lastCheckin = now()
|
||||
logIt "lastCheckin = ${state.lastCheckin}"
|
||||
handlePresenceEvent(true)
|
||||
|
||||
def results = []
|
||||
if (description?.startsWith('catchall:'))
|
||||
results = parseCatchAllMessage(descMap)
|
||||
else if (description?.startsWith('read attr -'))
|
||||
results = parseReportAttributeMessage(descMap)
|
||||
else logIt(descMap, "trace")
|
||||
|
||||
return results;
|
||||
log.debug "description is $description"
|
||||
def event = zigbee.getEvent(description)
|
||||
if (event) {
|
||||
sendEvent(event)
|
||||
}
|
||||
else {
|
||||
if ((description?.startsWith("catchall:")) || (description?.startsWith("read attr -"))) {
|
||||
def descMap = zigbee.parseDescriptionAsMap(description)
|
||||
if (descMap.clusterInt == 0x0001 && descMap.attrInt == 0x0020) {
|
||||
event = getBatteryResult(zigbee.convertHexToInt(descMap.value))
|
||||
}
|
||||
else if (descMap.clusterInt == 0x0006 || descMap.clusterInt == 0x0008) {
|
||||
event = parseNonIasButtonMessage(descMap)
|
||||
}
|
||||
}
|
||||
else if (description?.startsWith('zone status')) {
|
||||
event = parseIasButtonMessage(description)
|
||||
}
|
||||
|
||||
log.debug "Parse returned $event"
|
||||
def result = event ? createEvent(event) : []
|
||||
|
||||
if (description?.startsWith('enroll request')) {
|
||||
List cmds = enrollResponse()
|
||||
result = cmds?.collect { new physicalgraph.device.HubAction(it) }
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
private Map parseIasButtonMessage(String description) {
|
||||
int zoneInt = Integer.parseInt((description - "zone status 0x"), 16)
|
||||
if (zoneInt & 0x02) {
|
||||
resultMap = getButtonResult('press')
|
||||
} else {
|
||||
resultMap = getButtonResult('release')
|
||||
}
|
||||
|
||||
return resultMap
|
||||
}
|
||||
|
||||
private Map getBatteryResult(rawValue) {
|
||||
log.debug 'Battery'
|
||||
def volts = rawValue / 10
|
||||
if (volts > 3.0 || volts == 0 || rawValue == 0xFF) {
|
||||
return [:]
|
||||
}
|
||||
else {
|
||||
def result = [
|
||||
name: 'battery'
|
||||
]
|
||||
def minVolts = 2.1
|
||||
def maxVolts = 3.0
|
||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||
result.value = Math.min(100, (int) pct * 100)
|
||||
def linkText = getLinkText(device)
|
||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
private Map parseNonIasButtonMessage(Map descMap){
|
||||
def buttonState = ""
|
||||
def buttonNumber = 0
|
||||
if (((device.getDataValue("model") == "3460-L") || (device.getDataValue("model") == "3450-L"))
|
||||
&&(descMap.clusterInt == 0x0006)) {
|
||||
if (descMap.command == "01") {
|
||||
getButtonResult("press")
|
||||
}
|
||||
else if (descMap.command == "00") {
|
||||
getButtonResult("release")
|
||||
}
|
||||
}
|
||||
else if (descMap.clusterInt == 0x0006) {
|
||||
buttonState = "pushed"
|
||||
if (descMap.command == "01") {
|
||||
buttonNumber = 1
|
||||
}
|
||||
else if (descMap.command == "00") {
|
||||
buttonNumber = 2
|
||||
}
|
||||
if (buttonNumber !=0) {
|
||||
def descriptionText = "$device.displayName button $buttonNumber was $buttonState"
|
||||
return createEvent(name: "button", value: buttonState, data: [buttonNumber: buttonNumber], descriptionText: descriptionText, isStateChange: true)
|
||||
}
|
||||
else {
|
||||
return [:]
|
||||
}
|
||||
}
|
||||
else if (descMap.clusterInt == 0x0008) {
|
||||
if (descMap.command == "05") {
|
||||
state.buttonNumber = 1
|
||||
getButtonResult("press", 1)
|
||||
}
|
||||
else if (descMap.command == "01") {
|
||||
state.buttonNumber = 2
|
||||
getButtonResult("press", 2)
|
||||
}
|
||||
else if (descMap.command == "03") {
|
||||
getButtonResult("release", state.buttonNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
log.debug "Refreshing Battery"
|
||||
|
||||
return zigbee.readAttribute(0x0001, 0x20) +
|
||||
zigbee.enrollResponse()
|
||||
}
|
||||
|
||||
def configure() {
|
||||
log.debug "Configuring Reporting, IAS CIE, and Bindings."
|
||||
def cmds = []
|
||||
if (device.getDataValue("model") == "3450-L") {
|
||||
cmds << [
|
||||
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}", "delay 300",
|
||||
"zdo bind 0x${device.deviceNetworkId} 2 1 6 {${device.zigbeeId}} {}", "delay 300",
|
||||
"zdo bind 0x${device.deviceNetworkId} 3 1 6 {${device.zigbeeId}} {}", "delay 300",
|
||||
"zdo bind 0x${device.deviceNetworkId} 4 1 6 {${device.zigbeeId}} {}", "delay 300"
|
||||
]
|
||||
}
|
||||
return zigbee.onOffConfig() +
|
||||
zigbee.levelConfig() +
|
||||
zigbee.configureReporting(0x0001, 0x20, 0x20, 30, 21600, 0x01) +
|
||||
zigbee.enrollResponse() +
|
||||
zigbee.readAttribute(0x0001, 0x20) +
|
||||
cmds
|
||||
|
||||
}
|
||||
|
||||
private Map getButtonResult(buttonState, buttonNumber = 1) {
|
||||
if (buttonState == 'release') {
|
||||
log.debug "Button was value : $buttonState"
|
||||
def timeDiff = now() - state.pressTime
|
||||
log.info "timeDiff: $timeDiff"
|
||||
def holdPreference = holdTime ?: 1
|
||||
log.info "holdp1 : $holdPreference"
|
||||
holdPreference = (holdPreference as int) * 1000
|
||||
log.info "holdp2 : $holdPreference"
|
||||
if (timeDiff > 10000) { //timeDiff>10sec check for refresh sending release value causing actions to be executed
|
||||
return [:]
|
||||
}
|
||||
else {
|
||||
if (timeDiff < holdPreference) {
|
||||
buttonState = "pushed"
|
||||
}
|
||||
else {
|
||||
buttonState = "held"
|
||||
}
|
||||
def descriptionText = "$device.displayName button $buttonNumber was $buttonState"
|
||||
return createEvent(name: "button", value: buttonState, data: [buttonNumber: buttonNumber], descriptionText: descriptionText, isStateChange: true)
|
||||
}
|
||||
}
|
||||
else if (buttonState == 'press') {
|
||||
log.debug "Button was value : $buttonState"
|
||||
state.pressTime = now()
|
||||
log.info "presstime: ${state.pressTime}"
|
||||
return [:]
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
startTimer()
|
||||
configure()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def configure(){
|
||||
logIt "Configuring Smart Fob..."
|
||||
[
|
||||
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}", "delay 200",
|
||||
"zdo bind 0x${device.deviceNetworkId} 2 1 6 {${device.zigbeeId}} {}", "delay 200",
|
||||
"zdo bind 0x${device.deviceNetworkId} 3 1 6 {${device.zigbeeId}} {}", "delay 200",
|
||||
"zdo bind 0x${device.deviceNetworkId} 4 1 6 {${device.zigbeeId}} {}", "delay 200",
|
||||
"zdo bind 0x${device.deviceNetworkId} 1 1 1 {${device.zigbeeId}} {}", "delay 200"
|
||||
] +
|
||||
zigbee.configureReporting(0x0001,0x0020,0x20,20,20,0x01)
|
||||
}
|
||||
|
||||
def parseCatchAllMessage(descMap) {
|
||||
if (descMap?.clusterId == "0006" && descMap?.command == "01") //button pressed
|
||||
handleButtonPress(descMap.sourceEndpoint as int)
|
||||
else if (descMap?.clusterId == "0006" && descMap?.command == "00") //button released
|
||||
handleButtonRelease(descMap.sourceEndpoint as int)
|
||||
else logIt("Parse: Unhandled message: ${descMap}","trace")
|
||||
}
|
||||
|
||||
def parseReportAttributeMessage(descMap) {
|
||||
if (descMap?.cluster == "0001" && descMap?.attrId == "0020") createBatteryEvent(getBatteryLevel(descMap.value))
|
||||
else logIt descMap
|
||||
}
|
||||
|
||||
private createBatteryEvent(percent) {
|
||||
logIt "Battery level at " + percent
|
||||
return createEvent([name: "battery", value: percent])
|
||||
}
|
||||
|
||||
//this method determines if a press should count as a push or a hold and returns the relevant event type
|
||||
private handleButtonRelease(button) {
|
||||
logIt "lastPress state variable: ${state.lastPress}"
|
||||
def sequenceError = {logIt("Uh oh...missed a message? Dropping this event.", "error"); state.lastPress = null; return []}
|
||||
|
||||
if (!state.lastPress) return sequenceError()
|
||||
else if (state.lastPress.button != button) return sequenceError()
|
||||
|
||||
def currentTime = now()
|
||||
def startOfPress = state.lastPress?.time
|
||||
def timeDif = currentTime - startOfPress
|
||||
def holdTimeMillisec = (settings.holdTime?:3).toInteger() * 1000
|
||||
|
||||
state.lastPress = null //we're done with this. clear it to make error conditions easier to catch
|
||||
|
||||
if (timeDif < 0)
|
||||
//likely a message sequence issue or dropped packet. Drop this press and wait for another.
|
||||
return sequenceError()
|
||||
else if (timeDif < holdTimeMillisec)
|
||||
return createButtonEvent(button,"pushed")
|
||||
else
|
||||
return createButtonEvent(button,"held")
|
||||
}
|
||||
|
||||
private handleButtonPress(button) {
|
||||
state.lastPress = [button: button, time: now()]
|
||||
}
|
||||
|
||||
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])
|
||||
}
|
||||
|
||||
private getBatteryLevel(rawValue) {
|
||||
def intValue = Integer.parseInt(rawValue,16)
|
||||
def min = 2.1
|
||||
def max = 3.0
|
||||
def vBatt = intValue / 10
|
||||
return ((vBatt - min) / (max - min) * 100) as int
|
||||
}
|
||||
|
||||
private handlePresenceEvent(present) {
|
||||
def wasPresent = device.currentState("presence")?.value == "present"
|
||||
if (!wasPresent && present) {
|
||||
logIt "Sensor is present"
|
||||
startTimer()
|
||||
} else if (!present) {
|
||||
logIt "Sensor is not present"
|
||||
stopTimer()
|
||||
def initialize() {
|
||||
if ((device.getDataValue("manufacturer") == "OSRAM") && (device.getDataValue("model") == "LIGHTIFY Dimming Switch")) {
|
||||
sendEvent(name: "numberOfButtons", value: 2)
|
||||
}
|
||||
def linkText = getLinkText(device)
|
||||
def eventMap = [
|
||||
name: "presence",
|
||||
value: present ? "present" : "not present",
|
||||
linkText: linkText,
|
||||
descriptionText: "${linkText} has ${present ? 'arrived' : 'left'}",
|
||||
]
|
||||
logIt "Creating presence event: ${eventMap}"
|
||||
sendEvent(eventMap)
|
||||
}
|
||||
|
||||
private startTimer() {
|
||||
logIt "Scheduling periodic timer"
|
||||
schedule("0 * * * * ?", checkPresenceCallback)
|
||||
}
|
||||
|
||||
private stopTimer() {
|
||||
logIt "Stopping periodic timer"
|
||||
unschedule()
|
||||
}
|
||||
|
||||
def checkPresenceCallback() {
|
||||
def timeSinceLastCheckin = (now() - state.lastCheckin) / 1000
|
||||
def theCheckInterval = (checkInterval ? checkInterval as int : 2) * 60
|
||||
logIt "Sensor checked in ${timeSinceLastCheckin} seconds ago"
|
||||
if (timeSinceLastCheckin >= theCheckInterval) {
|
||||
handlePresenceEvent(false)
|
||||
else if ((device.getDataValue("manufacturer") == "CentraLite") &&
|
||||
((device.getDataValue("model") == "3455-L") || (device.getDataValue("model") == "3460-L"))) {
|
||||
sendEvent(name: "numberOfButtons", value: 1)
|
||||
}
|
||||
else if ((device.getDataValue("manufacturer") == "CentraLite") && (device.getDataValue("model") == "3450-L")) {
|
||||
sendEvent(name: "numberOfButtons", value: 4)
|
||||
}
|
||||
else {
|
||||
//default. can be changed
|
||||
sendEvent(name: "numberOfButtons", value: 4)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ****** Utility functions ******
|
||||
|
||||
private logIt(str, logLevel = 'debug') {if (settings.logging) log."$logLevel"(str) }
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
* Copyright 2016 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:
|
||||
@@ -11,100 +11,133 @@
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Capabilities
|
||||
* - Battery
|
||||
* - Configuration
|
||||
* - Refresh
|
||||
* - Switch
|
||||
* - Valve
|
||||
*/
|
||||
|
||||
metadata {
|
||||
definition (name: "Zigbee Valve", namespace: "smartthings", author: "SmartThings") {
|
||||
capability "Battery"
|
||||
capability "Configuration"
|
||||
capability "Refresh"
|
||||
capability "Switch"
|
||||
capability "Valve"
|
||||
definition (name: "ZigBee Valve", namespace: "smartthings", author: "SmartThings") {
|
||||
capability "Actuator"
|
||||
capability "Battery"
|
||||
capability "Configuration"
|
||||
capability "Power Source"
|
||||
capability "Refresh"
|
||||
capability "Valve"
|
||||
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0004,0005,0020,0006,0B02", outClusters: "0003"
|
||||
}
|
||||
fingerprint profileId: "0104", inClusters: "0000, 0001, 0003, 0006, 0020, 0B02, FC02", outClusters: "0019", manufacturer: "WAXMAN", model: "leakSMART Water Valve v2.10", deviceJoinName: "leakSMART Valve"
|
||||
fingerprint profileId: "0104", inClusters: "0000, 0001, 0003, 0004, 0005, 0006, 0008, 000F, 0020, 0B02", outClusters: "0003, 0019", manufacturer: "WAXMAN", model: "House Water Valve - MDL-TBD", deviceJoinName: "Waxman House Water Valve"
|
||||
}
|
||||
|
||||
// simulator metadata
|
||||
simulator {
|
||||
// status messages
|
||||
status "on": "on/off: 1"
|
||||
status "off": "on/off: 0"
|
||||
// simulator metadata
|
||||
simulator {
|
||||
// status messages
|
||||
status "on": "on/off: 1"
|
||||
status "off": "on/off: 0"
|
||||
|
||||
// reply messages
|
||||
reply "zcl on-off on": "on/off: 1"
|
||||
reply "zcl on-off off": "on/off: 0"
|
||||
}
|
||||
// reply messages
|
||||
reply "zcl on-off on": "on/off: 1"
|
||||
reply "zcl on-off off": "on/off: 0"
|
||||
}
|
||||
|
||||
// UI tile definitions
|
||||
tiles {
|
||||
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
|
||||
state "off", label: 'closed', action: "switch.on", icon: "st.Outdoor.outdoor16", backgroundColor: "#e86d13"
|
||||
state "on", label: 'open', action: "switch.off", icon: "st.Outdoor.outdoor16", backgroundColor: "#53a7c0"
|
||||
}
|
||||
main "switch"
|
||||
details(["switch"])
|
||||
}
|
||||
tiles(scale: 2) {
|
||||
multiAttributeTile(name:"valve", type: "generic", width: 6, height: 4, canChangeIcon: true){
|
||||
tileAttribute ("device.contact", key: "PRIMARY_CONTROL") {
|
||||
attributeState "open", label: '${name}', action: "valve.close", icon: "st.valves.water.open", backgroundColor: "#53a7c0", nextState:"closing"
|
||||
attributeState "closed", label: '${name}', action: "valve.open", icon: "st.valves.water.closed", backgroundColor: "#e86d13", nextState:"opening"
|
||||
attributeState "opening", label: '${name}', action: "valve.close", icon: "st.valves.water.open", backgroundColor: "#53a7c0", nextState:"closing"
|
||||
attributeState "closing", label: '${name}', action: "valve.open", icon: "st.valves.water.closed", backgroundColor: "#e86d13", nextState:"opening"
|
||||
}
|
||||
tileAttribute ("powerSource", key: "SECONDARY_CONTROL") {
|
||||
attributeState "powerSource", label:'Power Source: ${currentValue}'
|
||||
}
|
||||
}
|
||||
|
||||
valueTile("battery", "device.battery", inactiveLabel:false, decoration:"flat", width:2, height:2) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
|
||||
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||
}
|
||||
|
||||
main(["valve"])
|
||||
details(["valve", "battery", "refresh"])
|
||||
}
|
||||
}
|
||||
|
||||
private getCLUSTER_BASIC() { 0x0000 }
|
||||
private getBASIC_ATTR_POWER_SOURCE() { 0x0007 }
|
||||
private getCLUSTER_POWER() { 0x0001 }
|
||||
private getPOWER_ATTR_BATTERY_PERCENTAGE_REMAINING() { 0x0021 }
|
||||
private getTYPE_U8() { 0x20 }
|
||||
private getTYPE_ENUM8() { 0x30 }
|
||||
|
||||
// Parse incoming device messages to generate events
|
||||
def parse(String description) {
|
||||
log.info description
|
||||
if (description?.startsWith("catchall:")) {
|
||||
def value = name == "switch" ? (description?.endsWith(" 1") ? "on" : "off") : null
|
||||
def result = createEvent(name: name, value: value)
|
||||
def msg = zigbee.parse(description)
|
||||
log.debug "Parse returned ${result?.descriptionText}"
|
||||
return result
|
||||
log.trace msg
|
||||
log.trace "data: $msg.data"
|
||||
}
|
||||
else {
|
||||
def name = description?.startsWith("on/off: ") ? "switch" : null
|
||||
def value = name == "switch" ? (description?.endsWith(" 1") ? "on" : "off") : null
|
||||
def result = createEvent(name: name, value: value)
|
||||
log.debug "Parse returned ${result?.descriptionText}"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// Commands to device
|
||||
def on() {
|
||||
log.debug "on()"
|
||||
sendEvent(name: "switch", value: "on")
|
||||
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
|
||||
}
|
||||
|
||||
def off() {
|
||||
log.debug "off()"
|
||||
sendEvent(name: "switch", value: "off")
|
||||
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
|
||||
log.debug "description is $description"
|
||||
def event = zigbee.getEvent(description)
|
||||
if (event) {
|
||||
if(event.name == "switch") {
|
||||
event.name = "contact" //0006 cluster in valve is tied to contact
|
||||
if(event.value == "on") {
|
||||
event.value = "open"
|
||||
}
|
||||
else if(event.value == "off") {
|
||||
event.value = "closed"
|
||||
}
|
||||
}
|
||||
sendEvent(event)
|
||||
}
|
||||
else {
|
||||
def descMap = zigbee.parseDescriptionAsMap(description)
|
||||
if (descMap.clusterInt == CLUSTER_BASIC && descMap.attrInt == BASIC_ATTR_POWER_SOURCE){
|
||||
def value = descMap.value
|
||||
if (value == "01" || value == "02") {
|
||||
sendEvent(name: "powerSource", value: "Mains")
|
||||
}
|
||||
else if (value == "03") {
|
||||
sendEvent(name: "powerSource", value: "Battery")
|
||||
}
|
||||
else if (value == "04") {
|
||||
sendEvent(name: "powerSource", value: "DC")
|
||||
}
|
||||
else {
|
||||
sendEvent(name: "powerSource", value: "Unknown")
|
||||
}
|
||||
}
|
||||
else if (descMap.clusterInt == CLUSTER_POWER && descMap.attrInt == POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) {
|
||||
event.name = "battery"
|
||||
event.value = Math.round(Integer.parseInt(descMap.value, 16) / 2)
|
||||
sendEvent(event)
|
||||
}
|
||||
else {
|
||||
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||
log.debug descMap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def open() {
|
||||
log.debug "on()"
|
||||
sendEvent(name: "switch", value: "on")
|
||||
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
|
||||
zigbee.on()
|
||||
}
|
||||
|
||||
def close() {
|
||||
log.debug "off()"
|
||||
sendEvent(name: "switch", value: "off")
|
||||
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
|
||||
zigbee.off()
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
log.debug "sending refresh command"
|
||||
"st rattr 0x${device.deviceNetworkId} 1 6 0"
|
||||
log.debug "refresh called"
|
||||
zigbee.onOffRefresh() +
|
||||
zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE) +
|
||||
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) +
|
||||
zigbee.onOffConfig() +
|
||||
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING, TYPE_U8, 600, 21600, 1) +
|
||||
zigbee.configureReporting(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE, TYPE_ENUM8, 5, 21600, 1)
|
||||
}
|
||||
|
||||
def configure() {
|
||||
|
||||
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}"
|
||||
log.debug "Configuring Reporting and Bindings."
|
||||
zigbee.onOffConfig() +
|
||||
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING, TYPE_U8, 600, 21600, 1) +
|
||||
zigbee.configureReporting(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE, TYPE_ENUM8, 5, 21600, 1) +
|
||||
zigbee.onOffRefresh() +
|
||||
zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE) +
|
||||
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,683 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "Z-Wave Lock Reporting", namespace: "smartthings", author: "SmartThings") {
|
||||
capability "Actuator"
|
||||
capability "Lock"
|
||||
capability "Polling"
|
||||
capability "Refresh"
|
||||
capability "Sensor"
|
||||
capability "Lock Codes"
|
||||
capability "Battery"
|
||||
|
||||
command "unlockwtimeout"
|
||||
|
||||
fingerprint deviceId: "0x4003", inClusters: "0x98"
|
||||
fingerprint deviceId: "0x4004", inClusters: "0x98"
|
||||
}
|
||||
|
||||
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(scale: 2) {
|
||||
multiAttributeTile(name:"toggle", type: "generic", width: 6, height: 4){
|
||||
tileAttribute ("device.lock", key: "PRIMARY_CONTROL") {
|
||||
attributeState "locked", label:'locked', action:"lock.unlock", icon:"st.locks.lock.locked", backgroundColor:"#79b821", nextState:"unlocking"
|
||||
attributeState "unlocked", label:'unlocked', action:"lock.lock", icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff", nextState:"locking"
|
||||
attributeState "unknown", label:"unknown", action:"lock.lock", icon:"st.locks.lock.unknown", backgroundColor:"#ffffff", nextState:"locking"
|
||||
attributeState "locking", label:'locking', icon:"st.locks.lock.locked", backgroundColor:"#79b821"
|
||||
attributeState "unlocking", label:'unlocking', icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff"
|
||||
}
|
||||
}
|
||||
standardTile("lock", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'lock', action:"lock.lock", icon:"st.locks.lock.locked", nextState:"locking"
|
||||
}
|
||||
standardTile("unlock", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'unlock', action:"lock.unlock", icon:"st.locks.lock.unlocked", nextState:"unlocking"
|
||||
}
|
||||
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
standardTile("refresh", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||
}
|
||||
|
||||
main "toggle"
|
||||
details(["toggle", "lock", "unlock", "battery", "refresh"])
|
||||
}
|
||||
}
|
||||
|
||||
import physicalgraph.zwave.commands.doorlockv1.*
|
||||
import physicalgraph.zwave.commands.usercodev1.*
|
||||
|
||||
def updated() {
|
||||
try {
|
||||
if (!state.init) {
|
||||
state.init = true
|
||||
response(secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()]))
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn "updated() threw $e"
|
||||
}
|
||||
}
|
||||
|
||||
def parse(String description) {
|
||||
def result = null
|
||||
if (description.startsWith("Err 106")) {
|
||||
if (state.sec) {
|
||||
result = createEvent(descriptionText:description, displayed:false)
|
||||
} else {
|
||||
result = createEvent(
|
||||
descriptionText: "This lock 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.",
|
||||
eventType: "ALERT",
|
||||
name: "secureInclusion",
|
||||
value: "failed",
|
||||
displayed: true,
|
||||
)
|
||||
}
|
||||
} else if (description == "updated") {
|
||||
return null
|
||||
} else {
|
||||
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2, 0x85: 2, 0x86: 1 ])
|
||||
if (cmd) {
|
||||
result = zwaveEvent(cmd)
|
||||
}
|
||||
}
|
||||
log.debug "\"$description\" parsed to ${result.inspect()}"
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
|
||||
def encapsulatedCommand = cmd.encapsulatedCommand([0x62: 1, 0x71: 2, 0x80: 1, 0x85: 2, 0x63: 1, 0x98: 1, 0x86: 1])
|
||||
// log.debug "encapsulated: $encapsulatedCommand"
|
||||
if (encapsulatedCommand) {
|
||||
zwaveEvent(encapsulatedCommand)
|
||||
}
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.NetworkKeyVerify cmd) {
|
||||
createEvent(name:"secureInclusion", value:"success", descriptionText:"Secure inclusion was successful")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
|
||||
state.sec = cmd.commandClassSupport.collect { String.format("%02X ", it) }.join()
|
||||
if (cmd.commandClassControl) {
|
||||
state.secCon = cmd.commandClassControl.collect { String.format("%02X ", it) }.join()
|
||||
}
|
||||
log.debug "Security command classes: $state.sec"
|
||||
createEvent(name:"secureInclusion", value:"success", descriptionText:"Lock is securely included")
|
||||
}
|
||||
|
||||
def zwaveEvent(DoorLockOperationReport cmd) {
|
||||
def result = []
|
||||
def map = [ name: "lock" ]
|
||||
if (cmd.doorLockMode == 0xFF) {
|
||||
map.value = "locked"
|
||||
} else if (cmd.doorLockMode >= 0x40) {
|
||||
map.value = "unknown"
|
||||
} else if (cmd.doorLockMode & 1) {
|
||||
map.value = "unlocked with timeout"
|
||||
} else {
|
||||
map.value = "unlocked"
|
||||
if (state.assoc != zwaveHubNodeId) {
|
||||
log.debug "setting association"
|
||||
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
|
||||
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
|
||||
result << response(secure(zwave.associationV1.associationGet(groupingIdentifier:1)))
|
||||
}
|
||||
}
|
||||
result ? [createEvent(map), *result] : createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd) {
|
||||
def result = []
|
||||
def map = null
|
||||
if (cmd.zwaveAlarmType == 6) {
|
||||
if (1 <= cmd.zwaveAlarmEvent && cmd.zwaveAlarmEvent < 10) {
|
||||
map = [ name: "lock", value: (cmd.zwaveAlarmEvent & 1) ? "locked" : "unlocked" ]
|
||||
}
|
||||
switch(cmd.zwaveAlarmEvent) {
|
||||
case 1:
|
||||
map.descriptionText = "$device.displayName was manually locked"
|
||||
break
|
||||
case 2:
|
||||
map.descriptionText = "$device.displayName was manually unlocked"
|
||||
break
|
||||
case 5:
|
||||
if (cmd.eventParameter) {
|
||||
map.descriptionText = "$device.displayName was locked with code ${cmd.eventParameter.first()}"
|
||||
map.data = [ usedCode: cmd.eventParameter[0] ]
|
||||
}
|
||||
break
|
||||
case 6:
|
||||
if (cmd.eventParameter) {
|
||||
map.descriptionText = "$device.displayName was unlocked with code ${cmd.eventParameter.first()}"
|
||||
map.data = [ usedCode: cmd.eventParameter[0] ]
|
||||
}
|
||||
break
|
||||
case 9:
|
||||
map.descriptionText = "$device.displayName was autolocked"
|
||||
break
|
||||
case 7:
|
||||
case 8:
|
||||
case 0xA:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName was not locked fully" ]
|
||||
break
|
||||
case 0xB:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName is jammed" ]
|
||||
break
|
||||
case 0xC:
|
||||
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", isStateChange: true ]
|
||||
allCodesDeleted()
|
||||
break
|
||||
case 0xD:
|
||||
if (cmd.eventParameter) {
|
||||
map = [ name: "codeReport", value: cmd.eventParameter[0], data: [ code: "" ], isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code ${map.value} was deleted"
|
||||
map.isStateChange = (state["code$map.value"] != "")
|
||||
state["code$map.value"] = ""
|
||||
} else {
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: user code deleted", isStateChange: true ]
|
||||
}
|
||||
break
|
||||
case 0xE:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName: user code added", isStateChange: true ]
|
||||
if (cmd.eventParameter) {
|
||||
map.value = cmd.eventParameter[0]
|
||||
result << response(requestCode(cmd.eventParameter[0]))
|
||||
}
|
||||
break
|
||||
case 0xF:
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: user code not added, duplicate", isStateChange: true ]
|
||||
break
|
||||
case 0x10:
|
||||
map = [ name: "tamper", value: "detected", descriptionText: "$device.displayName: keypad temporarily disabled", displayed: true ]
|
||||
break
|
||||
case 0x11:
|
||||
map = [ descriptionText: "$device.displayName: keypad is busy" ]
|
||||
break
|
||||
case 0x12:
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: program code changed", isStateChange: true ]
|
||||
break
|
||||
case 0x13:
|
||||
map = [ name: "tamper", value: "detected", descriptionText: "$device.displayName: code entry attempt limit exceeded", displayed: true ]
|
||||
break
|
||||
default:
|
||||
map = map ?: [ descriptionText: "$device.displayName: alarm event $cmd.zwaveAlarmEvent", displayed: false ]
|
||||
break
|
||||
}
|
||||
} else if (cmd.zwaveAlarmType == 7) {
|
||||
map = [ name: "tamper", value: "detected", displayed: true ]
|
||||
switch (cmd.zwaveAlarmEvent) {
|
||||
case 0:
|
||||
map.value = "clear"
|
||||
map.descriptionText = "$device.displayName: tamper alert cleared"
|
||||
break
|
||||
case 1:
|
||||
case 2:
|
||||
map.descriptionText = "$device.displayName: intrusion attempt detected"
|
||||
break
|
||||
case 3:
|
||||
map.descriptionText = "$device.displayName: covering removed"
|
||||
break
|
||||
case 4:
|
||||
map.descriptionText = "$device.displayName: invalid code"
|
||||
break
|
||||
default:
|
||||
map.descriptionText = "$device.displayName: tamper alarm $cmd.zwaveAlarmEvent"
|
||||
break
|
||||
}
|
||||
} else switch(cmd.alarmType) {
|
||||
case 21: // Manually locked
|
||||
case 18: // Locked with keypad
|
||||
case 24: // Locked by command (Kwikset 914)
|
||||
case 27: // Autolocked
|
||||
map = [ name: "lock", value: "locked" ]
|
||||
break
|
||||
case 16: // Note: for levers this means it's unlocked, for non-motorized deadbolt, it's just unsecured and might not get unlocked
|
||||
case 19:
|
||||
map = [ name: "lock", value: "unlocked" ]
|
||||
if (cmd.alarmLevel) {
|
||||
map.descriptionText = "$device.displayName was unlocked with code $cmd.alarmLevel"
|
||||
map.data = [ usedCode: cmd.alarmLevel ]
|
||||
}
|
||||
break
|
||||
case 22:
|
||||
case 25: // Kwikset 914 unlocked by command
|
||||
map = [ name: "lock", value: "unlocked" ]
|
||||
break
|
||||
case 9:
|
||||
case 17:
|
||||
case 23:
|
||||
case 26:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName bolt is jammed" ]
|
||||
break
|
||||
case 13:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel was added", isStateChange: true ]
|
||||
result << response(requestCode(cmd.alarmLevel))
|
||||
break
|
||||
case 32:
|
||||
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", isStateChange: true ]
|
||||
allCodesDeleted()
|
||||
break
|
||||
case 33:
|
||||
map = [ name: "codeReport", value: cmd.alarmLevel, data: [ code: "" ], isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code $cmd.alarmLevel was deleted"
|
||||
map.isStateChange = (state["code$cmd.alarmLevel"] != "")
|
||||
state["code$cmd.alarmLevel"] = ""
|
||||
break
|
||||
case 112:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel changed", isStateChange: true ]
|
||||
result << response(requestCode(cmd.alarmLevel))
|
||||
break
|
||||
case 130: // Yale YRD batteries replaced
|
||||
map = [ descriptionText: "$device.displayName batteries replaced", isStateChange: true ]
|
||||
break
|
||||
case 131:
|
||||
map = [ /*name: "codeChanged", value: cmd.alarmLevel,*/ descriptionText: "$device.displayName code $cmd.alarmLevel is duplicate", isStateChange: false ]
|
||||
break
|
||||
case 161:
|
||||
if (cmd.alarmLevel == 2) {
|
||||
map = [ descriptionText: "$device.displayName front escutcheon removed", isStateChange: true ]
|
||||
} else {
|
||||
map = [ descriptionText: "$device.displayName detected failed user code attempt", isStateChange: true ]
|
||||
}
|
||||
break
|
||||
case 167:
|
||||
if (!state.lastbatt || now() - state.lastbatt > 12*60*60*1000) {
|
||||
map = [ descriptionText: "$device.displayName: battery low", isStateChange: true ]
|
||||
result << response(secure(zwave.batteryV1.batteryGet()))
|
||||
} else {
|
||||
map = [ name: "battery", value: device.currentValue("battery"), descriptionText: "$device.displayName: battery low", displayed: true ]
|
||||
}
|
||||
break
|
||||
case 168:
|
||||
map = [ name: "battery", value: 1, descriptionText: "$device.displayName: battery level critical", displayed: true ]
|
||||
break
|
||||
case 169:
|
||||
map = [ name: "battery", value: 0, descriptionText: "$device.displayName: battery too low to operate lock", isStateChange: true ]
|
||||
break
|
||||
default:
|
||||
map = [ displayed: false, descriptionText: "$device.displayName: alarm event $cmd.alarmType level $cmd.alarmLevel" ]
|
||||
break
|
||||
}
|
||||
result ? [createEvent(map), *result] : createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(UserCodeReport cmd) {
|
||||
def result = []
|
||||
def name = "code$cmd.userIdentifier"
|
||||
def code = cmd.code
|
||||
def map = [:]
|
||||
if (cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_OCCUPIED ||
|
||||
(cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_STATUS_NOT_AVAILABLE && cmd.user && code != "**********"))
|
||||
{
|
||||
if (code == "**********") { // Schlage locks send us this instead of the real code
|
||||
state.blankcodes = true
|
||||
code = state["set$name"] ?: decrypt(state[name]) ?: code
|
||||
state.remove("set$name".toString())
|
||||
}
|
||||
if (!code && cmd.userIdStatus == 1) { // Schlage touchscreen sends blank code to notify of a changed code
|
||||
map = [ name: "codeChanged", value: cmd.userIdentifier, displayed: true, isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier " + (state[name] ? "changed" : "was added")
|
||||
code = state["set$name"] ?: decrypt(state[name]) ?: "****"
|
||||
state.remove("set$name".toString())
|
||||
} else {
|
||||
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: code ] ]
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier is set"
|
||||
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
|
||||
map.isStateChange = true
|
||||
}
|
||||
result << createEvent(map)
|
||||
} else {
|
||||
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: "" ] ]
|
||||
if (state.blankcodes && state["reset$name"]) { // we deleted this code so we can tell that our new code gets set
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier was reset"
|
||||
map.displayed = map.isStateChange = true
|
||||
result << createEvent(map)
|
||||
state["set$name"] = state["reset$name"]
|
||||
result << response(setCode(cmd.userIdentifier, state["reset$name"]))
|
||||
state.remove("reset$name".toString())
|
||||
} else {
|
||||
if (state[name]) {
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier was deleted"
|
||||
} else {
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier is not set"
|
||||
}
|
||||
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
|
||||
map.isStateChange = true
|
||||
result << createEvent(map)
|
||||
}
|
||||
code = ""
|
||||
}
|
||||
state[name] = code ? encrypt(code) : code
|
||||
|
||||
if (cmd.userIdentifier == state.requestCode) { // reloadCodes() was called, keep requesting the codes in order
|
||||
if (state.requestCode + 1 > state.codes || state.requestCode >= 30) {
|
||||
state.remove("requestCode") // done
|
||||
} else {
|
||||
state.requestCode = state.requestCode + 1 // get next
|
||||
result << response(requestCode(state.requestCode))
|
||||
}
|
||||
}
|
||||
if (cmd.userIdentifier == state.pollCode) {
|
||||
if (state.pollCode + 1 > state.codes || state.pollCode >= 30) {
|
||||
state.remove("pollCode") // done
|
||||
} else {
|
||||
state.pollCode = state.pollCode + 1
|
||||
}
|
||||
}
|
||||
log.debug "code report parsed to ${result.inspect()}"
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(UsersNumberReport cmd) {
|
||||
def result = []
|
||||
state.codes = cmd.supportedUsers
|
||||
if (state.requestCode && state.requestCode <= cmd.supportedUsers) {
|
||||
result << response(requestCode(state.requestCode))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) {
|
||||
def result = []
|
||||
if (cmd.nodeId.any { it == zwaveHubNodeId }) {
|
||||
state.remove("associationQuery")
|
||||
log.debug "$device.displayName is associated to $zwaveHubNodeId"
|
||||
result << createEvent(descriptionText: "$device.displayName is associated")
|
||||
state.assoc = zwaveHubNodeId
|
||||
if (cmd.groupingIdentifier == 2) {
|
||||
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
}
|
||||
} else if (cmd.groupingIdentifier == 1) {
|
||||
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
|
||||
} else if (cmd.groupingIdentifier == 2) {
|
||||
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.timev1.TimeGet cmd) {
|
||||
def result = []
|
||||
def now = new Date().toCalendar()
|
||||
if(location.timeZone) now.timeZone = location.timeZone
|
||||
result << createEvent(descriptionText: "$device.displayName requested time update", displayed: false)
|
||||
result << response(secure(zwave.timeV1.timeReport(
|
||||
hourLocalTime: now.get(Calendar.HOUR_OF_DAY),
|
||||
minuteLocalTime: now.get(Calendar.MINUTE),
|
||||
secondLocalTime: now.get(Calendar.SECOND)))
|
||||
)
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
|
||||
// The old Schlage locks use group 1 for basic control - we don't want that, so unsubscribe from group 1
|
||||
def result = [ createEvent(name: "lock", value: cmd.value ? "unlocked" : "locked") ]
|
||||
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
if (state.assoc != zwaveHubNodeId) {
|
||||
result << response(zwave.associationV1.associationGet(groupingIdentifier:2))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
|
||||
def map = [ name: "battery", unit: "%" ]
|
||||
if (cmd.batteryLevel == 0xFF) {
|
||||
map.value = 1
|
||||
map.descriptionText = "$device.displayName has a low battery"
|
||||
} else {
|
||||
map.value = cmd.batteryLevel
|
||||
}
|
||||
state.lastbatt = now()
|
||||
createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
|
||||
def result = []
|
||||
|
||||
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
|
||||
log.debug "msr: $msr"
|
||||
updateDataValue("MSR", msr)
|
||||
|
||||
result << createEvent(descriptionText: "$device.displayName MSR: $msr", isStateChange: false)
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
|
||||
def fw = "${cmd.applicationVersion}.${cmd.applicationSubVersion}"
|
||||
updateDataValue("fw", fw)
|
||||
if (state.MSR == "003B-6341-5044") {
|
||||
updateDataValue("ver", "${cmd.applicationVersion >> 4}.${cmd.applicationVersion & 0xF}")
|
||||
}
|
||||
def text = "$device.displayName: firmware version: $fw, Z-Wave version: ${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}"
|
||||
createEvent(descriptionText: text, isStateChange: false)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationBusy cmd) {
|
||||
def msg = cmd.status == 0 ? "try again later" :
|
||||
cmd.status == 1 ? "try again in $cmd.waitTime seconds" :
|
||||
cmd.status == 2 ? "request queued" : "sorry"
|
||||
createEvent(displayed: true, descriptionText: "$device.displayName is busy, $msg")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationRejectedRequest cmd) {
|
||||
createEvent(displayed: true, descriptionText: "$device.displayName rejected the last request")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
createEvent(displayed: false, descriptionText: "$device.displayName: $cmd")
|
||||
}
|
||||
|
||||
def lockAndCheck(doorLockMode) {
|
||||
secureSequence([
|
||||
zwave.doorLockV1.doorLockOperationSet(doorLockMode: doorLockMode),
|
||||
zwave.doorLockV1.doorLockOperationGet()
|
||||
], 4200)
|
||||
}
|
||||
|
||||
def lock() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_SECURED)
|
||||
}
|
||||
|
||||
def unlock() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED)
|
||||
}
|
||||
|
||||
def unlockwtimeout() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED_WITH_TIMEOUT)
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
def cmds = [secure(zwave.doorLockV1.doorLockOperationGet())]
|
||||
if (state.assoc == zwaveHubNodeId) {
|
||||
log.debug "$device.displayName is associated to ${state.assoc}"
|
||||
} else if (!state.associationQuery) {
|
||||
log.debug "checking association"
|
||||
cmds << "delay 4200"
|
||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format() // old Schlage locks use group 2 and don't secure the Association CC
|
||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||
state.associationQuery = now()
|
||||
} else if (secondsPast(state.associationQuery, 9)) {
|
||||
cmds << "delay 6000"
|
||||
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
|
||||
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
|
||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||
state.associationQuery = now()
|
||||
}
|
||||
log.debug "refresh sending ${cmds.inspect()}"
|
||||
cmds
|
||||
}
|
||||
|
||||
def poll() {
|
||||
def cmds = []
|
||||
// Only check lock state if it changed recently or we haven't had an update in an hour
|
||||
def latest = device.currentState("lock")?.date?.time
|
||||
if (!latest || !secondsPast(latest, 6 * 60) || secondsPast(state.lastPoll, 55 * 60)) {
|
||||
cmds << secure(zwave.doorLockV1.doorLockOperationGet())
|
||||
state.lastPoll = now()
|
||||
} else if (!state.lastbatt || now() - state.lastbatt > 53*60*60*1000) {
|
||||
cmds << secure(zwave.batteryV1.batteryGet())
|
||||
state.lastbatt = now() //inside-214
|
||||
}
|
||||
if (cmds) {
|
||||
log.debug "poll is sending ${cmds.inspect()}"
|
||||
cmds
|
||||
} else {
|
||||
// workaround to keep polling from stopping due to lack of activity
|
||||
sendEvent(descriptionText: "skipping poll", isStateChange: true, displayed: false)
|
||||
null
|
||||
}
|
||||
|
||||
reportAllCodes(state)
|
||||
}
|
||||
|
||||
def requestCode(codeNumber) {
|
||||
secure(zwave.userCodeV1.userCodeGet(userIdentifier: codeNumber))
|
||||
}
|
||||
|
||||
def reloadAllCodes() {
|
||||
def cmds = []
|
||||
if (!state.codes) {
|
||||
state.requestCode = 1
|
||||
cmds << secure(zwave.userCodeV1.usersNumberGet())
|
||||
} else {
|
||||
if(!state.requestCode) state.requestCode = 1
|
||||
cmds << requestCode(codeNumber)
|
||||
}
|
||||
cmds
|
||||
}
|
||||
|
||||
def setCode(codeNumber, code) {
|
||||
def strcode = code
|
||||
log.debug "setting code $codeNumber to $code"
|
||||
if (code instanceof String) {
|
||||
code = code.toList().findResults { if(it > ' ' && it != ',' && it != '-') it.toCharacter() as Short }
|
||||
} else {
|
||||
strcode = code.collect{ it as Character }.join()
|
||||
}
|
||||
if (state.blankcodes) {
|
||||
// Can't just set, we won't be able to tell if it was successful
|
||||
if (state["code$codeNumber"] != "") {
|
||||
if (state["setcode$codeNumber"] != strcode) {
|
||||
state["resetcode$codeNumber"] = strcode
|
||||
return deleteCode(codeNumber)
|
||||
}
|
||||
} else {
|
||||
state["setcode$codeNumber"] = strcode
|
||||
}
|
||||
}
|
||||
secureSequence([
|
||||
zwave.userCodeV1.userCodeSet(userIdentifier:codeNumber, userIdStatus:1, user:code),
|
||||
zwave.userCodeV1.userCodeGet(userIdentifier:codeNumber)
|
||||
], 7000)
|
||||
}
|
||||
|
||||
def deleteCode(codeNumber) {
|
||||
log.debug "deleting code $codeNumber"
|
||||
secureSequence([
|
||||
zwave.userCodeV1.userCodeSet(userIdentifier:codeNumber, userIdStatus:0),
|
||||
zwave.userCodeV1.userCodeGet(userIdentifier:codeNumber)
|
||||
], 7000)
|
||||
}
|
||||
|
||||
def updateCodes(codeSettings) {
|
||||
if(codeSettings instanceof String) codeSettings = util.parseJson(codeSettings)
|
||||
def set_cmds = []
|
||||
def get_cmds = []
|
||||
codeSettings.each { name, updated ->
|
||||
def current = decrypt(state[name])
|
||||
if (name.startsWith("code")) {
|
||||
def n = name[4..-1].toInteger()
|
||||
log.debug "$name was $current, set to $updated"
|
||||
if (updated?.size() >= 4 && updated != current) {
|
||||
def cmds = setCode(n, updated)
|
||||
set_cmds << cmds.first()
|
||||
get_cmds << cmds.last()
|
||||
} else if ((current && updated == "") || updated == "0") {
|
||||
def cmds = deleteCode(n)
|
||||
set_cmds << cmds.first()
|
||||
get_cmds << cmds.last()
|
||||
} else if (updated && updated.size() < 4) {
|
||||
// Entered code was too short
|
||||
codeSettings["code$n"] = current
|
||||
}
|
||||
} else log.warn("unexpected entry $name: $updated")
|
||||
}
|
||||
if (set_cmds) {
|
||||
return response(delayBetween(set_cmds, 2200) + ["delay 2200"] + delayBetween(get_cmds, 4200))
|
||||
}
|
||||
}
|
||||
|
||||
def getCode(codeNumber) {
|
||||
decrypt(state["code$codeNumber"])
|
||||
}
|
||||
|
||||
def getAllCodes() {
|
||||
state.findAll { it.key.startsWith 'code' }.collectEntries {
|
||||
[it.key, (it.value instanceof String && it.value.startsWith("~")) ? decrypt(it.value) : it.value]
|
||||
}
|
||||
}
|
||||
|
||||
private secure(physicalgraph.zwave.Command cmd) {
|
||||
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
|
||||
}
|
||||
|
||||
private secureSequence(commands, delay=4200) {
|
||||
delayBetween(commands.collect{ secure(it) }, delay)
|
||||
}
|
||||
|
||||
private Boolean secondsPast(timestamp, seconds) {
|
||||
if (!(timestamp instanceof Number)) {
|
||||
if (timestamp instanceof Date) {
|
||||
timestamp = timestamp.time
|
||||
} else if ((timestamp instanceof String) && timestamp.isNumber()) {
|
||||
timestamp = timestamp.toLong()
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return (now() - timestamp) > (seconds * 1000)
|
||||
}
|
||||
|
||||
private allCodesDeleted() {
|
||||
if (state.codes instanceof Integer) {
|
||||
(1..state.codes).each { n ->
|
||||
if (state["code$n"]) {
|
||||
result << createEvent(name: "codeReport", value: n, data: [ code: "" ], descriptionText: "code $n was deleted",
|
||||
displayed: false, isStateChange: true)
|
||||
}
|
||||
state["code$n"] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def reportAllCodes(state) {
|
||||
def map = [ name: "reportAllCodes", data: [:], displayed: false, isStateChange: false, type: "physical" ]
|
||||
state.each { entry ->
|
||||
//iterate through all the state entries and add them to the event data to be handled by application event handlers
|
||||
if ( entry.key ==~ /^code\d{1,}/ && entry.value.startsWith("~") ) {
|
||||
map.data.put(entry.key, decrypt(entry.value))
|
||||
} else {
|
||||
map.data.put(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
sendEvent(map)
|
||||
}
|
||||
@@ -24,17 +24,24 @@ definition(
|
||||
iconX3Url: "http://www.gidjit.com/appicon@3x.png",
|
||||
oauth: [displayName: "Gidjit", displayLink: "www.gidjit.com"])
|
||||
|
||||
preferences(oauthPage: "deviceAuthorization") {
|
||||
// deviceAuthorization page is simply the devices to authorize
|
||||
page(name: "deviceAuthorization", title: "Device Authorization", nextPage: "instructionPage",
|
||||
install: false, uninstall: true) {
|
||||
section ("Allow Gidjit to have access, thereby allowing you to quickly control and monitor your following devices. Privacy Policy can be found at http://priv.gidjit.com/privacy.html") {
|
||||
input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false
|
||||
input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false
|
||||
input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade
|
||||
}
|
||||
|
||||
|
||||
preferences {
|
||||
section ("Allow Gidjit to have access, there by allowing you to quickly control and monitor the following devices") {
|
||||
input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false
|
||||
input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false
|
||||
input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade
|
||||
//input "bulbs", "capability.colorControl", title: "Control your lights", multiple: true, required: false //windowShade
|
||||
|
||||
}
|
||||
}
|
||||
page(name: "instructionPage", title: "Device Discovery", install: true) {
|
||||
section() {
|
||||
paragraph "Now the process is complete return to the Devices section of the Detected Screen. From there and you can add actions to each of your device panels, including launching SmartThings routines."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mappings {
|
||||
path("/structureinfo") {
|
||||
action: [
|
||||
|
||||
Reference in New Issue
Block a user