Potential bug in subscribing to routineExecuted from static SmartApp

@Jim marking you on this as I don’t know if this is a documentation bug and intended behavior or a bug with the platform (in which case I’ll tag @jody.albritton and @tslagle13)

According to the documentation SmartApps can subscribe to Routine Executed events using the following command:

subscribe(location, “routineExecuted”, routineChanged)

This ONLY works for SmartApps which have dynamic preference pages. If you use this in a SmartApp that has static preference pages the routineChanged is never called.

This is something akin to subscribing to mode change, it doesn’t work for static preferences only for dynamic preferences.

Is this is intended behavior?

No,that doesn’t make sense. That didn’t used to be the case, and if it is now, that’s not right.

Try it out @Jim, I just spent an hour debugging this scratching my head on why it worked in one app and not another, the only difference being on was a static preference page and the other dynamic. I changed the static preference page to a dynamic preference page (that’s it no other change) and bingo it starts working…

1 Like

I believe you, just saying it makes no sense for it to behave that way. :smile:

If you have a simple example SmartApp that shows the problem it will help track it down. A gist would be great. Thanks!

1 Like

Okay this is more complex than I thought but I’ll try to explain it (can’t understand it no matter how I skin it but I’ll explain how to reproduce it). The sample app code is given below. Install it and open Live Debugging.

Now with NO modes selected you hit any routine and the event is received by the Smart App - all great so far.
Now select one or more modes, infact select them ALL. So essentially selecting ALL modes should be the same as selecting NO modes - right? Apparently I’m wrong, if I select any mode including all modes and the current mode, the app won’t get the routine event notification. Go figure. Any theories?

definition(
    name: "Routine Event BugTest",
    namespace: "rboy",
    author: "RBoy",
    description: "Routine events are receveied in apps with static pages",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Allstate/lock_it_when_i_leave.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Allstate/lock_it_when_i_leave@2x.png"
)


preferences {
    section("Select Lock") {
        input "lock1","number", title: "Lock"
    }
}

def installed()
{
    log.trace "$settings"
    appTouch()
}

def updated()
{
    log.trace "$settings"
    appTouch()
}

def changeHandler(evt) {
    log.debug "Event called $evt.name $evt.value"
}

def appTouch() {
    unsubscribe()
    subscribe(location, "routineExecuted", changeHandler)
}

Sorry prematurely closed the message. So now if I convert this app into a dynamic preferences app it work fine with one or mode selected!
I suspect the bug is something to do with the codes, since static preferences apps handle modes differently than dynamic page apps

How are you defining the mode input for your dynamic pages? If you’re using the mode() method, that will behave as it does with single page static preferences (the SmartApp will only execute if the current mode is one of the selected modes). If you’re using an input with type "mode", that does not act as a filter in that way.

That aside, yes there appears to be an issue where "routineExecuted" events are not getting to the SmartApp if one or more (or all) modes are selected.

I tweaked your example to show more of what I mean, included added a simple switch with a subscription to see that the switch event is handled by the SmartApp (as long as the current mode is one of the selected modes):

definition(
    name: "Routine Event BugTest",
    namespace: "rboy",
    author: "RBoy",
    description: "Routine events are receveied in apps with static pages",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Allstate/lock_it_when_i_leave.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Allstate/lock_it_when_i_leave@2x.png"
)


preferences {
	// use dynamic page:
	page(name:"testPage", title:"Test Page", uninstall:true, install: true)
    
    // static preferences pages do not get routineExecuted if any modes selected
    // in the modes filter input
    //section("Select Lock") {
    //    input "lock1","number", title: "Lock"
    //}
}

def testPage() {
	return dynamicPage(name: "testPage") {
        section("Select Lock") {
           input "theswitch", "capability.switch"
           // using mode() means that this smartapp will ONLY execute if the mode is in one of the modes specified
           mode(title: "set for specific mode(s)")
           
           // input of type mode does no execution restriction - developer must control that
           //input "modes", "mode", title: "only when mode is", multiple: true, required: false
	    }
    }
}
def installed() {
    log.trace "$settings"
    init()
}

def updated() {
    log.trace "$settings"
    init()
}

def init() {
    subscribe(location, "routineExecuted", changeHandler)
    subscribe(theswitch, "switch", changeHandler)
}

// When modes are selected that control whether this SmartApp is 
// executed or not, routineExecuted events are not sent to this SmartApp,
// even if the current mode is one of the selected modes.
// Switch events are still received (provided the current mode is
// one of the selected modes)
def changeHandler(evt) {
    log.debug "Event called $evt.name $evt.value"
}


1 Like

Talking about Static vs Dynamic pages, here’s another bug, when using a static page, hidden attribute always evaluates to true on iOS (dynamic works fine). For Android Hidden and Hideable don’t work at all.

preferences {
	section("Open Garage Doors When People Arrive", hidden: (doorsOpen ? false : true), hideable: true) {
		input "doorsOpen", "capability.doorControl", title: "Which garage door(s)?", required: false, multiple: true
		input "arrives", "capability.presenceSensor", title: "When who arrives", description: "Which people leave?", multiple: true, required: false
	}
}

looping in dev advocates @tslagle13 and @jody.albritton - another issue to track please.

2 Likes