Bug using variables in input method for devices and smartapps


(www.rboyapps.com - Make your home your butler!) #1

I’m trying to use a dynamic variable for the name of a input device in a SmartApp. It doesn’t seem to work. It won’t remember it when you load it the next time, the variable value is stored in settings but the input parameter seems to ignore the stored value.

So this works:

input name: “homePhrase${i}”, type: “enum”, title: “Run Routine”, required: false, options: phrases, defaultValue: settings.“homePhrase${i}”

and this works:

input name: “turnOnSwitches”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

BUT this doesn’t work:

input name: “turnOnSwitches${i}”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

AND this doesn’t work:

input name: “turnOnSwitches${i}”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true, defaultValue: settings.“turnOnSwitches${i}”

Anyone know why and what I’m doing wrong?

Tagging some gurus’ @tgauchat @garyd9 @625alex @tslagle13


(www.rboyapps.com - Make your home your butler!) #2

Holy cow, I don’t believe what’s going on.

Entering the tags “name” and “type” are causing the issue!!
This works

input “turnOnSwitches${i}”, “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

This doesn’t!

input name: “turnOnSwitches${i}”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

and i’ve tried every possible combination, keeping only name, only type, removing space etc. Nothing! Only I remove them both it works.

@Jim and @tslagle13 tagging you guys for your inputs please. Jim has the documentation changed? BTW I don’t see defaultValue as an option in the documentation anymore.
If it’s not documentation then Tim is this a IDE or a platform bug? (the result is replicable on iOS and Android so I’m guessing it’s a platform issue)


(www.rboyapps.com - Make your home your butler!) #3

Anyone comments please? @Jim @tslagle13


(www.rboyapps.com - Make your home your butler!) #4

Still awaiting any comment from anyone on the ST staff, am I doing something wrong here or is there a bug or what’s going on guys?


(Mike Maxwell) #5

Use the following form:

	def myVal = "cpVal_" + n
OR
	def myVal = "cpVal_${n}" 

	result = input(
				name		: myVal
				,title		: "string value"
				,type		: "text"
				,required	: false
			)

where n is some ordinal that you maintain
The return result bit is optional, but useful for including the input field into a method.
Input (…, will stand on it’s own within a standard or dynamic page.


(www.rboyapps.com - Make your home your butler!) #6

It does not work with

type: “capability.switch”

I know with non capability types everything is okay but when the type is capability and you introduce a variable in the name, specifying the tags for name and type causes it to break.

Still waiting for someone from ST to comment on it. @Ben should I be reporting this to support or bring it to someone else’s attention?


(Mike Maxwell) #7

you specifically tried this without using the inline gString representation?
gStrings are evaluated late, and I have for a fact seen the code sample in your initial post fail…


(www.rboyapps.com - Make your home your butler!) #8

Yes and it doesn’t work.

BTW the inline representation works just fine as long as the type isn’t capability, i.e with type text my original code works fine.


(www.rboyapps.com - Make your home your butler!) #9

you’re missing the whole point, without the tags it works, with the tags (name/type) it doesn’t - and this is specific to type capability, so what’s going on?


(Jim Anderson) #10

We will look into this more next week. Until then I would suggest using the method that works (not using the named parameters).


(www.rboyapps.com - Make your home your butler!) #11

Thank you @Jim, I just realized it’s thanksgiving eve, wish you and everyone a happy thanksgiving.


(Jim Anderson) #12

@RBoy are you still seeing this? I tested using the name/type named parameters and is working for me.


(www.rboyapps.com - Make your home your butler!) #13

No @Jim it still doesn’t work. If I put a variable in the name and type is capability.switch, the moment I specify the tags name and type it stops working.


(Jim Anderson) #14

Ah so it’s when trying to build the values dynamically, not just that using the named values is causing an issue. Thanks for the clarification.


(www.rboyapps.com - Make your home your butler!) #15

@Jim one more point, can you clarify if defaultValue is an official tag? I can’t see it on the documentation but it works in most places.


(www.rboyapps.com - Make your home your butler!) #16

@Jim any update on the this and also clarification on the defaultValue? Merry christmas and seasons greeting to the whole ST team.


(Jim Anderson) #17

HI @RBoy, hope you are having a good holiday season as well!

Yes defaultValue is supported. Regarding the input variables, can you perhaps create a gist of a simple SmartApp that illustrates the issue? And if you are reproducing on Android and/or iOS.

I created a simple example here, but it is working for me on ios and Android, so a simple example that reproduces the issue will allow us to create an internal ticket for the issue.

Thanks!


(www.rboyapps.com - Make your home your butler!) #18

@Jim going back to my earlier post, the dynamic variables don’t work when using with a type “capability.switch”. In your example you’re using type “text”.
Same for defaultValue with using with type “capability.switch” it doesn’t work.

this works:

input name: “turnOnSwitches”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

BUT this doesn’t work:

input name: “turnOnSwitches${i}”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true

AND this doesn’t work:

input name: “turnOnSwitches${i}”, type: “capability.switch”, title: “Turn on switch(s)”, required: false, multiple: true, defaultValue: settings."turnOnSwitches${i}"


(Jim Anderson) #19

@RBoy,

Ok… I think there may be a couple issues here. Help me unpack them:

  1. Setting default values of a device input isn’t working as you’d expect.
  2. When using name and type explicitly to input() the preference values are not saving. I see them working within the preferences page, but then when hitting Install, if I open it back up the values are gone.

Am I getting warmer? :smile:

Is the gist now illustrative/correct?

Regarding 1), you can use the device id to set the default value (see the gist for an example).
Regarding 2), no clue. We can pass it on to engineering. Are you seeing this in general or just in specific cases? i.e, are you always seeing that any device input that uses the name/type form doesn’t save the selected values, or just in this case?

Thanks!


(www.rboyapps.com - Make your home your butler!) #20

Perfect Jim, you’re there. Your sample code is spot on.

I was suggesting if you could document the correct usage of defaultValue and what types of inputs it applies to and if there is any difference in the way it should be used.