ok I modified someone’s code where it checks to see if a door is open. I wanted to add the feature of checking to see if a lock is locked as well.
Here is the code and my log messages.
preferences {
section(“Which mode changes trigger the check?”) {
input “newMode”, “mode”, title: “Which?”, multiple: true, required: false
}
section(“When should I check? (once per day)”) {
input “timeToCheck”, “time”, title: “(Optional)”, required: false
}
section(“Which doors should I check?”){
input “door”, “capability.contactSensor”, title: “Which?”, multiple: false, required: true
input “lock”, “capability.lock”, title: “Which?”, multiple: true, required: false
}
}
def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe() unschedule() initialize()
}
def initialize() {
if (newMode != null) {
subscribe(location, modeChangeHandler)
}
if (timeToCheck != null) {
schedule(timeToday(timeToCheck, location.timeZone), checkDoor)
}
}
def modeChangeHandler(evt) {
log.debug “Mode change to: ${evt.value}”
// Have to handle when they select one mode or multiple if (newMode.any{ it == evt.value } || newMode == evt.value) { checkDoor() checkLock() }
}
def checkDoor() {
log.debug “Door ${door.displayName} is ${door.currentContact}”
if (door.currentContact == “open”) {
def msg = “${door.displayName} was left open!”
log.info msg
sendPush(msg)
} else {
log.debug “It wasn’t open.”
}
}
def checkLock() {
log.debug “Lock ${lock.displayName} is ${lock.currentLock}”
if (lock.currentLock == “unlocked”) {
def msg = “${lock.displayName} is unlocked!”
log.info msg
sendPush(msg)
} else {
log.debug “It wasn’t unlocked.”
}
}
1:55:32 PM:
debug
It wasn’t unlocked.
1:55:32 PM:
debug
Lock [Front Door] is [unlocked]
1:55:32 PM:
debug
It wasn't open.
1:55:32 PM:
debug
Door Garage Door is closed
1:55:32 PM:
debug
Mode change to: Experimental
I think the error must be in here
def checkLock() {
log.debug “Lock ${lock.displayName} is ${lock.currentLock}”
if (lock.currentLock == “unlocked”) {
def msg = “${lock.displayName} is unlocked!”
log.info msg
sendPush(msg)
} else {
log.debug “It wasn’t unlocked.”
}
}
but it says if it is unlocked send message but it keeps doing the “else”. Suggestions?