SOLVED: Problem: MQTT Item-> two digit floats:ok, one digit: fail

Dear all,

I have several Item definitions relying on MQTT information. For example:

Number C099_TempSensorB “Temperatur [%.1f °C]” (C099_SensorsetB) { mqtt="<[MQTTServer:099/O/THS/B/TEMP:state:default]" }

This works fine when two digit (before the comma) numbers are transmitted. If the temperature sinks below 10° (becoming one digit) the information is not passed to the item anymore.

So this sensor data is processed:

099/O/THS/D/STATUS OK
099/O/THS/D/HUM 55.2
099/O/THS/D/TEMP 10.3

This is not:

099/O/THS/B/STATUS OK
099/O/THS/B/HUM 94.4
099/O/THS/B/TEMP 2.3

When looking closely at the data, I sense the problem:

Working Sensor data:

“OK”
“55.4”
“10.3”

Non working sensor data:

“OK”
“94.7”
" 2.3"
Please notice the blank in front of the number.

Any ideas how to ignore the blank?

Thanks,
Christian

Happy new year btw :wink:

If you push the incoming MQTT message through a transform to trim off the space, then it will become an acceptable string from which to create a DecimalType, which can then update the Number item. This should be true for all versions of the MQTT binding including the change in 1.8.

Example:

Number C099_TempSensorB "Temperatur [%.1f °C]" (C099_SensorsetB) { mqtt="<[MQTTServer:099/O/THS/B/TEMP:state:JS(trim.js)]" }

transform/trim.js (not tested):

(function(num){ return num.trim(); })(input)
// or (function(num){ return num.replace(/^\s+|\s+$/gm,''); })(input)

And Happy New Year to you, too!

1 Like

Hey Watou,

thanks! Works fine!
Christian

1 Like