How to connect to mqtt

I’m running mosquitto on my raspberry and can send/receive message using tools such as mqtt.fx or a chrome plugin but I can’t seem to be able to connect from withing OH2 (2.4 M7). I installed the mqtt service via addon which went fine

This is my mqtt.cfg:

broker.url=tcp://192.168.178.46:1883
broker.clientId=openhab
broker.user=openhabian
broker.pwd=<mypassword>

the items file has this:

Switch MQTT_Command “Command” {mqtt=“>[broker:openhabian:command:ON:LichtAn]”}
String MQTT_State “State [%s]” {mqtt=“<[broker:openhabian:state:default]”}

Openhab-cli bundle:list shows me services are active

225 │ Active │ 80 │ 1.2.0 │ Paho MQTT Client
226 │ Active │ 80 │ 0.10.0.201812070742 │ Eclipse SmartHome Automation API
227 │ Active │ 80 │ 0.10.0.201812121521 │ Eclipse SmartHome MQTT Binding
228 │ Active │ 80 │ 0.10.0.201812121521 │ Eclipse SmartHome MQTT Thing Binding
229 │ Active │ 80 │ 0.10.0.201812070742 │ Eclipse SmartHome MQTT Transport Bundle

Yet when I switch MQTT_Command via the UI I get no message written out, and MQTT_State does not read any change I publish via mqtt.fx. Quite obviously I seem to be missing something, but what?

You are using the mqtt 2.4 binding but are using a configuration for the mqtt 1.4 binding. It’s not entirely your fault. The website shows mqtt 1 documentation until the oh 2.4 release next Monday.

But if you are using a snapshot/milestone it is a little bit of your responsibility to find out the changes that happened (some bindings have incompatible configuration. Not only mqtt but also milight, zwave, hue emulation and a few other).

Cheers, david

Thank you @David_Graeff , no problem. Where can i find the new documentation? is it this one https://github.com/eclipse/smarthome/tree/master/extensions/binding/org.eclipse.smarthome.binding.mqtt.generic?

:+1:

All,

I’d need some help. Given that I was using the old syntax and understand that I should rather use the new one I simply copied the full examples from the new documentation page (see above), but it still isn’t working.

When I copy this into my mqtt.things file

Bridge mqtt:broker:myUnsecureBroker [ host=“192.168178.46”,secure=“OFF” ]
{
Thing mqtt:topic:mything {
Channels:
Type switch : lamp “Kitchen Lamp” [ mqttstate=“lamp/enabled”, mqttcommand=“lamp/enabled/set” ]
Type switch : fancylamp “Fancy Lamp” [ mqttstate=“fancy/lamp/state”, mqttcommand=“fancy/lamp/command”, on=“i-am-on”, off=“i-am-off” ]
Type string : alarmpanel “Alarm system” [ mqttstate=“alarm/panel/state”, mqttcommand=“alarm/panel/set”, allowedStates=“ARMED_HOME,ARMED_AWAY,UNARMED” ]
Type color : lampcolor “Kitchen Lamp color” [ mqttstate=“lamp/color”, mqttcommand=“lamp/color/set”, rgb=true ]
Type dimmer : blind “Blind” [ mqttstate=“blind/state”, mqttcommand=“blind/set”, min=0, max=5, step=1 ]
}
}

I get a

2018-12-16 11:00:21.749 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘mqtt.things’, using it anyway:

Provide a thing type ID and a thing ID in this format:

<thingTypeId> <thingId>

2018-12-16 11:00:21.764 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘mqtt.things’

warning/error. Displaying one of the switches in UI and changing them results in nothing being written out to MQTT. Using other tools I made sure I can read/write anonymously.

Secondly I get the following messages in the logs when i bundle:start the mqtt bundles

2018-12-16 11:08:31.628 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-12-16 11:08:31.631 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘mosquitto’
2018-12-16 11:08:31.701 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘m2m-eclipse’
2018-12-16 11:08:31.737 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’

so three brokers are started but I have only 1 in my mqtt.cfg file. Where are the brokers “mosquitto” and “m2m-eclipse” coming from?

broker.url=tcp://192.168.178.46:1883
broker.clientId=openhab

I’m pretty much sure there are only beginner config issues but I would be grateful for any hint what is going wrong

Thanks

Stefan

Probably from a non updated mqtt.config.
Delete /var/lib/openhab2/config/org/openhab/mqtt.config and restart openHAB.

Thank you @sihui - I now have one broker indeed. So partially resolved. However, I still get the error about the things (see above) even though I copied the example straight from the new doc page, and nothing is written out to MQTT

This is a pre-release documentation with errors and mistakes expected :wink: Especially because the author, which happens to be me, does not touch configuration files if avoidable. This example was given by another user, but there is at least one mistake in it that I have corrected already.

Thank you @David_Graeff. Well, if one isn’t too deeply in the subject matter it’s hard to know what is s mistake and what isn’t. I was hoping that the error is the the example, I copied, but it seems as if not - it still isn’t working. Guess I’ll stop exploring MQTT for now, I have been trying all sorts of combination for the last hours, but it’s eating too much time .

By the way: in the part of the example that states "

{
Thing mqtt:topic:mything {
Channels:

the “topic” is the element that leads to the log file waring. If I take it out, i.e. only thing mqtt mything {… it reads the item file without warning…

maybe that helps someone

May I ask why you don’t use Paper UI for configuration? Because that works.
After the release there will be many people coming up with textual example files, I’m pretty sure.

“Thing mqtt:topic:mything” means: Create a Thing of the type topic from the binding mqtt with the id mything. That is correct as it is.

Thanks David,

why not Paper UI? Because a) I only saw examples that had config files so I though that is the way to go b) when I go to Paper UI and want to add a thing I don’t see the MQTT binding I could bind to