Why do all the temp sensors truncate the numbers instead of round?


(Patrick Stuart [@pstuart]) #1

I just picked up a AEON multi sensor and looked at the devicetype code, and sure enough, just like the ST multi sensor the device code truncates the readings.

So, if it read 77.9 then the ST Things interface will read 77. This is not correct.

I’ve modified this code to round up, but I’ve found this same type of bug in almost every temp aware device so far.

If anyone wants the code, let me know. I also added the ability to adjust the temp calibration up or down.


Questions about temperature data in ST
(Jim Roberts) #2

I ran into the same issue when trying to report a battery voltage. At some point, I found a reply around here from ST stating its an issue in mobileapp(s).

I sorta got around it by separating out the integer and fractional components and then re-combining in a string format. However even the string cannot contain the format x.x, you have to use some other delimiter. So 77,9 will work, or put space between the decimal point and number; 77. 9

 	def intVdc = (data.topaz.battery_level.toFloat()/1000).round(0)
def fracVdc = (data.topaz.battery_level.mod(intVdc*1000)).toInteger()   
    intVdc = intVdc.toInteger()

    sendEvent(name: 'batteryvolts', value: "$intVdc. $fracVdc" )