I have a ‘time’ type setting and I would like to set a default value of 1pm (13:00). I’ve tried various things and haven’t figured this out. Thank you.
Here is a code snippet to show what I’m trying to modify. I think what I meant to say is how to I define a “time” type constant?
input(name: 'theTimeToDoThings', type: 'time', title: 'Time when all the magic happens', required: true, refreshAfterSelection: true)
I didn’t try that before, but my understanding on how ST localize things is… they don’t localize anything. For instance, you want to use a unit (C vs F degrees), well you have to manage it by yourself in your code.
I believe it will be the same for the time.
I found this code in routine-director.groovy on the ST public master which could help you.
This will work if you want to hardcode the value. It has to follow the full date time format from JSScript something (sorry I read that yesterday but I cannot find the reference again in the ST documentation. Should be somewhere in a chapter dealing with Time).
input(name: 'theTimeToDoThings', type: 'time', title: 'Time when all the magic happens', required: true, refreshAfterSelection: true, defaultValue: "2017-11-05T13:00:00.000-0800")
But remember this is the defaultValue so it is used only the first time you enter your device settings before you set another value.
BTW, I believe that you cannot pass a defaultvalue through a variable, just like the rest of a DTH sections used for the GUI, these are parsed and not interpreted so your setting value is either a string that the parser reads and set if no value is stored in the ‘theTimeToDoThing’. Another way would be to send an event to “theTimeToDoThing” with a value following the string format I put above and do that from the Installed function so that it happens only once in the DTH life.
That does work, however it is time zone specific. If this is just for me than that’s fine, I’ll just set it to my local time zone (-6 or -7) but I was hoping to not do that.
I am using this in my fork of lock-manager I wrote that has a new user type that automates setting entry codes to the last 4 digits of a guest’s phone number. This should be in the smartthings documentation as being able to use a variable for a defaultValue makes life much easier.