How to get enum array of modes?



In my smart app, I want the user to select modes to run in - similar to the mode input - but then I want to set options per mode they chose. I saw a similar thread - but it is not acting as expected. For some reason, the first mode gets selected, but the other modes are just indexed:

	ST modes: [Home, 1, 2]

Get Enum Of Modes

def avaliableModes = []
location.modes.each {avaliableModes << "$it"}
    name: "linkedStModes",
    type: "enum",
    required: true,
    title: "Smartthings Modes:",
    multiple: true,
    submitOnChange: true,
    options: avaliableModes

Allow the User to link preferences to each mode

dynamicPage(name: "preferencesPage") {
    section("Preferences") {
        log.debug("ST modes: ${settings?.linkedStModes}")
        settings?.linkedStModes.each { stMode ->
                name: "onSTMode_${stMode}",
                type: "enum",
                required: true,
                title: "When ST mode ${stMode}, set:",
                options: myOtherOptions,
                multiple: false

What am I doing wrong here?

(Tim Slagle) #2

Use type: mode and we will do the heavy lifting for you :slight_smile:


Thanks for the reply @slagle. Unfortunately, when using type: mode - multiple select no longer works:

Log result: ST modes: [Away]

                name: "linkedStModes",
                type: "mode",
                required: true,
                title: "Smartthings Modes:",
                multiple: true

(Eric) #4

Change the name of your variable and see if it works. I’m just curious. I was seeing something like this a few weeks ago.

Also, what method is you log statement? Updated?


Thanks for the suggestion @whoismoses, I tried it out but I’m not seeing any behavior differences. I tried different variable names for both my method, and the method suggested by @slagle

(Tim Slagle) #6

This works for me right now:

        name:       	"newMode",
        type:       	"mode",
        title:      	"Modes",
        multiple:   	true,
        required:   	true

(Eric) #7

Maybe it is a bug with the simulator. Have you tried deploying the app to your device?


Yes, selecting multiple mode appears to work. But later in the settings - on a dynamic page - there is only one value in the linkedStModes variable. So, while it gives the impression of working, only one mode is actually selected.


From your suggestion, I installed a test app on my phone, and the issue where modes show up as ['Home', 1, 2] is a simulator-only bug. I’ve got mode selection working as expected now - just not in the simulator.