Trigger actions on mode change


(Yogesh Mhatre) #1

Continuing the discussion from Trigger on mode change:

Im building similar which would trigger arm/disarm action for my alarm system based on the mode change. However it does not work for me. Here is the required part of the code. Can some one help me? Strangely I dont get any errors in console or any messages. I’m atleast expecting log.debug called in the modeChangeHandler()


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(location, modeChangeHandler)
}

def modeChangeHandler(evt) {
log.debug “$evt.value”
//session = login(token)

	if (evt.value == "Away") {
        	log.debug "Mode is Away, Performing ArmAway"
        	//armAway(session)   
        }
    else if (evt.value == "Night") {
        	log.debug "Mode is Night, Performing ArmStay"
        	//armStay(session)
        }
    else {
        	log.debug "Mode is Home, Performing DisArm"
        	//disarm(session)
    }
//return session

}


(Yogesh Mhatre) #2

Got it. I think that code was old. I had to call “location.mode” to get the right answer. And for some one newbie like me, here is a complete code


def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
log.debug "Initializing"
subscribe(location, modeChangeHandler)
modeChangeHandler()

}

def modeChangeHandler(session) {
log.debug "ModeChange Handler function"
log.debug "Inside modeChangeHandler. Current mode = ${location.mode}"
session = login(token) //Logs In and gets the token for session

	if (location.mode == "Away") {
        	log.debug "Mode is Away, Performing ArmAway"
        	//armAway(session)   
        }
    else if (location.mode == "Night") {
        	log.debug "Mode is Night, Performing ArmStay"
        	//armStay(session)
        }
    else {
        	log.debug "Mode is Home, Performing DisArm"
        	//disarm(session)
    }
return session

}


(skp19) #3

Check out the SmartApp I made for Foscam cameras. It looks like it’s basically the same idea as what you are trying but with a Foscam alarm and the mode is not hard-coded. It allows multiple mode selections and there are notifications and working times also. You can just add another input and another mode check for ArmStay for your situation.


(Yogesh Mhatre) #4

Thank you @eparkerjr. Though I’m almost complete with my app, the more examples I see, more improvisation I do.