NodeMCU based MQTT multi-sensor with OLED display

Thank you - I’m glad my project is helping you learn openHAB (making it helped me, as well!).

The code will set an output value of -1 when either the temperature or humidity readings become invalid. The only time I’ve seen that was when I was using either a breadboard (testing), or using a proto-board setup, with the DHT22 sensor inserted into pin headers. I’m pretty sure it’s due to an intermittent connection issue. With all of the sensors I’ve put on my PCB I’ve never had any issues. I don’t think it’s your Wifi signal either, because then you’ll just get a non-changing value (openHAB item/MQTT topic will not get an update).

You could disable the logic in the Arduino IDE (just comment out the line that sets the sensor value to “-1” when the value is not a valid number). Then, the value you get over MQTT will just remain steady (stale) until the connection to the sensor is reestablished. That’s much easier to do than handling it in openHAB (though you could do it with a JS transform, I guess).Clearly the best solution is to make sure your sensor connection is solid (those Dupont connectors/headers don’t always work well).

Enjoy your adventure with openHAB!