Anyway to pass a Variable or Preferences value to a Tile for display?

This works :

{
valueTile(“temperature”, “device.temperature”, inactiveLabel: false) {
state “temperature”, label:’${currentValue}’, unit:“°C”}
}

but anything else I tried does not.
I am not even able to display in the Tile the “unit:” attribute of the “temperature” command; only a litteral string (as “°C”) is displayed correctly :-(.
I would like to do something like :

{
valueTile(“temperature”, “device.temperature”, inactiveLabel: false) {
state “temperature”, label:’${label_string}°C’, unit:’${unit_string}’}
}

with label_string and unit_string a device attribute set in the Handler or in Preferences.
Any suggestion ?

I haven’t tried actually using preferences in the way you are trying. To access preferences in the Device Type, you need to use syntax like this:

settings.preferenceName

No idea if it will work in the tile section.

If it is temperature, that you are looking at specifically. I added code similar to this below to a device type recently based on the other temperature related Device Types available in the IDE. I was told it worked for Celsius and looked good to me for Fahrenheit. It doesn’t show the temp scale though.

valueTile("temperature", "device.temperature") {
    state("temperature", label:'${currentValue}°', backgroundColors:[ ... ] )
    }

function() {
    // ...
    def tempValue = getTemperature(value)
    sendEvent(name: name, value: tempValue, unit: getTemperatureScale())                                     									 
}

def getTemperature(value) {
    def celsius = value
    if(getTemperatureScale() == "C"){
        return celsius
     } else {
        return celsiusToFahrenheit(celsius) as Integer
     }
}

Thanks for the suggestion.
I tried “settings.preferenceName” in the Tile section, but although it works fine in the Commands section (as well as “preferenceName” alone) it returns only “null” in the Tile section.
As explained in my original post, I have no problem displaying the Temperature value using “label:’${currentValue}°’”, my problem is that I cannot display ANY other dynamic value passed into the Tile command, either with “unit:xxx” or anything else.
The reason I am doing all that is that I have multiple temperature sensors in multiple rooms, and would like to display the room name on the iPhone/iPad Dashboard, in addition to the temperature.currentValue.
But although the room name is properly displayed on top of the Tile in the IDE, it is completely missing on the Dashboard.

Good evening JJG,
I know this is old, but were you ever able to solve this?
I want to do something similar: I have a device handler that I called temperature that displays the temperature on the dashboard but multiple values (wind sped, wind direction, probability of rain, etc…) in the secondary tile. On the dashboard, I would like to have the temperature + Wind speed.
Curently I have “Temperature 9°C” I would like to have “Temperature 9°C + 22 ssw” (The 22 ssw means 22 kph South-South-West)
Thx

Hi JP, no I was never able to solve that.
Actually, it is even worse than explained in the original post of this thread : I did not find either any way to have the same Handler code switching the colors thresholds depending on °F / °C selection : to do that, you would have to be able to replace $xxx below by a dynamic variable, but AFAIK only constants are accepted there.

tiles {
valueTile(…) {
backgroundColors:[ [value: $xxx, color: “#0033ff”], …

However I have not been looking for a solution since I first encountered this problem 3 years ago, and it is possible some workaround now exists which did not then.
But if you cannot get any answer from the SmartThings developers Forum, you won’t get any help from SmartThings support which will throw away your ticket as soon as they read “custom Handler”.

Sorry of not being more help :frowning: