# Capability lockCodes (update)

**URL:** <https://community.smartthings.com/t/capability-lockcodes-update/17510>\
**Category:** Capability Type Suggestions\
**Created:** [June 5, 2015, 7:34pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510 "2015-06-05T19:34:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncan](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/duncan/32/11724_2.png) [@duncan](https://community.smartthings.com/u/duncan)\
**Post date:** [June 5, 2015, 7:34pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/1 "2015-06-05T19:34:58Z")

</div>

In preparation for the long-delayed official lock code management solution, we’re making some changes to how the “Lock Codes” capability works. The main difference is that we’re removing the actual unlock codes from the events and storage for security reasons.

Also, the `setCode` command will add an optional `name` argument that will let you give meaningful names to your codes so you know which code to delete or change when you need to. We decided to store this at the device level so you can eventually manage codes directly in the device preferences.

The proposed spec is below – let us know if you see anything missing or any issues that may hurt its usability.

### Attributes

`lockCodes` – JSON object mapping code IDs to code names. If a code hasn’t been set it won’t appear in the mapping. Example:

```auto
{ 1: "Code 1", 2: "Code 2", 3: "Alice", 4: "Bob", 8: "Carla" }

```

This means the lock has codes 1, 2, 3, 4, and 8 set, 1 and 2 were likely the default codes so they were automatically given default names.

`codeChanged` – An event attribute (i.e. current value is not relevant) with string value `"$id $change_type"` where `change_type` is one of `["set", "changed", "deleted", "failed"]` and `id` is either the integer code ID (0 for the master code) or “all”. Examples: “3 set”, “5 changed”, “all deleted”, “3 failed” – the “failed” status is sent when we try to set a code but the lock rejects it, for example because it was the wrong length or duplicated another code.

`codeLength` – The integer length of code string that the lock accepts, most locks default to 4 but have the option to increase it with the setCodeLength() command.

`maxCodes` – Reports the number of code slots the lock has, which is also the maximum code ID that can be set.

### Commands

`setCode(int id, String code, String name)` – Programs code `code` into code slot `id` – if the code is successfully set on the lock, it will update the `lockCodes` attribute value to indicate that code `id` is named `name`. The `code` parameter is generally a string of numerical characters, such as “0485” or “7777”. A `codeChanged` event will also be sent with the result of the operation, which is useful if you are editing an existing code or if the setCode fails.

`deleteCode(int id)` – Deletes code `id` from the lock and removes its name from `lockCodes`

`checkCode(int id)` – Will query the lock to determine if code `id` is set in order to update the `lockCodes` information. For example, if you delete code 4 using the lock’s keypad when your SmartThings hub is offline, we will not know that the code is no longer set until a call to `checkCode(4)`.

`checkAllCodes()` – Basically calls `checkCode(id)` for each code id in sequence to fully refresh the `lockCodes` information to accurately represent the current status of the lock.

`setCodeLength(int length)` – Most locks allow you to change the code length – they require that all codes are the same length so the keypad knows when to tell you that you entered the code wrong. Therefore changing the length will generally delete all existing codes, so it should be used carefully.

---

<div class="post-metadata">

**Author:** ![JDRoberts](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jdroberts/32/56577_2.png) [@JDRoberts](https://community.smartthings.com/u/JDRoberts)\
**Post date:** [June 5, 2015, 10:56pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/2 "2015-06-05T22:56:11Z")

</div>

Sounds like a good direction.

Did anything change overnight in the official device handler?

My Yale zwave lock began making voice announcements today, something it has not done since the original installation 8 months ago. Battery life is over 50%. We have not made any changes to the lock or codes. We do not use any custom SmartApps or device type with the lock.

_edited to add_ And after 6 hours of voice notifications, now they’ve stopped. No changes on our part, standard device type.

---

<div class="post-metadata">

**Author:** ![surfous](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/surfous/32/12168_2.png) [@surfous](https://community.smartthings.com/u/surfous)\
**Post date:** [June 6, 2015, 12:27am UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/3 "2015-06-06T00:27:15Z")

</div>

> [@duncan](#):
>
> setCodeLength(int length) – Most locks allow you to change the code length – they require that all codes are the same length so the keypad knows when to tell you that you entered the code wrong. Therefore changing the length will generally delete all existing codes, so it should be used carefully.

This isn’t how the Yale locks work, at least. Can’t speak for other mfrs/models. The Yales accept 4-8 character codes, and use the asterisk to denote the end of the code, so you can have mixed code lengths (I think this approach gives about an 11%-ish bump in keyspace)

But as long as my handler can noop on it, that’s fine as it supports other types of locks that care.

Therefore:

> [@duncan](#):
>
> codeLength – The integer length of code string that the lock accepts, most locks default to 4 but have the option to increase it with the setCodeLength() command.

Perhaps this should be a pair of attrs: minCodeLength and maxCodeLength? With the Yale, min=4; max=8. For a uni-length model min=max=4 (assuming it is indeed 4). If the unit supports having the code length set, then, both min and max would change accordingly (yet be equal).

> [@duncan](#):
>
> Also, the setCode command will add an optional name argument that will let you give meaningful names to your codes so you know which code to delete or change when you need to. We decided to store this at the device level so you can eventually manage codes directly in the device preferences.

I like this - this was how I’d originally developed my Yale handler, but excised names to the app level specifically because support for managing codes HAD to be at the app level.

---

<div class="post-metadata">

**Author:** ![dnintzel](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/dnintzel/32/93210_2.png) [@dnintzel](https://community.smartthings.com/u/dnintzel)\
**Post date:** [March 16, 2019, 11:54pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/4 "2019-03-16T23:54:30Z")

</div>

Hello, I don’t see **Capability.lockCodes** in the documentation and don’t see recent discussions, so what happened with the plan to add this capability?

I see there was a [Lock Code Manage](https://community.smartthings.com/t/depricated-lock-code-manager/12280) smartapp once upon a time that is deprecated and I’m familiar with the [Smart Lock Guest Access](https://support.smartthings.com/hc/en-us/articles/200958090-Smart-Lock-Guest-Access) but I want to create my own SmartApp to manage codes. Ultimately, I would like to see if I can then use Webhooks or such to control through my website. Are these possible?

Thanks,  
Doug

---

<div class="post-metadata">

**Author:** ![dansouza](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/dansouza/32/95743_2.png) [@dansouza](https://community.smartthings.com/u/dansouza)\
**Post date:** [April 13, 2019, 7:52pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/5 "2019-04-13T19:52:17Z")

</div>

@dnintzel were you able to find some documentation on how to manage lock users/codes? I’m looking for that as well to try and manage the users on a Yale lock. I can lock and unlock it, but I couldn’t find any documentation on how to manage code slots/etc. Any help would be appreciated if you found something!

---

<div class="post-metadata">

**Author:** ![tgauchat](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tgauchat/32/49516_2.png) [@tgauchat](https://community.smartthings.com/u/tgauchat)\
**Post date:** [April 14, 2019, 2:56am UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/6 "2019-04-14T02:56:39Z")

</div>

It’s just usual SmartThings’s _halfassedness_.

Capability “Lock” is quite fleshed out for **Attributes** , but certainly doesn’t haven’t documented _ **Commands** _ for even setting a single slot Lock Code(s), let alone complex management like scheduled, etc.

> **[SmartThings Developers](https://smartthings.developer.samsung.com/docs/api-ref/capabilities.html#Lock)**
>
> SmartThings Developers Documentation

---

<div class="post-metadata">

**Author:** ![dnintzel](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/dnintzel/32/93210_2.png) [@dnintzel](https://community.smartthings.com/u/dnintzel)\
**Post date:** [April 17, 2019, 9:05pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/7 "2019-04-17T21:05:41Z")

</div>

@dansouza, no, I never got responses and tried calling SmartThings-support, but they don’t support developers. I’ve seen some [articles](https://www.grc.com/sn/sn-559-notes.pdf) advising that feature caused security holes, so maybe it was scrapped?

@tgauchat  
When you say they are fleshed out, I assume that does not mean implemented, correct?

---

<div class="post-metadata">

**Author:** ![tgauchat](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tgauchat/32/49516_2.png) [@tgauchat](https://community.smartthings.com/u/tgauchat)\
**Post date:** [April 17, 2019, 9:25pm UTC](https://community.smartthings.com/t/capability-lockcodes-update/17510/8 "2019-04-17T21:25:13Z")

</div>

> [@dnintzel](#):
>
> When you say they are fleshed out, I assume that does not mean implemented, correct?

Capabilities themselves are not “implemented”.

They are a contract that if a Device Handler claims, then that DH must follow that documented contract.

So DHs implement Capabilities.

And they do… but not always correctly or completely. Compliance is weakly enforced.
