Possible to change displayed temperature units from °C to °F on the fly from within a device handler?

Hello gentlemen,
i’m trying to implement an automatic fahrenheit/celsius conversion in my device handler that would use the user set field ${location.temperatureScale} to determine the selected temperature scale and change the tile’s unit label to the selected one?

I managed to do the conversion of data without any problems, but when it comes to changing how the unit label looks i’ve had no luck. All the device handler examples i could find that convert the temperature value don’t actually display °C or °F but instead just use the label to display the degree sign:

label:'${currentValue} °'

In my device handler event i return the map object as usual, the data in the received command does get displayed, but no luck with the temperature unit change:

map.value = command.scaledSensorValue.toString()
map.unit = "°"+location.temperatureScale

Does anyone have any tips regarding this or got something similar to work?

1 Like

If it is just for display Tile, you can add a new composite String Attribute that holds the “numeric value + units” and update this whenever the temperature is updated… Perhaps?

Thanks for the tip, it’s worth a shot.

The only thing i worry after that is how rule engines would interpret this string since it’s not purely numerical.

Thanks for the offer Robin, if you could PM the code for your device handler it’d be much appreciated since it seems i fubar’ed rule smartApps by sticking the unit tag inside the value.

Not to mention the event list in the IDE :slight_smile:

Check out my DTH for the Sinope Thermostat.

You can’t use this new composite Attribute in arbitrary SmartApps. My intention was to solve your units display problem only.

For SmartApps / rules, you need to use the standard temperature Attribute only, though you can adjust its value in the DTH to be in either scale.

Thanks for the help guys, it’s much appreciated.

1 Like