OH2 mqtt commands


I’m new to this smart home thing. So I’m following every tutorial I found but I’m having some problems to make OH2 getting and sending instructions
I have RPi + Raspbian + mosquitto. My goal is to send and receive from/to an arduino to OH2.

Resuming: My mosquitto broker seams to work fine (tested in the rapbian terminal and with a remote pc using mqtt.fx), so the problem must lie somewhere with OH2 config:
1 - I added a file mqtt.cfg to /etc/openhab2/services with the content (saw in a tutorial somewhere):

  1. Added 2 items:
    Switch ArduinoRelay2 “Nome da tomada 2” {mqtt=">[broker:mikasa/garagem/relay2:command:ON:1],>[broker:mikasa/garagem/relay2:command:OFF:0],<[broker:mikasa/garagem/relay2:state:ON:1],<[broker:mikasa/garagem/relay:state:OFF:0]"}
    Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[broker:mikasa/garagem/temperatura:state:default]"}

  2. and added those to the sitemap so they can be seen in the OH2 browser

  3. from the raspbian terminal typed:
    mosquitto_pub -h localhost -t mikasa/garagem/temperatura -m “22”

My goal is to get and set some relay status and temperature from a thermoresistor.
Can someone spot whats wrong here?

Thanks in advance

Please read the docs.

Did you actually install the MQTT Binding? If you had successfully then a default services/mqtt.cfg should have been created for you.

Remove the “mqtt:” part of your configs, that is the old OH 1.x style of configuration back when all the configs were in the same file.

Have you set up username/password on Mosquitto? If so you need to fill out the mqtt:user and mqtt:password fields.

Hi Rich

Thanks for your reply.

Did you actually install the MQTT Binding? If you had successfully then a default services/mqtt.cfg should >>have been created for you.
I did now… It created a new file called mqtt-eventbus.cfg.

Remove the “mqtt:” part of your configs, that is the old OH 1.x style of configuration back when all the >>configs were in the same file.
I delete the file mqtt.cfg. OH created a new file descrived above.
That file mqtt-eventbus.cfg dont have the same syntax. It also refers to a openhab.cfg file that i cant find.

Have you set up username/password on Mosquitto? If so you need to fill out the mqtt:user and >>mqtt:password fields.
Yes I did.

There should be an mqtt.cfg file too. You don’t want to mess with the mqtt-eventbus.cfg.

There is no longer an openhab.cfg file. That is a 1.x version thing and doesn’t exist for OH 2.x

Not knowing the order you did things I can’t say what happened.But I recommend uninstalling the mqtt binding. Deleting the mqtt*.cfg files. Then reinsall the mqtt binding.

Then fill out the config as documented in the readme, including the username and password.

I did reinstall the mqtt binding. There is now the file mqtt.cfg
I uncommented and chaged changed the lines:

my item is configurated like this
Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[broker:mikasa/garagem/temperatura:state:default]"}

In my Windows PC I open mqtt.fx and subscrive the topic "mikasa/#"
then at the RPi terminal typed:
mosquitto_pub -h localhost -t mikasa/garagem/temperatura -m “20”

mqtt.fx gets the message, OH dont change a thing

Once again, fill out the config as documented in the binding’s readme


<broker> is an alias name for the MQTT broker. This is the name you can use in the item binding configurations afterwards.

i’m following the syntax… replaced broker by mosquitto, in mqtt.cfg and in my item same result.
is there a tutorial for OH2 with mqtt? only find for OH1


This is the tutorial with examples.

If you were following the syntax your mqtt.cfg file would look like:


rather than what I assume (since you didn’t use code fences anything between < > gets hidden) you have which is:


and your Item would be:

Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[mosquitto:mikasa/garagem/temperatura:state:default]"}

instead of:

Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[broker:mikasa/garagem/temperatura:state:default]"}

Look at the examples on the readme. Notice how it consistently uses the same name for the “broker” part in both the configs and the Items.

the files are like that and is not working…
Im also realized that my page is not showing the date and some of the icons are not the same as the page

