Selecting and Executing Actions within a SmartApp


(Greg) #1

Does anyone know, is it possible to have the user select an action from a list of configured actions, and then later execute it? Kind of like Modes…

input “modeChange”, “mode”, title: “Set my mode to…”

setLocationMode(modeChange)*

I’m brand new to this stuff and having difficulty navigating the API.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

Yes…

You can present the list of defined “Hello Home” phrases and execute any of them as well.

I’ll update with an example (and/or private message me to remind / inquire).

… CP.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #3

@gthomson: As promised… here’s some sample code: All questions/comments welcome.

Code is Apache licensed, borrowed from myself and SmartThings: (https://github.com/CosmicPuppy/SmartThings-ButtonsAsPIN/blob/master/ButtonsAsPIN.app.groovy)

            def phrases = location.helloHome?.getPhrases()*.label
            if (phrases) {
                myDebug("Phrase list found: ${phrases}")
                /* NB: Customary to not allow multiple phrases. Complications due to sequencing, etc. */
                input "phrase", "enum", title: "Trigger Hello Home Action", required: false, options: phrases
            }
private def findPreferenceSetting(preferenceName) {
    def pref = settings[preferenceName]
    if(pref != null) {
        myDebug("Found Pref Setting: $pref for $preferenceName")
    }
    return pref
}
    def phrase = findPreferenceSetting('phrase')
    if (phrase != null)	{
        myTrace("helloHome.execute: \"${phrase}\"")
        location.helloHome.execute(phrase)
    }

…CP / Terry.