Dynamic configuration of a SmartApp

Hi,

I’m working on a SmartApp as a virtual thermostat. I’d like to centralize more of the config in one app instead of having several apps for each room and modes (like the default Virtual Thermostat). I have it working through some rudimentary inputs, dynamicPage and submitOnChange. But I see a lot of potential for better config.

So my question is really: How is the best way to create a dynamic setup page? Where you can add and remove sections as needed? I think something along the lines of how the Smart Lighting app does it would work, though not ideal. Anyone know where I can find the code of the Smart Lighting app? Or something similar?

I suspect that the way Smart Lighting is made possible is through sub-apps? Does anyone know?

Thanks,
Anders,

You may want to consider using a parent- "child SmartApp design. You can learn about it here, and towards the bottom there is a simplified example similar to Smart Lighting: http://docs.smartthings.com/en/latest/smartapp-developers-guide/parent-child-smartapps.html

Thanks, I’ll look into that.

Even though I will put each room into a separate sub-app, I’ll also need a dynamic section to add X number of sections specifying temperatures for different modes. I know how to do this via a DynamicPage and input with number, but feels a bit clunky.

Is there some kind of plus/minus buttons available to add/remove sections? I know I could probably do this with another level of sub-apps (which is not recommended), but I would prefer to keep it on one page.

Is there some way to access the defined rooms via the API? That’s really what I would like to have in a list. :slight_smile:

Anders,

Unfortunately no, Rooms are not available via the SmartApp API.

You can create your room section() in a for loop based on an array that contains the list of your rooms (or use app.getChildApps() to get an array of the child apps), then add another section() outside the loop as a placeholder for “new”…

def list = []
for (item in list) {
   section( ){
      ...
   }
}
section() {
   ...new item...
}
2 Likes

That’s awesome, I think that will work.

But I can’t seem to find a way to reset the field that triggers a new item? I use submitOnChange to trigger a new render for item in the list, but the values in the “new item” input fields does not go away. I’ve tried to set settings[“newItemInputName”] = null . The specific input is modes if that’s relevant.

Any idea how I can do this?

Thanks,
Anders,

You can’t push a change to a user input field… it would make app development much easier if you could!

Equally if you remove data from a field, the fields will still be stored against the app… you can’t force removal of data from redundant fields…

Your other option is just to increment the field name, but this could leave a lot of redundant data in the background, so best to just get the user to change the data in the cell to be honest!

1 Like