Display temperature and humidity in Openhab2

Dude…

You use the wrong configuration for the wrong binding (version)!

1 Like

@Hinda
Did you understand the problem or do you need more help?

Hello;
I am still in stuck with my project.

Okay, as @BrutalBirdie says, you were trying to use MQTT version 1 configuration with the version 2 binding, it isn’t going to work as they are quite different.

Be careful looking at any old MQTT tutorials or posts, as they are not going to tell you about this (before version 2 was created).

So, you need to start over and create Things and channels for your version 2 MQTT binding, as in the binding docs.

I have looked for MQTT version 1 or older but I did not find any.
So I think I should install mosquitto version 2.0.4 in order to be compatible with the version of MQTT 2.0.4.
Please reply to me soon.

No. Use what mosquitto you like.

It doesn’t matter to openHAB what mosquitto you use, it’s just a broker.
openHAB needs to talk to your chosen broker using a binding. openHAB-2 has a binding MQTT version 2, that will do the job.
You need to configure things and channels for version 2, and link your openHAB Items to channels.

Ignore any old notes and documents that you might find with configurations involving mqtt.cfg or {mqtt= "..."}, they simply won’t work with version 2.

You mean that I have to remove definitively the mqtt.cfg file ?

mqtt.cfg is totally useless with MQTT binding version 2.

Item definitions including {mqtt="..." are totally useless with MQTT binding version 2.

Configuring of MQTT binding version 2 must be done with things and channels.
You define a Thing pointing at your MQTT broker.
You define channels for the MQTT topics you want.
You link openHAB Items to those channels.

Delete services/mqtt.cfg

Create a file things/mqtt.things with the following contents:

Bridge mqtt:broker:mosquitto "MQTT Broker" [ host="192.168.2.169", secure=false, username="", password="", clientID="openHAB2" ]
{
  Thing topic livingroom "Livingroom Things" {
    Channels:
    Type number : temperature "Temperature" [ stateTopic="topicName/temperature" ]
    Type number : humidity "Humidity" [ stateTopic="topicName/humidity" ]
  }
}

Create a file items/mqtt.items with the following contents:

Number  home_temp "Living Room [%.1f °C]" <temperature> { channel="mqtt:topic:mosquitto:livingroom:temperature" }

More info:

2 Likes

Thanks a million.
That is very kind of you.
I will try it and tell you the results.

Just to clarify.
This is the manual “hard” way (Textual Configuration) which is not necessary.
All this can be done via PaperUI.

4 Likes

True enough. The OP is already defining the textual way in an xxx.items file, so they’re not unfamiliar with it.

Thanks guys for your advice.
Thanks to your constructive advice and directions it works very well.

1 Like

Hello guys,
I want to secure my user interface of Openhab2 in order to give the user just the access to visualize the interface but not to change a parameter or configuration or install/uninstall an item or a library.
And I have noticed that if I give the user the ip address with the port so he could modify the configurations.
Would you please tell me how may I secure my UI paper.
Thanks in advance.

It cannot really be done. All of the UIs work through the REST APIs. You can either allow access to the entire REST API or none of it (in which case no UI works). It might be possible to set up a reverse proxy that only allows access to the PaperUI for certain users, but that would not prevent someone knowledgeable from making config changes through the REST API directly.

1 Like

Hello,
I saw the code for esp8266 above, can I have some information how the bool function called checkbound worked.
Is it possible to set a minimum difference between the new and previous value?
When the function returns true or false, how is the value used?
This function is used to publish the data only if it has changed from the previous one sent?
Thanks.