contactSensor.open Event not Firing

Hi, I am new to SmartThings and am writing my first program. I am writing a home security app and have learned a lot and made good progress so far but have hit a snag that I can’t seem to figure out. I have a door contact sensor (Aeotec Door/Window Sensor 6) in my system. The goal is to do some stuff like send texts and sounds alarms when the system is armed and the sensor “opens”. There are lot’s of great code examples on how to set up the input, subscribe and eventHandler code. I have successfully tested location. mode change events, but can’t seem to get the door sensor to fire an event by opening both virtual and physical devices. For what it’s worth, the lock handler doesn’t seem to work either. Seems pretty basic but I must be missing something. I have posted the code below. Any thoughts are appreciated.

preferences {

section("Change to this mode") {

input "newMode", "mode", title: "Mode?"

}

section("When these doors unlock") {

input "lock1", "capability.lock", title: "Select door locks", multiple:true

}

section("When these door switches open") {

input "contact1", "capability.contactSensor", title: "Select contact Sensors", multiple:true

}

section("When these smoke detectors sound") {

input "smokeDetector", "capability.smokeDetector", title: "Select smoke Detector", multiple:true

}

section("When these carbon monoxide detectors sound") {

input "carbonMonoxideDetector", "capability.carbonMonoxideDetector", title: "Select CO Detector", multiple:true

}

section("False alarm threshold (defaults to 10 min)") {

input "falseAlarmThreshold", "decimal", title: "Number of minutes", required: false

}

section("Text me at…") {

input("recipients", "contact", title: "Send notifications to") {

input "phone1", "phone", title: "SMS Phone Number?"

}

}

}

def installed() {

log.debug "Installed with settings: ${settings}"

initialized()

}

def updated() {

log.debug "Updated with settings: ${settings}"

unsubscribe()

initialized()

}

def initialized(){

log.debug "Initialized with settings: ${settings}"

subscribe(location,"mode", modeChangeHandler)

subscribe(contact1, "contact1.open",contactOpenHandler)

subscribe(lock1, "lock1",lockOpenHandler)

subscribe(smokeDetector, "smokeDetector.detected",smokeDetectorDetectedHandler)

subscribe(carbonMonoxideDetector, "carbonMonoxideDetector.detected",carbonMonoxideDetectorDetectedHandler)

}

def modeChangeHandler(evt){

state.currentMode = location.mode

}

def contactOpenHandler (evt) {

log.debug "Your ${contact1.label ?: contact1.name} was opened"

runIn(60*10,soundAlarms(evt))

}

def lockOpenHandler (evt) {

log.debug "Your ${lock1.label ?: lock1.name} was opened"

}

My limited understanding is that the second argument to subscribe() should be an attribute or an attribute and value. So I think you probably need “contact.open”, “lock” (or “lock.unlocked” if you are only interested in unlocked events), “smoke.detected” and “carbonMonoxide.detected”.

3 Likes

orange bucket, thanks for responding quickly. You comment prompted me to realize me error, which was in the subscribe implementation. The line which prevented the event handler from firing was written as “subscribe(contact1, “contact1.open”,contactOpenHandler)”, the correction I made is "subscribe(contact1, “contact.open”,contactOpenHandler). Now the code works fine.

1 Like