[SOLVED] Sending data to UI via MQTT

Hi all
First of all I’m a completly beginner with Raspberry and OpenHab so be patient with me :slight_smile:

I want to send temperature and humidity from DHT11 to my OpenHab. I followed this tutorial but the temperature and humidity is not displayed properly in BasicUI.

What I see in PuTTy:

I think that I have something wrong in my mqtt settings. I have installed Mosquitto through openhabian-config and installed mqtt bindings in PaperUI.

My mqtt.dhtsensor.py looks like this:

MOSQUITTO_HOST = 'openhabianpi'
MOSQUITTO_TEMP_MSG = str(sys.argv[1]) # Old channel name in here
MOSQUITTO_HUMI_MSG = str(sys.argv[2]) # Old channel name now passed by argument
print('Mosquitto Temp MSG {0}'.format(MOSQUITTO_TEMP_MSG))
print('Mosquitto Humidity MSG {0}'.format(MOSQUITTO_HUMI_MSG))

I’m not sure if MOSQUITTO_HOST and PORT is correct is I typed there an adress that I use to connect to my OpenHab.

My demo.items looks like this:

Number Cupboard_temp "Riser temperatuur [%.1f °C]" <temperature> (GF_Corridor) {mqtt="<[mosquitto:cupboard/temperature1:state:default]"}
Number Cupboard_humidity "Riser humidity [%.0f %%]" <line> (GF_Corridor) {mqtt="<[mosquitto:cupboard/humidity1:state:default]"}

My mqtt bindings in PaperUI looks like this:

And mqtt services in PaperUI looks like this:

Can’t say how/if this script is working however your item setup uses the MQTT syntax for the Binding version ! although you seem to have installed the version 2 binding. On version 2 bindings you need to setup Things, which have channels. Items can connect to those channels.

So I assume i have to fill this?

You need to have a broker-thing (which represents the connection from openHAB to your MQTT broker) AND you need the mqtt things (which represent your devices using the MQTT protokoll).
Only for the later you need to create the channels.
All documented in here

Regarding the problem with the script (are you sure the devices are sending messages) I’d use an external MQTT viewer (like MQTTfx) in order to check if/which messages are really being sent.


So I created MQTT Broker:

and MQTT Thing

And now my Things looks like that

I also used MQTTfx as you said and it shows that messages are being sent.

MQTTfx shows that you know which message to subscribe to in order to get a temperature or humidity. Create channels for both with a StateTopic holding the respective subscription. As you are getting the value directly from this subscription no transformation should be needed.

All the honor goes the the author of this binding!

1 Like

Im wondering what I have to put in Channel id

The name of that channel as YOU want to have it.

1 Like

Thanks man! Everything works!
Now im ready to watch der Klassiker :slight_smile:

…and you can monitor the rising temperature and trigger someone if the humidity drops.

1 Like

I will work on that for sure.