Set up mqtt2 from scratch on linux

I run openHAB 2.4 stable on I3 desktop running Debian 9
I’ve been using openHAB for 6 months so I know openHAB pretty well. I know nothing about mqtt other then what I’ve read here on the forum. I have tasker on my phone and would like to send mqtt from phone to openHAB when connected locally. I am NOT looking for help with Tasker, I need help getting mqtt running in openHAB. I have installed mqtt2 binding and mqtt generic thing binding. I set up the embedded broker in openHAB and it shows in paper UI. I am not using any credentials. I have mqttfx installed on separate Win laptop to monitor the set up until I get everything running and it seems to connect to openHAB server running broker.
first question
Do I create the channel for messages to be sent in generic mqtt thing or mqtt broker
edit ANSWER:
In the generic thing
create a channel in the generic mqtt thing, give it a topic

which does the item I create link to?
ANSWER:
link an item to the channel created in the generic thing

I’ve read the docs here:
mqtt binding

mqtt generic thing binding

And found this tutorial by @Sascha_Billian

I will start and others may chime in, here some general thoughts that hopefully will help you:

  • MQTT works on the publication/subscription mechanism (pub/sub) and is organized in topics; a message can be be published to the MQTT broker (e.g., by a device) under a specific topic, and any subscriber for this topic will received that message; in this regard, MQTT is just an information broker, it receives information and distributes it .
  • OH will need a binding to be able to communicate with a broker…through the binding, a Thing will be able to receive or post messages from the broker; the topic will define to what messages the Things is subscribed or will publish; you will then have of course channels and items as with everything else OH interacts.
  • So for MQTT it will be critical that you know the topic under which information are posted to the MQTT Broker, as you will need to subscribe to the same topic to receive the information. The topic-construct is specific to the broker and organize how the broker distributes the messages to the subscribers. The Thing will need to know this topic…

I don’t use tasker, so cannot help with specifics, but in general terms: you will need to configure tasker to connect to the broker (you need ip and port number), and define a topic under which tasker will publish the message to the broker; you will then need the Thing to subscribe to this topic (through the MQTT bridge that you will need setup as per docs) and link the Thing through a channel to an item…and voila…tasker talks to OH2

Hope this helps

Thanks @lipp_markus for background info on mqtt. I understand the basics of the protocol and I don’t require help with Tasker. (I’ve edited my post to indicate that) but need help implementing mqtt in openHAB

Which thing? The generic mqtt thing or broker thing?

Got it, sorry.
You will need to configure the broker (bridge) and the MQTT thing; here an example from my config (I have everything configured in text files):

  • MQTT broker is mosquitto running on the same machine as OH, no security enabled
  • I have a sensor that measures both, humidity and temperature (one Thing, two Channels)

Here the Things definition

Bridge mqtt:broker:mosquitto "Mosquitto" @ "Systems" [ host="127.0.0.1", secure=false ]	
	{
	Thing topic mysensor_Thing "Mysensor_Thing" @ "Downstairs" { 
		Channels:
			Type string : Humidity "Humidity" [ stateTopic="homie/5ccf7f2cdc52/humidity/humidity" ]
			Type string : Temperature "Temperature" [ stateTopic="homie/5ccf7f2cdc52/temperature/temperature" ]
	}
}

Here the Items definitions

String Mytestsensor_temp (gSensors) {channel="mqtt:topic:mosquitto:mysensor_Thing:Temperature"}
String Mytestsensor_hum (gSensors) {channel="mqtt:topic:mosquitto:mysensor_Thing:Humidity"}

Hope that helps as example.

1 Like

You may want to look into this (I much prefer it over mqttfx)

1 Like

Yes, I saw that post. looks like a cool application. I only installed mqttfx on separate laptop to be able to monitor the set up until I have everything working. Thanks for help so far.