Event triggering without a listener(?)

The following is a very basic app. Listens for a contact to open and then turns on the alarm and lights. Works as expected. What I don’t understand is this… why does closing the contact (the one that originally triggered the event) turn the alarm and lights off? I’m not listening for contact.close anywhere in the code. What is inherently causing these actions? I’m clearly missing something in Groovy.


    DawgOnKing Security System
    Author: Ryan Martin
    Date: 06/10/2014
        name: "DawgOnKing Security System",
        author: "Ryan Martin",
        description: "Sound Alarms and Flash Lights when contact is opened.",
        category: "Safety & Security",
        iconUrl: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/App-IsItSafe.png",
        iconX2Url: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/App-IsItSafe@2x.png"
    preferences {
    	section("Door/Window Sensors") {
    		input "houseContacts", "capability.contactSensor", title: "Sensors", multiple: true, required: true
    	section("Alarms/Settings") {
    		input "houseAlarms", "capability.alarm", title: "Alarms", multiple: true, required: true
    	section("Lights") {
    		input "houseLights", "capability.switch", title: "Lights", multiple: true, required: true
    	section("Notification") {
    def installed() {
    	log.debug "APP INSTALLED"
    	state.alarmActive = null
    def updated() {
    	log.debug "APP UPDATED"
    	state.alarmActive = null
    private subscribeToEvents() {
    	subscribe houseContacts, "contact.open", runContact
    	subscribe houseAlarms, "alarm", runAlarm
    /* When contact opens, log it, turn on alarms and lights. */
    def runContact(evt) {
    	log.debug "A contact has been opened. Alarms On. Requesting Lights."
    /* When alarms sounds, turn on lights */
    def runAlarm(evt) {
    	if(houseLights) {
        log.debug "Lights have been turned on as requested."
        if(evt.value == "off") {
        	log.debug "The alarm has been selected off. Turning off lights now."

BTW, this works 100% correctly in the console testing. Just doesn’t work in live testing at home.

Do you have a dashboard app setup to run an alarm for that contact? thats the only thing i can think of. The app you wrote looks fine to me.

I do Tim. That’s what I meant by in console (sorry, that’s a Rails term). Anyway, works correctly in dashboard. Fails in live home testing.

i would uninstall it from the mobile dashboard and see if that changes things. Remove all the variables and then test :smile:

Yeah, I’m writing different variations as we speak. Removed the alarm listener and replaced with lights, etc, etc.

Will update once I get something functional. Thanks.

Nothing I try works. Every time I close the door that triggers the sequence, the alarm turns off.

At this point I think it’s a hardware communication feature that I can’t override. Disappointing.

Maybe instead of writing your own app you can use the dashboard in the mobile app to set up this trigger? it might work as you intend it to from there. I don’t have an alarm(yet) so i can’t test.

Tim, you’re a genius! :smile:

The whole reason I wrote my own app was because installing through the dashboard resulted in the alarm turning off when the contact was closed. I completely forgot to uninstall that behavior for the door I’ve been testing on. As a result, it was overriding my custom app.

After uninstalling the default behavior and implementing my original code, it works! Cheers my friend!

1 Like

Glad i could help!:slight_smile: This community rocks!

1 Like