Issues with MQTT humidity sensor

Hello, everyone. I’m new to Openhab. Now I want to recieve messages from i.thu-skyworks.org and show them on the web http://127.0.0.1:8080/openhab.app?sitemap=demo.

In openhab.cfg
mqtt:rpibroker.url=tcp://i.thu-skyworks.org:1883
mqtt:rpibroker.clientId=MQTT

In demo.items
Number Humi_skyworks “Humidity: [%.1f %%]” (Weather) {mqtt="<[rpibroker:/values/i_10536884/humidity:state:default]"}

In demo.sitemap
Text item=Humi_skyworks

Using the command ‘mosquitto_sub -h i.thu-skyworks.org -t ‘/#’ -v’, I get
mosquitto_sub -h i.thu-skyworks.org -t ‘/#’ -v
/capability/i_10536993/values gas,mV
/capability/i_10536852/values human,*
/capability/i_10536703/values temperature,Chumidity,%RH
/capability/i_10536884/values illuminance,lx
pressure,Pa

/capability/i_10536884/control switch,int
PWM,int

/capability/i_10349952/values illuminance,lx
/capability/i_10536809/control switch,int
/values/i_10536993/illuminance 61 lx
/values/i_10536993/gas 273 mV
/values/i_10536852/human true *
/values/i_10536703/temperature 26.00 C
/values/i_10536703/humidity 30.00 %RH
/values/i_10536884/gas 2116 mV
/values/i_10536884/temperature nan C
/values/i_10536884/humidity 0.00 %RH
/values/i_10536884/illuminance 13654 lx
/values/i_10536884/pressure 211888.00 Pa
/values/i_10349952/illuminance 17066 lx

However, in the web is always

What can I do to make it show Humidity normally? Thank you for every help!

I am pretty sure your problem is that the MQTT client sends the unit (%RH) as well and not just a number. This prevents openhab from using the default setup of transformations to conver the MQTT message to a float value (for your Number item).

You should be able to strip away the unit part (%RH) of the message from the MQTT client by using a transformation/regex expression in the item definition so that openhab can concentrate on converting the actual value.

Sadly I cannot tell you in detail how to configure said transformation/regex, :frowning:

1 Like

One thing I always do when I hit MQTT problems is to fire up MyMQTT on my android phone and subscribe to what you are hoping to see in OH.

That way you get to see what is happening and if you have the correct topic addressing etc.
I’ve a sneaky feeling that the leading “/” shouldnt be there but I might be wrong

In demo.items

Number Humi_skyworks "Humidity: [%.1f %%]"  (Weather) {mqtt="<[rpibroker:/values/i_10536884/humidity:state:JS(numonly.js)]"}

transform/numonly.js (untested):

(function(rh) {
  return rh.split(" ")[0];
})(input);

Thank you!
But there is something wrong. Even I write in the transform/numonly.js as below:
(function(rh) {
return 0.3
})(input);
The result is same with above.

Is anything wrong with my openhab.cfg?
mqtt:rpibroker.url=tcp://i.thu-skyworks.org:1883

Have you added

mqtt:.user=
mqtt:.pwd=

to the config file with the relevant detail to your setup?

No…They are essential?

Now I get the right web, which shows the value of Huminity.
But, I can’t change it.