@April Please call this to the attention of the proper ST person.
I’m basing this off the existing “z-wave door lock” device type. In that case, when a PIN code is used to unlock a door, the event setting to the “lock” attribute to “unlocked” also sets the events map.data to a map containing [usedCode: x] (where “x” is the index of the PIN code used. 1 for the first PIN, 2 for the second, etc.)
Example:
map.name = "lock"
map.value = "unlocked"
map.data = cmd.eventParameter[0]
createEvent(map)
The same mechanism is used when a door is locked with a PIN code.
However, this mechanism is NOT used when a door is locked/unlocked by some other means (such as auto (un)locking, manual (un)locking, and single button (un)locking.) I’d like to see ST adopt using the “usedCode” mechanism for those other means of (un)locking a door.
I know I can do this for my own device types, but if smartApp’s are to take advantage of this type of system, it must use a consistent standard (and ST is the body that should dictate that by example in their pre-existing device types.) (Otherwise, specific device types must be paired with specific smartApps, instead of having smartApps that can take advantage of ANY of a class of devices.)
- For manual: map.data = [ usedCode: “manual” ]
- auto: map.data = [usedCode: “auto” ]
- from the keypad (but not with a PIN) such as the “Schalge” button on schlage locks: [ usedCode = 0 ]
- from anything else: [usedCode : null ] (or evt.data simply not set)
Note that there’s a special case for locking from the keypad… in that case, it’s similar to a PIN entry (as it’s using the keypad), but no actual code was entered (hence it’s assigned a numeric value, but the index is 0.) As well, this keeps it consistent with the messages passed from the door lock to the device type.
If this is done, a smartApp can easily determine HOW a door was locked or unlocked - which is often as important as IF a door was locked or unlocked.
Example code for parsing:
def lockHandler(evt)
{
def usedCode = null
if (evt.data != null)
{
usedCode = parseJson(evt.data).usedCode
}
// if a usedCode was set, check that for the method used to unlock
if (usedCode == null)
{
usedCode = "Other/Unknown"
log.debug "Lock was locked/unlocked via code $usedCode"
}
}
Edit: I just want to add that, as far as I can tell, there’s only a single existing device type (from ST) that this would impact: “z-wave lock”. The changes in there would be trivial to do.