Temperature Sensor (Celcius with one decimal)

I have ZigBee power outlet with temperature reporting and writing a custom DH for it. I have copy pasted some code from a temperature sensor and this is working fine, but with no decimal. I would like the device to report “25.4C” rather than just “25C”.

Code looks like this:

> def getTemperature(value) {
> 	log.debug "Temperature raw: $value"
> 	def celsius = Integer.parseInt(value, 16).shortValue() / 100
>   
>         if(getTemperatureScale() == "C"){
> 		return Math.round(celsius)
> 		} else {
> 			return Math.round(celsiusToFahrenheit(celsius))
> 		}
> 	}

The raw temperature logged looks like this: 2653

How can I correctly return 26.5C?

Kind regards

Bump :slight_smile:

This works for me:

if (value.isNumber()) {
    Double temperature = value.toDouble() / 100.0
    if (getTemperatureScale() == 'C') {
        return temperature.round(1).toString()+'C'
    } else {
        return celsiusToFahrenheit(temperature).round(0).toString()+'F'
    }
}

(Sorry, I took you literally about returning 26.5C - if you just want the value, drop the .toString()+‘C’ )