Hi All,
I am a newbie. I have started to write my first app, but I have run into some questions and I was hoping some one can help answer my questions.
My app is to “warn if z-wave lock is locked BUT the Contact Sensor is Open” I can’t figure out how to read the state of the Contact Sensor. I am handling the door lock or unlock event and then want to check the contact Sensor to see if the door is really closed.
I tried this def sensorState = thesensor(“open”), but no cigar.
Here is my app: thanks, Sal
preferences {
section(“Check Door Closed When Locked”) {
input “thesensor”, “capability.contactSensor”, required: true, title: “Which Open/Close Sensor?”
}
section(“Doors Locked”){
input “thelock”, “capability.lock”, title:“door lock”, required: true, multiple: false
}
}
def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
subscribe(thelock, “lock.locked”, lockLockedHandler)
subscribe(thelock, “lock.unlocked”, lockLockedHandler)
}
// TODO: implement event handlers
def lockLockedHandler(evt){
def sensorState = thesensor(“open”)
if (evt.value == “locked”) {
// locked detected
log.debug "lockLockedHandler called: LOCK $evt"
if (sensorState.value == “open”) {
log.debug “lockLockedHandler detected $thesensor is OPEN”
}}
if (evt.value == “unlocked”) {
// unlocked detected
log.debug “lockLockedHandler called: UNLOCK $evt”
}
}