def getDriverVersion() { return "1.07" } // **** DEVICE DRIVER VERSION. /* * Yale Assure Lock 2 * * Version 1.07 * * 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. * * Features: * - Z-Wave S2 Security (Supervision encapsulation) * - DoorSense (Contact Sensor) * - Lock Code Manager compatibility * - Detailed Event Text Reporting * * Version History * v1.00 Initial Driver Release * v1.01 Update fingerprints for auto driver select * v1.02 fix the ZW2 usercode delete issue * ID module type and store in state * add device fingerprints for all non-fingerprint unlock capable locks with both ZW2 and ZW3 modules. * v1.03 work around ZW3 usercode maintenance bug in firmware v1.3.28 * v1.04 capture biometric fingerprint unlock and reflect in lock state * v1.05 update zwave signatures to include biometric lock variants * v1.06 fix typo in UserCodeReport handler, and undeclared commandClassVersions * ignore truncated (1 digit) user code reports * differentiate keypad vs fingerprint unlocks via v1 alarm type, and record (best guess) last code name for fingerprint * handle several more Access Control notifications (auto-lock, jam, etc.), and tag lock events with physical/digital * clean up handling of open/close notifications * add data map to notification event to trigger "Lock code entered" in RM * v1.07 Z-Wave JS: ignore "Opening state" updates (arrived as event 1, a phantom lock on every door open) * Z-Wave JS: read the user slot from eventParameter[0] when there's no embedded User Code Report * log lock operations from the notification; lock status reports log at info only when they change state * Z-Wave JS: drop repeated door open/close events (Door state is re-sent 2-3 times per open/close) * treat the lock's "code deleted" notification as confirmation of a delete we initiated, instead of * waiting on a read-back (which on a slow link made Lock Code Manager retry the delete several times) * report doorLockMode 0xFE (bolt position unknown) as "unknown" rather than "unlocked" */ metadata { definition (name: "Yale Assure Lock 2 Custom", namespace: "Sleuth255", author: "Trunzoc/Sleuth") { capability "Actuator" capability "Lock" capability "LockCodes" capability "ContactSensor" capability "Battery" capability "Configuration" capability "Refresh" fingerprint mfr: "0129", prod: "8104", deviceId: "05D3", deviceJoinName: "Yale Assure Lock 2 push button ZW2 module (YRD430)" fingerprint mfr: "0129", prod: "8104", deviceId: "05D5", deviceJoinName: "Yale Assure Lock 2 Touchscreen ZW2 module (YRD450)" fingerprint mfr: "0129", prod: "8104", deviceId: "05D1", deviceJoinName: "Yale Assure Lock 2 push button Key ZW2 module(YRD10)" fingerprint mfr: "0129", prod: "8104", deviceId: "05D2", deviceJoinName: "Yale Assure Lock 2 Touchscreen Key ZW2 module(YRD420)" fingerprint mfr: "0129", prod: "8104", deviceId: "09D3", deviceJoinName: "Yale Assure Lock 2 Touch push button ZW2 (YRD430-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "09D5", deviceJoinName: "Yale Assure Lock 2 Touch Touchscreen ZW2 module (YRD450-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "09D1", deviceJoinName: "Yale Assure Lock 2 Touch push button Key ZW2 module(YRD10-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "09D2", deviceJoinName: "Yale Assure Lock 2 Touch Touchscreen Key ZW2 module(YRD420-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "45D3", deviceJoinName: "Yale Assure Lock 2 push button ZW3 module (YRD430)" fingerprint mfr: "0129", prod: "8104", deviceId: "45D5", deviceJoinName: "Yale Assure Lock 2 Touchscreen ZW3 module (YRD450)" fingerprint mfr: "0129", prod: "8104", deviceId: "45D1", deviceJoinName: "Yale Assure Lock 2 push button Key ZW3 module(YRD410)" fingerprint mfr: "0129", prod: "8104", deviceId: "45D2", deviceJoinName: "Yale Assure Lock 2 Touchscreen Key ZW3 module(YRD420)" fingerprint mfr: "0129", prod: "8104", deviceId: "49D3", deviceJoinName: "Yale Assure Lock 2 Touch push button ZW3 (YRD430-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "49D5", deviceJoinName: "Yale Assure Lock 2 Touch Touchscreen ZW3 module (YRD450-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "49D1", deviceJoinName: "Yale Assure Lock 2 Touch push button Key ZW3 module(YRD410-F)" fingerprint mfr: "0129", prod: "8104", deviceId: "49D2", deviceJoinName: "Yale Assure Lock 2 Touch Touchscreen Key ZW3 module(YRD420-F)" command "initialize", [[name:"Clear state variables, refresh current states"]] } preferences { input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true input name: "debugEnable", type: "bool", title: "Enable debug logging", defaultValue: true input name: "traceEnable", type: "bool", title: "Enable trace logging", defaultValue: false } } import hubitat.zwave.commands.doorlockv1.* import hubitat.zwave.commands.usercodev1.* import hubitat.zwave.commands.notificationv3.* import hubitat.zwave.commands.supervisionv1.* // --- Device Identification def getZWaveDeviceId() { def decimalId = device.getDataValue("deviceId") if (!decimalId) return null try { // Convert the decimal string to an integer int idInt = Integer.parseInt(decimalId) // Format to a 4-character, upper-case, padded Hex string return String.format("%04X", idInt) } catch (NumberFormatException e) { // Fallback in case it's already a non-numeric/hex string return decimalId } } // Command class versions, used for top-level parsing and for unwrapping the // Supervision / Security encapsulated commands. private Map getCommandClassVersions() { return [0x98: 1, 0x62: 1, 0x71: 3, 0x80: 1, 0x85: 2, 0x86: 1, 0x63: 1, 0x6C: 1] } // --- Core Z-Wave Parsing --- def parse(String description) { if (traceEnable) log.trace "parse(String description): ${description}" // Z-Wave JS reports each Access Control state variable as its own value update, and the hub // rebuilds a NotificationReport with event = the state's value. "Door state" values are real // event codes (22/23), but "Opening state" is 0/1 (closed/open), so every door open arrived as // event 1 (Manual Lock). Door state already covers open/close, so drop Opening state entirely. if (description.startsWith("{")) { def json = parseJson(description) if (json.cc == 113 && json.values?.any { it.propertyKey == "Opening state" }) { if (debugEnable) log.debug "Ignoring Z-Wave JS 'Opening state' update (duplicates Door state)" return null } } def result = null def cmd = zwave.parse(description, commandClassVersions) if (cmd) { result = zwaveEvent(cmd) if (debugEnable) log.debug "Parsed ${cmd} to ${result.inspect()}" } return result } // --- S2 Security Supervision Handler --- def zwaveEvent(SupervisionGet cmd) { if (traceEnable) log.trace "zwaveEvent(SupervisionGet cmd): ${cmd}" if (debugEnable) log.debug "SupervisionGet: $cmd" def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions) if (encapsulatedCommand) { zwaveEvent(encapsulatedCommand) } sendHubCommand(new hubitat.device.HubAction(zwaveSecureEncap(zwave.supervisionV1.supervisionReport(sessionID: cmd.sessionID, reserved: 0, moreStatusUpdates: false, status: 0xFF, duration: 0).format()), hubitat.device.Protocol.ZWAVE)) return null } def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) { if (traceEnable) log.trace "zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd): ${cmd}" def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions) if (encapsulatedCommand) { return zwaveEvent(encapsulatedCommand) } } // --- Lock Operation & State --- def zwaveEvent(DoorLockOperationReport cmd) { if (traceEnable) log.trace "zwaveEvent(DoorLockOperationReport cmd): ${cmd}" def map = [name: "lock"] if (cmd.doorLockMode == 0xFF) { map.value = "locked" map.descriptionText = "${device.displayName} was locked" } else if (cmd.doorLockMode == 0xFE) { // 0xFE means the lock doesn't know the bolt position (e.g. jammed or mid-travel), so it must // not be reported as unlocked. map.value = "unknown" map.descriptionText = "${device.displayName} reports an unknown lock state" } else { map.value = "unlocked" map.descriptionText = "${device.displayName} was unlocked" } // The Access Control notification that precedes this report already logged the operation in // detail, and Z-Wave JS also tends to deliver this report twice. So only log at info when this // report is what actually changes the lock state (e.g. the notification was lost in transit). if (device.currentValue("lock") != map.value) { if (txtEnable) log.info map.descriptionText } else if (debugEnable) { log.debug map.descriptionText } sendEvent(map) } // --- Consolidated Event Reporting --- def zwaveEvent(NotificationReport cmd) { if (traceEnable) log.trace "zwaveEvent(NotificationReport cmd): ${cmd}" if (debugEnable) log.debug cmd.event // Notification Type 0x06: Access Control if (cmd.notificationType == 0x06) { def map = [name: "lock", isStateChange: true] switch (cmd.event) { case 0x01: // Manual Lock map.value = "locked" map.type = "physical" map.descriptionText = "${device.displayName} was locked manually" break case 0x02: // Manual Unlock map.value = "unlocked" map.type = "physical" map.descriptionText = "${device.displayName} was unlocked manually" break case 0x03: // RF/App Lock map.value = "locked" map.type = "digital" map.descriptionText = "${device.displayName} was locked digitally" break case 0x04: // RF/App Unlock map.value = "unlocked" map.type = "digital" map.descriptionText = "${device.displayName} was unlocked digitally" break case 0x05: // Keypad Lock map.value = "locked" map.type = "physical" map.descriptionText = "${device.displayName} was locked via keypad" break case 0x06: // Keypad or Fingerprint Unlock (With User Data) // Old stack: embedded User Code Report [0x63, 0x03, slot, status, code...] -> slot at [2]. // Z-Wave JS: the hub passes parameters.userId through as a single byte -> slot at [0]. // (eventParametersLength is not kept consistent with eventParameter, so don't use it.) def params = cmd.eventParameter def slotId = (params?.size() >= 3 && params[0] == 0x63 && params[1] == 0x03) ? params[2] : params?.getAt(0) def codeName = getCodeName(slotId) map.value = "unlocked" map.type = "physical" map.data = [(slotId.toString()): [name: codeName]] // On at least some ZW3 variants, Yale reports both keypad and fingerprint unlocks // as event 0x06 with identical event parameters, only distinguishing them in the // legacy v1 alarm type. Z-Wave JS doesn't pass the v1 alarm type through (it's always 0), // so there both read as keypad. if (cmd?.v1AlarmType == 0x91) { map.descriptionText = "${device.displayName} unlocked by ${codeName} via fingerprint" } else { // Keypad match observed as 0x13 but just defaulting here map.descriptionText = "${device.displayName} unlocked by ${codeName} via keypad" } sendEvent(name: "lastCodeName", value: codeName) break case 0x09: // Auto Lock map.value = "locked" map.type = "physical" map.descriptionText = "${device.displayName} was auto-locked" break case 0x07: // Manual Not Fully Locked case 0x08: // RF/App Not Fully Locked case 0x0A: // Auto Lock Not Fully Locked case 0x0B: // Lock Jammed map.value = "unknown" map.descriptionText = "${device.displayName} is jammed" log.warn map.descriptionText break case 0x0D: // Code Deleted // The lock sends this after it has cleared the slot, so for a delete we initiated it IS the // confirmation: drop the slot now rather than waiting on a read-back that, on a slow link, // arrives after Lock Code Manager has already started retrying the delete. Z-Wave JS doesn't // pass this event's slot through (eventParameter is empty), so the slot comes from the pending // delete that deleteCode() recorded. A delete we didn't initiate falls back to reading the // slot back, which is safe even if state.slotId is stale. def pending = state.pendingDelete if (pending && now() - (pending.at as Long) < 120000) { def deletedSlot = pending.slot state.remove("pendingDelete") def codes = loadLockCodes() if (codes.containsKey(deletedSlot)) { codes.remove(deletedSlot) updateLockCodes(codes) sendEvent(name: "codeChanged", value: "${deletedSlot} deleted", descriptionText: "Code position ${deletedSlot} deleted", isStateChange: true) } if (txtEnable) log.info "${device.displayName} deleted lockcode ${deletedSlot}" return } def slotId = state.slotId if (txtEnable) log.info "${device.displayName} deleting lockcode ${slotId}..." executeCommand(zwaveSecureEncap(zwave.userCodeV1.userCodeGet(userIdentifier: slotId))) return case 0x0E: // Code Added/Changed //def slotId = cmd.eventParameter[0] def slotId = state.slotId if (txtEnable) log.info "${device.displayName} syncing code ${slotId}..." executeCommand(zwaveSecureEncap(zwave.userCodeV1.userCodeGet(userIdentifier: slotId))) return case 0xFE: // Keypad Unlock with Fingerprint map.value = "unlocked" map.type = "physical" map.descriptionText = "${device.displayName} unlocked by Fingerprint match" break // Z-Wave JS re-sends the current Door state whenever other Notification values change // (e.g. alarmType/alarmLevel on a lock operation), and sometimes delivers it twice, so the // same door state arrives 2-3 times per open/close. Contact is a state, so let Hubitat drop // repeats (no isStateChange) and only log when the value actually changes. case 0x16: // Door Opened map.name = "contact" map.value = "open" map.descriptionText = "${device.displayName} was opened" map.remove("isStateChange") if (txtEnable && device.currentValue("contact") != map.value) log.info map.descriptionText break; case 0x17: // Door Closed map.name = "contact" map.value = "closed" map.descriptionText = "${device.displayName} was closed" map.remove("isStateChange") if (txtEnable && device.currentValue("contact") != map.value) log.info map.descriptionText break default: log.info "Unknown event ${cmd.event} param0: ${cmd.eventParameter[0]} param1: ${cmd.eventParameter[1]} param2: ${cmd.eventParameter[2]}" break } if (map.value) { // Lock events log here; contact events log in their own cases, and jams already warned. if (map.name == "lock" && map.value != "unknown" && txtEnable) log.info map.descriptionText sendEvent(map) } } } // Fallback handler for older Yale Z-Wave reporting structures (RF/App/Manual) def zwaveEvent(hubitat.zwave.commands.alarmv2.AlarmReport cmd) { if (traceEnable) log.trace "zwaveEvent(hubitat.zwave.commands.alarmv2.AlarmReport cmd): ${cmd}" // Alarm Type 0x09: Access Control (Legacy/RF Events) if (cmd.alarmType == 0x09) { switch (cmd.alarmLevel) { case 0x01: // Manual Lock case 0x02: // Manual Unlock case 0x03: // RF Lock case 0x04: // RF Unlock def status = (cmd.alarmLevel % 2 != 0) ? "locked" : "unlocked" sendEvent(name: "lock", value: status, descriptionText: "${device.displayName} ${status} via ${cmd.alarmLevel > 2 ? 'App' : 'Manual'}") break } } // Handle DoorSense (if reported via AlarmReport) if (cmd.alarmType == 0x16 || cmd.alarmType == 23) { return handleDoorSenseReport(cmd) } } // --- Lock Code Manager Integration --- def zwaveEvent(UserCodeReport cmd) { if (traceEnable) log.trace "zwaveEvent(UserCodeReport cmd): ${cmd}" def codePosition = cmd.userIdentifier.toString() def lockCodes = loadLockCodes() if (cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_OCCUPIED) { def pin = cmd.userCode.toString() // When adding a code, ZW3 has been observed to send 3 UCRs: full code, first digit, then full code again. // Usually this is fine since the last one takes, but sometimes it's dropped and we end up with the truncated version. // This ignores any truncated code -- safe since Yale lock codes are min 4 digits anyway. if (pin.length() == 1) { return null } if (!lockCodes.containsKey(codePosition)) { lockCodes[codePosition] = [name: "User ${codePosition}", code: pin, status: "active"] sendEvent(name: "codeChanged", value: "${codePosition} updated", descriptionText: "Code position ${codePosition} updated", isStateChange: true) } else if (lockCodes[codePosition].code != pin) { lockCodes[codePosition] = [name: lockCodes[codePosition].name, code: pin, status: "active"] sendEvent(name: "codeChanged", value: "${codePosition} updated", descriptionText: "Code position ${codePosition} updated", isStateChange: true) } } else { if (lockCodes.containsKey(codePosition)) { lockCodes.remove(codePosition) sendEvent(name: "codeChanged", value: "${codePosition} deleted", descriptionText: "Code position ${codePosition} deleted", isStateChange: true) } } updateLockCodes(lockCodes) } def setCode(codePosition, pin, codeName = null) { if (traceEnable) log.trace "setCode(codePosition, pin, codeName = null): ${codePosition}, ${pin}, ${codeName}" if (!codeName) codeName = "User ${codePosition}" state.slotId = codePosition def lockCodes = loadLockCodes() lockCodes[codePosition.toString()] = [name: codeName, code: pin.toString(), status: "active"] updateLockCodes(lockCodes) executeCommand(zwaveSecureEncap(zwave.userCodeV1.userCodeSet(userIdentifier: codePosition, userIdStatus: 1, userCode: pin))) } def deleteCode(codePosition) { if (traceEnable) log.trace "deleteCode(codePosition): ${codePosition}" log.info "deleting code ${codePosition}" state.slotId = codePosition // Lets the "code deleted" notification (event 0x0D) be trusted as confirmation for this slot. state.pendingDelete = [slot: codePosition.toString(), at: now()] executeCommand(zwaveSecureEncap(zwave.userCodeV1.userCodeSet(userIdentifier: codePosition, userIdStatus: 0))) } def getCodes() { if (traceEnable) log.trace "getCodes()" executeCommand(zwaveSecureEncap(zwave.userCodeV1.usersNumberGet())) } private getCodeName(slotId) { if (traceEnable) log.trace "getCodeName(slotId): ${slotId}" def codes = loadLockCodes() def entry = codes["${slotId}"] ?: codes[slotId] return entry?.name ?: "User ${slotId}" } private Map loadLockCodes() { if (traceEnable) log.trace "loadLockCodes()" def lockCodes = device.currentValue("lockCodes") def decrypted = decrypt(lockCodes) ?: lockCodes return parseJson(decrypted ?: "{}") ?: [:] } private void updateLockCodes(lockCodes) { if (traceEnable) log.trace "updateLockCodes(lockCodes): ${lockCodes}" def json = new groovy.json.JsonOutput().toJson(lockCodes) sendEvent(name: "lockCodes", value: json, displayed: false, descriptionText: "Lock codes updated") } def zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd) { if (traceEnable) log.trace "zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd): ${cmd}" // 0xFF (255) is Z-Wave's standard report for a low battery warning def percent = (cmd.batteryLevel == 0xFF) ? 1 : cmd.batteryLevel def descText = "${device.displayName} battery is ${percent}%" if (txtEnable) log.info descText sendEvent( name: "battery", value: percent, unit: "%", descriptionText: descText, isStateChange: true ) } // Catch-all for any other unhandled Z-Wave commands to prevent future MissingMethodExceptions def zwaveEvent(hubitat.zwave.Command cmd) { if (traceEnable) log.trace "zwaveEvent(hubitat.zwave.Command cmd): ${cmd}" if (debugEnable) log.debug "Unhandled Z-Wave Command: $cmd" } def zwaveEvent(hubitat.zwave.commands.usercodev1.UsersNumberReport cmd) { if (traceEnable) log.trace "zwaveEvent(hubitat.zwave.commands.usercodev1.UsersNumberReport cmd): ${cmd}" if (debugEnable) log.debug "UsersNumberReport: lock supports ${cmd.supportedUsers} codes" //sendEvent(name: "maxCodes", value: cmd.supportedUsers, displayed: false) // Update the maxCodes attribute so Lock Code Manager knows the limit // 250 user slots leaving 5 for firmware use (programming codes etc) sendEvent(name: "maxCodes", value: 250, displayed: false) } // --- Actuator Commands --- def lock() { if (traceEnable) log.trace "lock()" executeCommand(zwaveSecureEncap(zwave.doorLockV1.doorLockOperationSet(doorLockMode: DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_SECURED))) } def unlock() { if (traceEnable) log.trace "unlock()" executeCommand(zwaveSecureEncap(zwave.doorLockV1.doorLockOperationSet(doorLockMode: DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED))) } def refresh() { if (traceEnable) log.trace "refresh()" def cmds = [] cmds << zwaveSecureEncap(zwave.doorLockV1.doorLockOperationGet()) cmds << zwaveSecureEncap(zwave.batteryV1.batteryGet()) sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZWAVE)) } // General App Events def configure() { if (traceEnable) log.trace "configure()" log.info "Configuring Association Groups..." // Group 1 is the Lifeline for Z-Wave locks, required to report events to the Hub def hubNode = zwaveHubNodeId def cmds = [] cmds << zwaveSecureEncap(zwave.associationV1.associationSet(groupingIdentifier: 1, nodeId: hubNode)) cmds << zwaveSecureEncap(zwave.associationV1.associationGet(groupingIdentifier: 1)) // Also request a full refresh to align current states cmds << zwaveSecureEncap(zwave.doorLockV1.doorLockOperationGet()) sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZWAVE)) //set user slots to 250 leaving the last 5 for firmware use (programming codes etc) sendEvent(name: "maxCodes", value: 250, displayed: false) } def initialize() { state.DriverVersion = getDriverVersion() state.slotId = 0 state.remove("pendingDelete") //detect zwave module that's installed def firstChar = getZWaveDeviceId().take(1) // or myString[0] if (firstChar == "0") { log.info "ZW2 module detected" state.module = "ZW2" } else if (firstChar == "4") { log.info "ZW3 module detected" state.module = "ZW3" } else { log.info "Unknown module detected" } //set user slots to 250 leaving the last 5 for firmware use (programming codes etc) then clean up the json. sendEvent(name: "maxCodes", value: 250, displayed: false) def lockCodes = loadLockCodes() for (int i = 251; i < 256; i++) if (lockCodes.containsKey(i.toString())) lockCodes.remove(i.toString()) updateLockCodes(lockCodes) } def installed(){ initialize() } def updated(){ initialize() } private executeCommand(command) { if (traceEnable) log.trace "executeCommand(command): ${command}" sendHubCommand(new hubitat.device.HubAction(command, hubitat.device.Protocol.ZWAVE)) }