I’m building an app that creates an unlimited number of dynamic input pages, and sub pages from single page templates.
this took more than 10 minutes to work out LOL…
/**
* superState 1.0
*
* Copyright 2015 Mike Maxwell
*
* Device (switch/dimmer/color) state capture and replay utility.
* - resulting scene is assigned to a child device
* - scene devices are editable post capture (recapture/add/delete)
* - option to restore each devices previous state individually (as captured when scene is turned on) when the scene is turned off
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "superState",
namespace: "mmaxwell",
author: "Mike Maxwell",
description: "Device state capture, replay and edit tool",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic@3x.png"
)
preferences {
page(name: "main")
page(name: "group",nextPage : "main")
page(name: "scene",nextPage : "main")
page(name: "delete",nextPage: "main")
}
def main(){
def nextGroupIDX = getNextGroupIDX()
def nextGroupID = "g${nextGroupIDX}"
dynamicPage(name: "main", title: "superState", uninstall: true,install: true) {
section("Device groups"){
def prefGroups = getGroupMaps()
prefGroups.each(){ prefGroup ->
href(
name : prefGroup.key
,title : prefGroup.value
,required : false
,params : [groupID:prefGroup.key]
,page : "group"
,description: null
,state : isGroupComplete(prefGroup.key)
)
}
}
section(){
//always have a link for adding a new group
href(
name : nextGroupID
,title : "Add a device group..."
,required : false
,params : [groupID:nextGroupID]
,page : "group"
,description: null
)
}
}
}
def group(params){
def groupID = params.groupID
def switchID = groupID + "dswitches"
def lockID = groupID + "dlocks"
def relayID = groupID + "drelays"
def valveID = groupID + "dvalves"
def doorID = groupID + "ddoors"
def nextSceneIDX = getNextSceneIDX(groupID)
def nextSceneID = "${groupID}s${nextSceneIDX}"
dynamicPage(name: "group", title: getGroupPageTitle(groupID), uninstall: false,install: false) {
section() {
input(
name : groupID
,title : "Group Name"
,multiple : false
,required : true
,type : "text"
)
}
section("Scenes"){
def prefScenes = getSceneMaps(groupID)
prefScenes.each(){ prefScene ->
href(
name : prefScene.key
,title : prefScene.value
,required : false
,params : [sceneID:prefScene.key]
,page : "scene"
,state : "complete"
,description: null
)
}
}
//need to skip this section if groupID.value is null
//some bug here if we create a scene before the group is saved
//log.debug "settings on group page:${settings}"
if (settings[groupID]){
section(){
//always have a link for adding a new scene
href(
name : nextSceneID
,title : "Add a Scene..."
,required : false
,params : [sceneID:nextSceneID]
,page : "scene"
,description: null
)
}
}
section("Devices"){
input(
name : switchID
,title : "Switches"
,multiple : true
,required : false
,type : "capability.switch"
)
}
}
}
def scene(params){
def sceneID = params.sceneID
dynamicPage(name: "scene", title: getSceneTitle(sceneID), install: false) {
section() {
input(
name : sceneID
,type : "text"
,title : "Name for this Scene..."
,required : true
)
}
}
}