(Enhanced) Z-Wave Schlage Touchscreen Lock

code has been updated. Breaking with the existing non-standard ST standard, I’m now using the lock/unlock event’s “userCode” to indicate a manual (“manual”), automatic (“auto”) or keypad (without code)(0) event. When the lock command is performed via a z-wave operation (such as using the ST mobile app to lock the door), there’s no userCode at all.

This app is great! Thanks so much. I’m trying to add a couple functionalities to this app but it seems my programming skills are a bit rusty.
In short, my concept is if I unlock with a certain code, it will update the mode and turn on a particular song on sonos.

I’ve added components from the Sonos Mood Music template to attempt to achieve this.
Here’s the Sonos Mood Music code:

I’ve been receiving this error:
java.lang.NullPointerException: Cannot get property ‘selectedSong’ on null object @ line 69
Highlighted below

Any help of course would be greatly appreciated.


  • Door Unlock Triggers
  • Copyright 2015 Gary D
  • 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.


name: “Door Unlock Triggers with music selection”,
namespace: “garyd9”,
author: “Gary D”,
description: “Triggers switches, door controls, etc based on lock events”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
section(“When a door unlocks…”) {
input “lock1”, “capability.lock”, title: “Door Lock?”, required: true
input “mySwitch”, “capability.switch”, title: “Switch? (for debugging)”, required: false
section(“And this user code opened the door:”) {
input “User1”, “enum”, title: “User Code”, metadata:[values:[“1”,“2”,“3”,“4”,“5”]]
input “doors”, “capability.doorControl”, title: “Close these doors”, multiple: true, required: false
input “switches”, “capability.switch”, title: “Turn on these switches”, multiple: true, required: false
input “newMode”, “mode”, title: “Change to this mode”, multiple: false, required: false
input name: “sendPush”, type: “bool”, title: “Push notification to mobile devices?”, defaultValue: false
input “sonos”, “capability.musicPlayer”, title: “On this Sonos player”, required: false
input “song”, “enum”, title:“Play this track”, required:false, multiple: false, options: songOptions()
label title: “Assign a name”, required: false
def installed() {
log.debug "Installed with settings: ${settings}"
def updated() {
log.debug "Updated with settings: ${settings}"
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
subscribe(lock1, “lock.unlocked”, lockHandler)
subscribe(mySwitch, “switch”, switchHandler, [filterEvents: false])
log.debug "about to subscribe to command…"
subscribeToCommand(mySwitch, “on”, switchOnHandler)


private songOptions() {

// Make sure current selection is in the set

def options = new LinkedHashSet()

if (state.selectedSong?.station) { // THIS IS WHERE THE ERROR OCCCURS
options << state.selectedSong.station
else if (state.selectedSong?.description) {
// TODO - Remove eventually? ‘description’ for backward compatibility
options << state.selectedSong.description

// Query for recent tracks
def states = sonos.statesSince("trackData", new Date(0), [max:30])
def dataMaps = states.collect{it.jsonValue}

log.trace "${options.size()} songs in list"
options.take(20) as List


private saveSelectedSong() {
try {
def thisSong = song
log.info "Looking for $thisSong"
def songs = sonos.statesSince(“trackData”, new Date(0), [max:30]).collect{it.jsonValue}
log.info “Searching ${songs.size()} records”

	def data = songs.find {s -> s.station == thisSong}
	log.info "Found ${data?.station}"
	if (data) {
		state.selectedSong = data
		log.debug "Selected song = $state.selectedSong"
	else if (song == state.selectedSong?.station) {
		log.debug "Selected existing entry '$song', which is no longer in the last 20 list"
	else {
		log.warn "Selected song '$song' not found"
catch (Throwable t) {
	log.error t


def performActions(evt)
doors.eachWithIndex {s, i ->
def state = s.latestValue(“door”)
if (state == “open”)
log.debug "$s is currently $state. Closing it."
log.debug “$s is currently $state. (can’t close it)”
switches.eachWithIndex {s, i ->
def state = s.latestValue(“switch”)
if (state == “off”)
log.debug "$s is currently $state. Turning it on."
log.debug “$s is already $state.”
log.debug "We made it this far!!!“
if (sendPush)
def lockHandler(evt)
if (evt.data == null)
log.debug “evData is null”
def evData = parseJson(evt.data)
log.debug “evData.usedCode: ${evData.usedCode}. Attempting to find user $User1"
if (”${evData.usedCode}” == “$User1”)
log.debug User1 + " unlocked the door!"
def switchHandler(evt)
// performActions(evt)
log.debug “switchHandler ${evt.value}”
def switchOnHandler(evt)
log.debug “switchOnHandler ${evt.inspect()}”

(Sorry for taking so long to reply - been on vacation.) I don’t think there’s anything I can do to help here. Perhaps trying to ask folks more familiar with sonos would help?

This is great! Is there a way to get the app to send me an SMS when a user code is entered, rather than a mobile notification? My wife is logged in on her phone as well, so I’d prefer just an SMS to my phone if possible. Thanks!

Hello! I am super new here. I have been super let down by how confusing the SmartThings app is. I went all in bought all the stuff, got the Schlage Deadbolt, and now 6 months later, SmartThings still doesn’t even think its a “door” Anyways, today I discover that all the functionality is here made by a community member. And there is a website for SmartThings its just a “Developer” site? Alright thats all to say I am trying to figure this all out.

So I was able to find the code on github, I went to the developer portal, but then when I go looking where to add this new device’s code I cannot find it at all?!

Maybe I am diving too deep too quickly. Is there a way to set up rules on a webpage?

Yeah, it can get very confusing.

There are two rules engines that have been created by community members that you could give a try. One is only available for iOS, Obyrules, and the other is web-based by JoeC. Neither are officially supported by smartthings, but they’re worth a look.

For an overview of all the various scheduling options that are available, including where you can usually find custom code, take a look at this:

1 Like

Ok, so what I realized is I had the account on the graph.api.smartthings.com but I didn’t have the account approved for a developer account, so adding the smart apps wasn’t possible.

But still its amazing that the process is this bonkers. I get they don’t want people to mess up their smart homes, and thus make it a little hard to get this level of access. But once I found the steps, in 2 mins I had an updated thermostat, and a updated front door lock. Seems like they need an “appstore” where people can share these and allow people to try them out, and then rate them. Doing it all through a forum seems really lazy.

But I am soo soo happy for the community, and I love that people are even writing apps! So here is to that!



Nice work Gary. Fun playing with this versus my zigbee yale touchscreen (until it died…) These are pretty good for the price point.

1 Like

Thank you for your work, Gary, however when I try this code on my BE469NX - Century style, lock only responds to open command and no longer responds to anything after that. Lock works great with generic driver “Z-Wave Lock” that is comes up when I pair it under this model in “things”. Any help would be greatly appreciated. Btw, I noticed that same exact behavior happens in the simulator, it only unlocks there and stop responding.

Thanks for this great app. I would like to suggest an enhancement. It would be interesting to change the delay for auto lock to be triggered. But I not very familiar with this type of code. Can you tell me how to change this parameter in your code? Also, it would probably be interesting to add this as a end user parameter for futur versions.

Thanks again


[quote=“petruha98, post:32, topic:10034”]
however when I try this code on my BE469NX - Century style, lock only responds to open command and no longer responds to anything after that.
[/quote]Did it fully work at any time? What shows up in the live logging page on the IDE? Please describe, in detail, what you are doing to “open” it, and what else you’re trying to do. Please don’t make assumptions in your descriptions - assume you’re describing it to a 2 year old and go step by step.

I’m not worried about the simulator - I never really used that to develop against, so might have not bothered to fully support it.

Auto-lock delay isn’t user configurable. It’s just an “on/off” toggle in the lock itself.

  1. Open “New Device Type” in dev page
  2. Copy code from github
  3. Pasted to New Device Type
  4. Saved -> that created new device type “Z-Wave Schlage Touchscreen Lock”.
  5. Published -> For Me … successfully
  6. Removed lock from Things, re-added it as new “Z-Wave Schlage Touchscreen Lock” type. so far so good…
  7. App shows green “Locked”… pushed the green “Locked” button, lock responds almost immediately, opens, and icon (tile) changes to grey “Unlocking”… thats it… it would not change state to “Unlocked” or respond to any other commands.

Sorry, i do not have live log, as I actually need it working, so I moved it back to default Z-Wave Lock driver that finds this lock by default. Lock responds almost immediately to that driver, open/close/battery… though unfortunately no other fancy details. I am ok for testing though, if you need that live log I would be able to re-create device driver and test next week. If you want to take it off-line, may be that would be easier to communicate… and again thank you so much for your work and support.

I’ve tried, but I’m unable to repeat your issue. I’m not even sure how things could have gone wrong, as the basic code for lock/unlock is nearly identical to the ST device type. If you can capture live logging of some breakage, I’ll be happy to look into it.

Take care

@garyd9, is this something you can add to your device type to enable communication with the Smart Alarm app when the lock senses tampering or forced entry?

I can, but I probably won’t. It’s a hack that I’m uncomfortable with.

I’ve been trying to get ST to add a standard mechanism to “alert” for critical events for more months than I can count. There’s been several discussions, suggestions, and everything seems to get completely ignored by ST in the end.

To be quite honest, I’m tired of banging my head against a brick wall.

Unless ST takes an interest in their own product (and visibly demonstrates that interest), I’m pretty much done trying to work around and force their system to do sensible things.

Oh, and adding @April. Perhaps she can get someone to look into this again.


@garyd9 I’m also fedup with ST, their platform is going from bad to worse. Not to jump the topic but when basic features don’t work (last few days the event filtering is no longer working, see this thread below) I don’t see how they can devote time to any new stuff.

Update 2015-08-22

I merged all the changes from the ST “z-wave lock” device type back into this device type. This seems to add a couple bug fixes as well as changes to security related stuff. The device type is also mostly compatible with Erik Thayer’s “lock code manager” smart app. (However, there are a few change requests I’ve made to Erik that would make the compatibility a bit better.)

Erik’s FREE lock code manager: [Depricated] Lock Code Manager

Current incompatibilities with that lock code manager:

1: When the Schlage lock is queried what user codes it has stored, it will only respond with asterisks for used slots. (Most likely a security measure from Schlage.) This only matters if the device type doesn’t already have the user codes cached (which it normally does.) This will cause Erik’s lock code manager to re-send the usercodes. No real impact here.

2: Erik’s code is designed to work with Kwikset locks which allow different user code slots to have different lock code lengths. For example, slot 1 might have a 6 digit code while slot 2 has a 5 digit code. With the Schlage locks, all the slots must use the same length, and that length must be configured on the lock ahead of time. (I can change the length in code, but the command for changing the length erases ALL existing user codes, so I don’t expose that to a user. My opinion is that it’s better to make the user perform that manually so they understand it’s destructive and don’t blame me.)

3: As of this message, Erik’s lock code manager will spit out errors in the IDE “live logging” when a user manually locks/unlocks the door. These errors are harmless and have NO impact. (As well, they’ll likely be going away in a day or two of this post.)


Hi Gary - so is it now Erik’s lock code manager (the link you published) that we should try with the Schlage Camelot touchpad lock? There are so many posts going back a long time on this, but this appears to be the latest and greatest, or whatever device you merged all this into. Thanks in advance, I haven’t tried anything with the lock other than the native ST device, but need remote pin control for a distance house. Thanks!

Yes, right now I’d suggest using @ethayer’s lock code manager with this device type (if you want any lock manager at all.) It’s a bit more robust than any other I’ve played with. There are a couple of issues that I’ve noted. As of right now, Erik hasn’t updated it, but issues that need an update are (in my opinion) minor issues that really don’t impact the use of the manager.

Take care