MQTT question

I have built an arduino mqtt device, all it does is report temperature, humidity and light level, back to openhab every 2 minutes.

I’m sure this is a binding issue or I’m not using it correctly, as when I use an mqtt client to see the traffic, I get the data I expect. Anyhow lets get to the problem.

In openhab, whenever the light level gets updated to any value under 10. when I open my control panel from my web browser or the openhab app on my phone, it ether shows the state as blank or a dash, whenever the value is higher than 10 percent it displays as expected.

this is my binding:

Number lightLevel “Light Level [%.1f]” (lr) {mqtt=“<[myBroker:STATUS/LIGHT:state:default]”}

Any Suggestions?

Do you have a MQTT broker installed or used a cloud based broker?
the MQTT binding acts as a client and I would assume that your Ardunio board is also acting as a client aswell.

I do have my own broker on the network, the messages are getting into openhab, I have other mqtt stuff happening as well, all seems fine.

let me clarify, when openhab receives a light level that is less then 10%, it does update the state according to the console, but it doesn’t show that value within the user interface, just a - .

I suspect that there is a space character in front of 9 and lower values, which does not allow openHAB to recognize the MQTT message as a number. In your MQTT in-binding strings, replace default with JS(trim.js), and create a text file in openHAB’s transform directory named trim.js:

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

This will remove any leading and trailing spaces from the string, which the MQTT binding will then be able to parse as a number and update your items.

4 Likes

Thanks a lot!, that solved my problem Instantly

1 Like