Multiple Mode Selection Issue!


(Ash (www.smart-dots.com) / Ashutosh Jaiswal) #1

Hi All!

I have written this smart app for my doorbell, which triggers different push notifications if my door bell is rung, based on whether I am in Home Mode or Away Mode. When selecting “Away Mode” I have set the selection to multiple, so that I can have the “Away” mode push sent in “Away” mode and “Vacation” mode. However, I the app fails to execute the “Away” mode when I provide multile inputs for mode - The moment I change the code to provide just one input, it works fine. Below is the code… How do I change it for it to check for multiple modes (in my case “Away” and “Vacation”), and trigger events accordingly.

preferences {
section(“When door bell is rung…”) {
input “contact1”, “capability.contactSensor”, title: “Where?”
}
section(“Send this push notification (when at home)”){
input “message2”, “text”, title: “Message Text”, required: true, description:“Tap Here to Enter”
}
section(“And if everyone is away - Choose Mode for Away…”) {
input “AwayMode”,“mode”, title: “Away Mode”, multiple: true
}
section(“Then turn these lights ON…”) {
input “switches”, “capability.switch”,title: “Choose Lights…”, multiple: true
}
section(“Keep Lights on for these many minutes”){
input “onTime”, “number”, title: “Minutes?”,description:“Tap Here to Enter”
}
section(“When no one at home, send this push notification”){
input “message1”, “text”, title: “Message Text”, required: true,multiple: true, description:“Tap Here to Enter”
}
}

def installed()
{
subscribe(contact1, “contact.open”, contactOpenHandler)

}

def updated()
{
unsubscribe()
subscribe(contact1, “contact.open”, contactOpenHandler)

}

def contactOpenHandler(evt) {
log.trace "$evt.value: $evt, $settings"
log.debug “$contact1 was opened, texting $phone1”

if(location.mode == AwayMode) {
log.debug "Mode is Away"
def msg1 = message1
sendPush msg1
log.debug "Away mode Push Sent.."
turnon()
}
else {
def msg2 = message2
sendPush msg2
log.debug "In Home Push sent.."
}

}

def turnon() {
log.debug "Lights have been turned ON"
switches?.on()
runIn(onTime*60, “turnoff”)
}

def turnoff() {
log.debug "Lights turned off"
switches?.off()
}


(Bruce) #2

if(location.mode in AwayMode) …

AwayMode is an array, since it is multiple:true (might make sense to call it AwayModes), so we just want to see if location.mode is one of the elements.


(Ash (www.smart-dots.com) / Ashutosh Jaiswal) #3

“AwayMode” is just a variable, and yes it will make sense to call is “Awaymodes”, But by changing the variable name, how will it affect the behavior of the code?


(Bruce) #4

Has nothing to do with the variable name. It has to do with how you selected it. When you use multiple:true you are selecting more than one item, and those items end up in an array variable, not a simple scalar variable.

So, if you had said multiple:false, only a single mode would be selected, and it would be tested with “==”. But with multiple:true, you get an array, and the test is “in” instead of “==”.


(Ash (www.smart-dots.com) / Ashutosh Jaiswal) #5

OK got it…Let me try that…


(Ash (www.smart-dots.com) / Ashutosh Jaiswal) #6

@bravenel Thanks a lot…I did nt realize that it would be an array. It works great now. Thanks for your help!