How can I store the list of preferences?


Hi all,

I am new to SmartThings and I’m tryng to create an application, which controls thermostats and lights in several zones of my house.
The number of zones can be changed at any time with an option to configure the new zone or delete an existing one. Actually the layout for this configuration should be very similar to Phrases (actions) configuration.
I created the layout, but ran into another issue: how to store configuration for each zone.

  1. Can I use HashMap (or any other storage entity: List, Array, etc.) to store it?
  2. If yes, how to define it as a global variable?

Thank you,

(Gary D) #2

take a look at “state” and “settings” from here:

Map settings
A Map of name/value pairs containing all of the SmartApp’s preferences. .

Map state
A Map of name/value pairs that the SmartApp can use to save and retrieve data. .


Thank you for the quick response!

Yes, it’s exactly what I do. I just don’t like the idea of settings names like “zone_1_thermostat”, “zone_2_thermostat”. It’s really hard to manage them.

I am wondering if I can store all zones in (for example) a List and add a zone to this list when user adds it on UI?

(Gary D) #4

There are some notes somewhere on the forum I remember reading related to state or settings (or both?) only being able to store certain variable types.

Here’s what I’d do: try it. Abuse “log.debug” to test things. Add a switch handler to a real or virtual switch that uses lots of log.debug’s to inspect the variables.

(Mike Maxwell) #5

You can create arbitrary global objects in smart apps, the scope of which is limited to the smart app that created it.
state.myWhatEverHere = whatever…

myWhateverHere could be anything, however it’s json encoded on the back end, avoid date strings since these get munged.