Event triggering without a listener(?)


(DawgOnKing) #1

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.

Thanks.

 /*
    
    DawgOnKing Security System
    Author: Ryan Martin
    Date: 06/10/2014
    
    
    */
    
    definition(
        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"
    	subscribeToEvents()
    	state.alarmActive = null
    }
    
    def updated() {
    	log.debug "APP UPDATED"
    	unsubscribe()
    	subscribeToEvents()
    	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."
    	houseAlarms?.both()
    }
    
    /* When alarms sounds, turn on lights */
    def runAlarm(evt) {
    	if(houseLights) {
        houseLights?.on()
        }
        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."
            houseLights?.off()
        }
    }

(DawgOnKing) #2

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


(Tim Slagle) #3

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.


(DawgOnKing) #4

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.


(Tim Slagle) #5

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


(DawgOnKing) #6

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.


(DawgOnKing) #7

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.


(Tim Slagle) #8

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.


(DawgOnKing) #9

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!


(Tim Slagle) #10

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