No display of temps below 10°C or 10% humidity in OpenHAB through MQTT

Hi all,

I’m struggling with a problem which i can relate to OpenHAB, but i’m not able to solve it. I’ve been searching the internet for a solution, but unable to find one. I have a DHT22 temp sensor connected to a NodeMCU, which communicates via Raspberry Pi 3 running Mosquitto and OpenHAB. All is working well and temperature+humidity are displayed correctly in Mosquitto and OpenHAB at room temperatures.

Yesterday i moved one DHT22+NodeMCU outside for outdoor temps+humidity. Temperature dropped from room temp to outside temp, but got stuck at ~10°C in OpenHAB while temperature outside was around 0°C. Humidity values were still being updated, being above 10%.
Since this moment i checked the following:

  • I checked multiple DHT22 sensors at room temp, but all displayed about the same values: DHT22 is likely not the problem
  • I cooled the DHT22 sensor to ~3°C while connected to the serial monitor of Arduino IDE: the serial monitor displayed the temperature correctly, being lower than 10°C. Even humidity dropped briefly to about 7%, while OpenHAB stopped updating at 10%: DHT22 is definitely not the problem
  • I logged into my RPi, opened a terminal and subscribed to the outside temp topic: MQTT displayed the same values as the serial monitor in Arduino IDE: MQTT is not the problem
  • When temperature and humidity reached values above 10 (°C or %) OpenHAB picked up the correct values again automatically
  • i checked the format of the variables in OpenHAB, being “Temperatuur [%.1f °C]” and “Luchtvochtigheid [%.1f %%]”, but this seems to be the appropriate annotation. I even changed them temporarily to %s, but without result for the values below 10 (°C or %)

So i’m guessing the problem lies within OpenHAB, but i’m out of options. Any help would be more than welcome! Thanx in advance.

Do you see any errors in openhab.log?

Do you see the correct values, 10 °C, or nothing at all in events.log when the the temp is below that threshold?

If you change the Item to a String Item and just print the value being read by OH, do you see anything that might point to a parsing error when the temp gets below the threshold? Common problems are leading or trailing white space, using a , instead of . for the decimal place, extraneous characters, etc.

There is nothing about the code that would cause OH to treat the numbers below 10 any differently than any other number so the problem almost has to be something different about the String that is being sent to OH when the number drops below 10.

1 Like

Thanx for your reply.
I see nothing at all in events.log. Below 10°C nothing is logged anymore, see screenshot of part of events.log.

I’m not sure if i follow you on the Item to String Item change, but i guess i have to look into arduino ide for a format conversion. See below for the code conversion before publishing to mqtt.

tempC = dtostrf(event.temperature, 5, 2, msgBuffer);
Serial.print("Temperature: ");
Serial.print(event.temperature);
Serial.println(" *C");
client.publish(tempTopic, tempC);

Variable " *tempC" is of type “Char”, as is necessary for the client.publish() input. Should i add code to convert tempC for <10 values like this?:
“tempC = dtostrf(event.temperature, 4, 2, msgBuffer);”

(I haven’t got the time to check it now, but i will try this code tomorrow. If my english is confusing (i’m dutch) please let me know :slight_smile: )

Thanx!

Assuming event.temperature is a float try the following:

client.publish(temptopic, String(event.temperature).c_str());
    

If that works then use round first to get event.temperature to two decimal places.

1 Like

Use a String Item instead of a Number Item and use [%s] in the label. That will show you EXACTLY what is being received and it will show you whether you are receiving values below 10 or not. If you do receive such values when it is a String it means there is something wrong with the value sent by the arduinos that OH can’t parse into a Number.

Don’t worry about that. I’d venture to say non-native English speakers are the majority on this forum. :slight_smile:

1 Like

I’m almost certain that numbers below 10 are being formatted with a space, probably where then tens digit would go.

In the place you have default in your MQTT item binding for subscribing (<), change it to JS(trim.js). Install the JavaScript transform if you haven’t already. Put the following in transform/trim.js:

(function(num){
 return num.trim();
})(input)
2 Likes

Thanx Michael, this seems to be the solution to my problem! I can see my temps below 10°C now :slight_smile:

Thanx Rich, i tried the String item and i got the right values in OH (that is without the solution of Michael applied yet). This would be a good solution too if no math is necessary.

Thanx for you reply John, but with Michael’s solution working i haven’t tried yours anymore. But it was definitely a format problem.

Finally i can see the outside temperature (8,8°C at the moment), thanx all! :slight_smile: :+1:

1 Like