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?
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.
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...
}
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.
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!