Displaying unit in a valueTile?


(codersaur) #1

For device attributes with dynamic units, how can I display the unit in a value tile???

It seems it used to be possible to use ${unit} in the label definition, e.g.:

    valueTile("attribute", "attribute", decoration: "flat", width: 2, height: 1) {
        state "default", label:'${currentValue} ${unit}'

… however this no longer seems to work. (instead I just get -- on an iPhone) :frowning:

Anyone any ideas?

I’d rather not have to hard-code the unit, or build a companion display string attribute for every attribute.

(Stephan H.) #2

I’ve never had to do this so it’s a complete guess here but wouldn’t the syntax be:

label: ‘${currentValue}’, unit: ‘${unit}’

(codersaur) #3

Thanks, but the unit attribute is just ignored in this case.

Interestingly, you can reference the unit attribute from the label though:

state "default", label: '${currentValue} ${unit}', unit:'xyz' 

… but it still only seems possible to define the unit as a static string.

Doing this…

state "default", label: '${currentValue} ${unit}', unit:'${unit}' 

results in:

  • iPhone:
  • Android:

which only serves to highlight the inconsistancies in number formatting between iPhone and Android apps! :imp:

For the record, using currentUnit doesn’t work either:

state "default", label: '${currentValue} ${currentUnit}'


I was trying to use the unit prop for temperature degree fromatting between degrees C and degrees F but never got unit changing to work from within the state declaration or event calls.

I’ve tried the same approach as @zcapr17 did. Chainging the unit prop doesn’t ever seem to be displayed or registered by SmartThings.

Eventually i gave up and just used the degree symbol.

(JJG) #5

I also tried to do this (for a handler supposed to support both °F and °C) but I was unable to do it either since “unit:” accepts only static strings.
One year after going international, it looks like SmartThings has still work to do to ACTUALLY support internationalization… :rage: