String Item for temperature

Hello I made a small gateway software which gets data from serial port and publish data to mosquitto.

Unfortunately I didn’t managed to send temperature values as real float values, only as string, i am using paho MQTT Client library.

On openHAB I made a conversion from string to float as following:
String Temperature1_MQTT “Temperature_RFM69 [%s °C]” (GF_Heating,Heating) {mqtt="<[mymosquitto:sensor99/temperature:state:default]"}
Number Temperature1_RFM69 (GF_Heating,Heating)

rule "RFM69"
Item Temperature1_MQTT received update
var buff = Temperature1_MQTT.state.toString
var test = new Double(buff)

and sitemap:

Text item=Temperature1_MQTT icon=“temperature” {Frame item=Temperature1_RFM69 label=“Temperature_RFM69 Graph” {
Chart item=Temperature1_RFM69 period=4h refresh=1000 h=200 w=800

Everything works, meaning that values are displayed and stored in rrd.

My problem is that the openhab webui is not automatically updated.
More, when I click on the interface in order to see the chart, is not working (the page is not displaying the new page which should contain the graph).
I managed to observe that the problem seems to be:
String Temperature1_MQTT “Temperature_RFM69 [%s °C]” (GF_Heating,Heating) {mqtt="<[mymosquitto:sensor99/temperature:state:default]"}

And my guess is the type “String”.

Help is highly appreciated.

If someone needs my source code for “gateway” from serial port to mqtt broker, can just ask for it. is not in it’s final form, but is working.

There is a bug in OH 1 that prevents the UI from always refreshing with the latest values. If you reload the sitemap or go into a frame and back out doe it then show the correct value?

If this is indeed the problem, there is no fix available. It is fixed in OH 2 but will not be fixed in OH 1.

What is your rrd4j persistence configuration? One problem with rrd4j is that charting and sometimes other persistence activities will not work unless you are saving the data on your Items at least once a minute whether or not they are changing.

Indeed this is a problem. rrd4j can only save numerical data. However, if you just change your Item definition to:

Number Temperature1_MQTT "Temperature_RFM69 [%s °C]" (GF_Heating,Heating) {mqtt="<[mymosquitto:sensor99/temperature:state:default]"}

OH is smart enough to convert the String to a Number, assuming it is just the the digits (e.g. there are no leading or trailing spaces in the data published to the broker).

if i write:
Number Temperature1_MQTT “Temperature_RFM69 [%s °C]” (GF_Heating,Heating) {mqtt="<[mymosquitto:sensor98/temperature:state:default]"}
Then I get this message in openhab.log:

given new state is NULL, couldn’t post update for ‘Temperature1_MQTT’

RRD4J has no problem because only item Temperature1_RFM69 is stored in rrd4j, which is a number and everything is ok with it.

That means the value being passed over MQTT isn’t a parsable number. It likely has trailing or leading whitespace. You may have to trim it. Search “MQTT JavaScript Trim” in this forum and you will see some examples of how to do this.

Then I will repeat my question, are you saving the value every minute or only on changes? rrd4j charting will not work unless you save at least every minute.

I solved the problem, it seems that in my “gateway” software i was sending more characters than data, fixed it and now works only by replacing String with Number in items file.

Yes rrd4j is configured as storing once per minute