Backup Settings and Restore in SmartApps

So, as I was developing a new SmartApp, it dawned on me there is no really good method to export and import the settings one uses during the SmartApp install.

Since the settings object only exists in the install or update phase, there isn’t a really good method yet to backup / export or import / restore settings.

Given that hub v2 is around the corner (not sure how long that corner is) and most likely the first adopters with them will have to probably reset up everything. Wouldn’t it be great to be able to backup your smartapp settings object and restore it?

So, community, lets get something together and not wait on ST to come up with a solution.

My thoughts on how this could be accomplished:

-Export to file
To my knowledge, there is no way to write to local device / mobile. So this is pretty much out of the question right now.

-Export to trusted website
This would be possible with existing resources. The question would be which site?
-Google Drive
-Dropbox
-Custom 3rd party site? Someone would have to write it.
This also has security risks associated with it. Since you would be transmitting potentially sensitive info to a 3rd party.
It could be encrypted, or at least sent via ssl.

-Export to location / hub
This also doesn’t exist today, but maybe we could convince the powers that be at ST to give us one accessible global location settings object we could write / read.
This would be the safest and easiest to hook up to.

Anyone have any other ideas? During testing of my app, it would be so much nicer to just read in a file or object and be able to do pseudo unit testing on it.

Maybe I’ll start up stbackup.com :smile:

5 Likes

Can smart-apps read states and settings from other smart-apps?

1 Like

I believe that @ben mentioned a migration assistant that could double as a backup/restore. I know with my 115+ devices and 30+ custom apps I really need that for v2 migration. I really don’t want to set it all up again.

2 Likes

[quote=“pstuart, post:1, topic:16182”]
-Export to file To my knowledge, there is no way to write to local device / mobile. So this is pretty much out of the question right now.
[/quote]App could provide an oauth web endpoint, and “export to endport” as json. Then you just hit the endpoint in a browser and save the json.

json settings file could be uploaded back to the settings app (again, via the oath enpoint POST) to “restore” the settings.

That seems to be the web2.0 way :smile:

This would need to be added to every app manually though right? Without access between smart-apps to other smartapps settings and such, this becomes really tedious, and would not work with stock apps… i think? I’ve been wrong before :slight_smile:

Yep, you’re right. We don’t have full access to everything so a community backup solution isn’t really possible. Can you even (re)name a device via an app? If so, it would be possible to back up and restore device names - not the most useful thing, but something.

ST of course can make a full backup/restore of all the metadata in your install.

2 Likes

SmartApps can store and share data through Device Instances in the same “Account”.

It is a very good way to get SmartApps to interact.

But are we limited to simple datatypes for Attributes? Are Lists / Maps allowed?

I think so. Backing up meta data would be really hard i think

Are you referring to backing up “preferences[]” (and “settings[]” and … “state[]”)?

Couldn’t we iterate through these Map with, and make a call to a Device with each Map element?

Or, just use JSON to send the whole Map as a string, since an Attribute can be a string…?

1 Like

Yeah, I know we are limited. But a community accepted standard for importing and exporting settings / inputs inside of a SmartApp would be great.

This isn’t going to replace the migration tools, or even touch backing up devices. This would be limited to the scope of an installed SmartApp and the need to reinstall it, etc.

Right now, if you remove a SmartApp, all the settings and inputs are lost, including any logged data that might have been stored in the SmartApp.

I’m trying to establish the basis for a default, copy and paste this into all smartapps kind of approach that will export the settings object and maybe state and others that might be commonly used in smartapps and provision for a way to restore that data inside another installed instance of that smartapp.

Hopefully this makes sense.

1 Like

So… I’m definitely leaning towards experimenting with a Virtual Device with a custom / adhoc string Attribute(s) to hold JSON. The user would just select this Device for each Instance of the SmartApp.

Can a SmartApp update its own “preferences[]”?

1 Like

Definitely could :smile:

I am wondering the same thing.

2 Likes

I really don’t think so.

Well… perhaps SmartApps have to “copy” their preferences Maps into state[] and then use the state for actual work? Then they could save and reload state[] (to and from a shared Device Instance or external website).

Messy … but a Proof-Of-Concept for backup/restore?

1 Like

Honestly guys, for something that is going to be done infrequently, it’s just not worth the effort. It just introduces another point of failure.

2 Likes

Yea I feel like I mess with my stuff enough where a feature like this would be immensely useful. Just today in an effort to troubleshoot why some switches were turning off I had a leave myself a trail of screenshots for how things were installed before I removed one switch and one smartapp…

Has to be a better way.

2 Likes

So, I’ll play around with some proofs of concept later tonight. But, yes a SmartApp at install or update can update its preferences, it has to. Outside of the install or update (UI screens) you can’t.

Even if it is a method that just populates the “default” values for all inputs and all you have to do is next your way through the setup screens, it still would be a huge time saver for those testing and working apps.

So, basic workflow, dynamic page at beginning.

Do normal install or load settings from URL / endpoint

Load settings just brings in the object, and is coded into the install pages as default values, or better yet, just loops through the settings map and sets them before install.

Just walk though the set up screens with all the values set (just like an update) and install the app.

On update, first screen allow you to export to URL / endpoint the settings map.

Seems simple to me, could be pasted into even the most simple non-dynamic page smartapps, since the last page would just be the default section.

I’m getting excited, time to find the limitations.

2 Likes

Hmmm, the settings and state variables seem to be read only and inaccessible outside of a page refresh.

About the only way to do it is to call each page and pass in the restored object as a param.

This is going to be a bit more difficult, but I don’t think it will be impossible.

2 Likes

You can get a complete list of your installed smartApps and the settings as JSON from here when logged in. https://graph.api.smartthings.com/api/smartapps/installations/

Not sure about getting state variables though.

1 Like

Damn, settings and default values are locked to only user input. So frustrating.

Why, ST, Why?

So who do I have to buy drinks to get the settings to be writable?

1 Like