I’ll try to install everything from the begining and see if it solves the problem.

After some days struggling to get a solution… The thing is… By this date, there is no solution.
The mosquitto version that cames with the raspbian image don’t work with openhab2, and mosquitto can’t be updated for the latest raspbian stretch as shown at https://github.com/eclipse/mosquitto/issues/529
All I can do now is wait for some gentil soul works on a solution :confounded:

Is there any reason you must be on stretch? It works just fine on Jessie.

That’s better than just giving up. Some people are still running on weezy just fine.

If you are cohosting OH and mosquito on the same pi, I’d recommend using openHABian.

I’m using the stretch because it’s the image that is available to download at:

cant find the jessie image.

openhabian dont even starts. gives a processor error in the config (tried twice with 2 different SD cards).
It refers to a processor error…

@ThomDietrich, any ideas?

I just installed Jessie on a brand new Pi Zero W and didn’t see any sorts of errors.

You can download older versions of Raspbian here:


Hello @xSERGIOx,
the mosquitto error is one of the issues why we didn’t yet move the openHABian image to stretch (which we will do very soon). However changes introduced in stretch are pretty much unimportant for openHAB (bluetooth audio improvements might be interesting). Please try again with the latest openHABian image.

Regarding the problems, I believe @rlkoshak has mentioned all that’s needed.

  1. Set up openHAB
  2. Set up an MQTT broker
  3. Check the broker is working, using a desktop client
  4. Install and connect the MQTT binding
  5. Bind a simple item to an MQTT topic, once again check the functionality (desktop client)
  6. Continue

Could you please summarize once again where you are having problems?

Started again from scratch and followed Rich advise and installed Raspbian Jessie…
I’m stuck at the same point as before…
The mqtt binding is installed, mosquitto is working and openhab don’t get it…
I’m trying to do something simple such as get and set a relay status and get a sensor value such temperature
Switch ArduinoGarageRelay1 “Grupo Tomadas Parede” {mqtt=">[mosquitto:mikasa/garagem/relay1:command:ON:1],>[mosquitto:mikasa/garagem/relay1:command:OFF:0]"}
Number ArduinoGarageThermoresistor “Temperatura [%.1f C]” {mqtt="<[mosquitto:mikasa/garagem/temperatura:state:default]"}

I’m plublishing mqtt messages using the terminal at the RPi and from windows mqtt.fx and each one receibes one another, but openhab dont.
I also notice that Basic UI at the Rpi is not updating values (need to manually refresh), unlike the Paper UI, and at Android (that uses the same Basic UI) does auto refresh… Is this how its supposed to be?

Please use code fences to format your Item and cfg text. It is soo much easier to read when you do:

code goes here

Are there errors in the log? If you are not publishing something that can be parsed into a Number (e.g. there is white space before or after the digits) OH won’t be able to convert the text into a Number. These will generate error logs.

You should at least see a “Starting MQTT broker connection ‘mosquitto’” in your logs at OH startup if everything is OK. That will narrow the problem down to one of mqtt.cfg or your Items.

Do you have the MQTT Action installed? If so uninstall and reinstall it. This is a known issue and reinstalling the Action fixes it.

I can’t say anything about autorefresh on the Pi, but perhaps the browser on the Pi doens’t support as fast of an autorefresh. All other things being equal, the entries in BasicUI should refresh within a few seconds of the change, usually a lot faster.

Maybe the log file have some clue about the problem.

[INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-09-07 18:44:43.003 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2017-09-07 18:44:47.505 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.core.thing.link.ThingLinkManager@6f3567’ takes more than 5000ms.
2017-09-07 18:50:17.477 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.io.monitor.internal.EventLogger@f2b96e’ takes more than 5000ms.
2017-09-07 18:50:17.659 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.io.monitor.internal.EventLogger@f2b96e’ takes more than 5000ms.

so the service starts but it cant get events from it, I think.

At this point, I recommend reading and following the following:

1 Like