So, I created a valueTile() like this. . .
tiles {
valueTile("power", "device.power", decoration: "flat") {
state "power", label:"${currentValue} W"
}
}
Notice that all strings are double quoted, this is significant. Here is a page that discusses the Groovy programming language syntax with a lot to say about strings.
http://www.groovy-lang.org/syntax.html#all-strings
And here is a digest of section 4 on that page.
Groovy lets you instantiate two kinds of strings: java.lang.String objects and groovy.lang.GString objects (a.k.a. “interpolated strings”).
Single quoted and triple quoted strings don’t support interpolation (I infer from this statement that single quoted and triple quoted strings can only be java.lang.String objects). Only double quoted strings can be groovy.lang.GString objects.
If there’s no interpolated expression then a double quoted string is a plain java.lang.String object. But, if interpolation is present then it is a groovy.lang.GString object.
Any Groovy expression can be interpolated in double quoted string literals. Interpolation is the act of replacing a placeholder in the string with its value upon evaluation of the string. Placeholders are expressions surrounded by ${} or prefixed with $ (for dotted expressions).
Based on the material above, using double quotes in label string (as shown in my example above) must be the correct syntax. But it’s not. Using double quotes here will cause the valueTile() to display “NULL.”
Here’s a working example given at
http://docs.smartthings.com/en/latest/ref-docs/device-handler-ref.html#valuetile
tiles {
valueTile("power", "device.power", decoration: "flat") {
state "power", label:'${currentValue} W'
}
}
Notice that double quotes are used everywhere except in the label string, which contains a placeholder for the current value, which is what we want to interpolate and display.
So what gives? Why do I have to use this “incorrect” syntax to make my tile work? What am I missing?