Backup Settings and Restore in SmartApps

Ok, so I can pass params or use state to set defaultValues of inputs, so unit testing could be possible.

But backing up and restoring values will be impossible as soon as the settings input value is set.

There appears to be no way, other then user input to override the settings values.

In case someone is curious…

Here is what I threw together around dynamicPages to restore default values and how something might work in concept.

/**
 *  ps_Test_Time_Input
 *
 *  Copyright 2015 Patrick Stuart
 *
 *  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: "ps_Test_Time_Input",
    namespace: "ps",
    author: "Patrick Stuart",
    description: "Testing Backing up and Restoring",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
    page(name: "BackupRestore", title: "Backup/Restore Settings", uninstall:true, install:false)
    page(name: "Backup", title: "Backup Settings", uninstall:true, install:false)
    page(name: "Restore", title: "Restore Settings", uninstall:true, install:false)
    page(name: "Settings", title: "Settings", nextPage: "BackupRestore", uninstall:true, install:true)
    
}

def BackupRestore(params) {
    log.debug params
    dynamicPage(name:"BackupRestore") {
        section("Backup") {
            // backup settings here
            href(name: "Backup", title: "Backup Settings", page: "Backup", description: "Tap to Backup")
            log.debug settings
        }
        section("Restore") {
            //restore settings here
            href(name: "Restore", title: "Restore Settings", page: "Restore", description: "Tap to Restore")
            log.debug settings
        }
        section("Settings") {
            //restore settings here
            href(name: "Settings", title: "Settings", page: "Settings", params: params, description: "Tap to Continue", state:"incomplete")
            log.debug settings
        }
    }
}

def Backup(params) {
    log.debug params
    dynamicPage(name:"Backup") {
        //do something        
        section("Backup") {
            href(name: "Back",params: params, title: "Go Back", page: "BackupRestore", description: "Go Back", state:"incomplete")
        }
        log.debug settings
    }
}

def Restore(params) {
    log.debug params
    dynamicPage(name:"Restore") {
        //do something
        def restore
        params.inputValueNumber =1
        params.inputValueString = "testing123"
        
        section("Restore") {
            href(name: "Back",params: params, title: "Go Back", page: "BackupRestore", description: "Go Back", required: false, state:"incomplete" )
        
        }
        
      
        log.debug settings
    }
}

def Settings(params) {
    log.debug params
    settings.inputValueNumber = params.inputValueNumber.toInteger()
    settings.inputValueString = params.inputValueString
    
    dynamicPage(name:"Settings") {
        section("Settings") {
            input( name: "timeStart_1", title: "Time?", type: "time", required: false)
            
            input( name: "inputValueNumber", title: "number", type: "number", required: false, defaultValue: params.inputValueNumber.toInteger())
            
            input( name: "inputValueString", title: "string", type: "string", required: false, defaultValue: params.inputValueString)
        }
        section("Restore") {
            href(name: "Back",params: params, title: "Go Back", page: "BackupRestore", description: "Go Back", required: false, state:"incomplete" )
        
        }
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"

    initialize()
}

def updated() {
    log.debug "Updated with settings: ${settings}"

    unsubscribe()
    initialize()
}

def initialize() {
    // TODO: subscribe to attributes, devices, locations, etc.
    log.debug settings
}

// TODO: implement event handlers
2 Likes

I have three Aeon Minimotes and everytime I want to change anything I need to change it on each of three controllers (I want them all to always work the same way). So having the ability to export/load from one to the other would be great. Alternatively, some way to tell all three to look at the same settings would be even better. No clue how to accomplish this, though.

1 Like