Smart app with "More Options"

Without any of my doing, almost all apps I have written automatically insert the Preferences options “Assign a name” and “Set for specific mode(s)” once installed via mobile. Today, I wrote one hwever, and these options are not there. The only difference is that the app Preference section includes a dynamic page. The code is

preferences {
	page(name: "selectPhrases")

def selectPhrases() {
    dynamicPage(name: "selectPhrases", title: "Routines",  install: true, uninstall: true) {		
	 section("Virtual Switch Controlled by IFTTT"){
		input "vtSwitch",  "device.onOffButtonTile", title: "Choose a Virtual Switch"
        def actions = location.helloHome?.getPhrases()*.label
		if (actions) {
		section("Select Associated Routines When") {
			input "switchedOn", "enum", title: "Run this Routine when Virtual Switch turns on", required: true, options: actions, refreshAfterSelection:true
			input "switchedOff", "enum", title: "Run this Routine when Virtual Switch turns off", required: true, options: actions, refreshAfterSelection:true


Why are the above described options not included and what do I need to do to fix this??

Only single page apps get the automatic inclusion of naming the app and the mode restriction (handled by the platform, not by the app). Once you have a multi-page app, any app with a dynamic page, the app itself must provide these features, and place them in the UI where desired. Also, the app will have to handle its own restrictions in code.

There are several examples of this code floating around. The restrictions can get more complicated when you go beyond just mode to include time of day and days of week.

1 Like

Thanks for the quick reply… I really have no need for a dynamic (or multiple) page but according to the documentation, to display phases, I have to use a dynamic page. The code I pasted above is (almost) directly out of the ST documentation.

I found something similar you posted that looks like…
section(“Run this phrase…”) {
input “switchedOn”, “enum”, title: “Which phrase?”, required: true, options: phrases

However when I run /select it I get a screen with “No devices to connect” message… :frowning:

This is correct, that to get the phrases from the platform, you have to have a dynamic page. Once you have a dynamic page, then you are on your own for naming the app, etc.

Interestingly, Button Controller, ST’s app for Minimotes, supports running a phrase (now Routine). So, it doesn’t have the automatic naming and mode restriction. Every instance is called Button Controller, which is hugely confusing. I implemented Button Controller+ off that code, and included both naming it and the restrictions. You can see that code here, on Github, for examples of how to do this:

To retrieve the “phrases”

def phrases = location.helloHome?.getPhrases()*.label

1 Like

Well with all the examples posted here that wasnt all that painful… :slightly_smiling:
To the above code within the selectPhases() function, I added…

	        section() {
	        	label title: "Assign a name:", required: false
				input "modes", "mode", title: "Only when mode is", multiple: true, required: false

Then, in the main body

private getModeOk() {
	def result = !modes || modes.contains(location.mode)
	log.debug "modeOk = $result"

To ensure my functions only execute when the appropriate mode(s) are set:

if (getModeOk()==true) {
	sendNotificationEvent("Performing \"${switchedOn}\" because ${} turned on.")
1 Like