I’ve been diving into the world of smart home automation, and I must say, it’s been an exciting journey! One of the challenges I’ve encountered is getting precise temperature readings from my ZigBee power outlet. After some research, I found that modifying the device handler (DH) could help me achieve the desired precision. Currently, the temperature is reported as a whole number, like 25°C, but I’d love it to display one decimal place, such as 25.4°C.
I came across some sample code that seemed promising, but it didn’t include the decimal precision I wanted. Here’s the code I’m working with:
java
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 value logged is something like 2653, which I believe corresponds to 26.53°C. My goal is to correctly return 26.5°C instead of just 26°C. I’ve tried tweaking the code, but I’m not entirely sure how to handle the decimal conversion properly.
Has anyone else tackled a similar issue? Any tips or resources would be greatly appreciated! I’m really looking forward to getting this working and sharing my findings with the community. ![]()