Ah, thanks. That did the trick. I appreciate the feedback. So here’s my pretty brute-force solution to my specific need. I tried the Unlock Too program from Barry, but it was doing some odd behaviors - setting then re-setting the mode. So this just sends a message and sets your mode when a specific lock code is used.
I have an open/close sensor on my door as well, and I was pleased to see the mode change occurs in the proper sequence so the alarm doesn’t go off because of the open/close sensor… that would be an unwelcome surprise for the cleaners.
/**
- Cleaners have arrived
- Copyright 2014 Chris Cooney
- 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.
*/
definition(
name: “Cleaners have arrived”,
namespace: "cooney.christopher@gmail.com",
author: “Chris Cooney”,
description: “Sends a message and sets status when a particular user code is used on a door lock”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences
{
section(“When a door unlocks…”) {
input “lock1”, “capability.lock”
}
section(“And this user opened the door:”){
input “User1”, “enum”, title: “User Code”, metadata:[values:[“1”,“2”,“3”,“4”,“5”]]
}
section(“Send this message (optional, sends standard status message if not specified)”){
input “msg”, “text”, title: “Message Text”, required: false
}
section( “Notifications” ) {
input “sendPushMessage”, “enum”, title: “Send a push notification?”, metadata:[values:[“Yes”,“No”]], required:false
input “phone”, “phone”, title: “Send a Text Message?”, required: false
}
section(“And change to this mode”) {
input “newMode”, “mode”, title: “Mode?”, required: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribeToEvents()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribeToEvents()
}
def subscribeToEvents() {
log.debug "Settings: ${settings}"
subscribe(lock1, “lock”, eventHandler)
}
def eventHandler(evt) {
if (evt.value == “unlocked”) {
if (evt.data == ‘{“usedCode”:’+User1+’}’)
{
setLocationMode(newMode)
send(evt)}
}}
private send(evt) {
if ( sendPushMessage != “No” ) {
log.debug( “sending push message” )
sendPush( msg )
}
if ( phone ) {
log.debug( “sending text message” )
sendSms( phone, msg )
}
log.debug msg
}