[Solved] Items not working with MQTT

Hey Everyone.
As much as it pains me to make yet another “help me” topic especially involving MQTT, I just can not get mine to work.
Info about my install:
OH2 2.2.0-1 running on a RPi3. Mosquito is my broker. I installed Mosquito through the openhabian-config and also installed the MQTT bidding version 1.11.0.

I am currently trying to subscribe to two topics: garage/door and garage/button so I can control my garage and get the status of the door. I can subscribe and send commands through MQTT.fx.
Here is my mqtt.cfg, obviously with a few things I do not want to share, ip, usernames, pass…


Next we got my items:

String  GarageDoorState "Door State" {mqtt="<[broker:/garage/door:state:default]"}
Switch GarageDoorButton "Garage Door" { mqtt=">[broker:garage/button:command:OPEN]"}

No matter what I seem to do, I can not control the door through BasicUI or HABPanel.

//Garage Door
Frame label="Garage Door"{
        Switch item=GarageDoorButton
        Text item=GarageDoorState

On BasicUI the state is blank. On HABPanel the state shows NULL. The switch doesn’t work with either.

Does anyone have any idea what I am doing wrong?

check a couple of things first to start with the troubleshooting:
0) Read through MQTT Binding (v1.11) Getting Started 101

  1. Check the log files (in /var/log/openhab2/ directory)
  2. Check the contents of your /var/lib/openhab2/config/org/openhab/mqtt.config and see if they correspond to your /etc/openhab2/services/mqtt.cfg settings
  3. Fix your items file:
Switch GarageDoorButton "Garage Door" {mqtt=">[broker:garage/button:command:*:default]"}
1 Like

I would say this is wrong for item type switch … it can be ON or OFF… not open… also you have missed the / before garage

would have changed it to:

Switch GarageDoorButton "Garage Door" { mqtt=">[broker:/garage/button:command:OPEN:ON]"}

Just checking there’s no reserved word of “broker” in openhab? ie. there’s no issues with replacing the “” placeholders with a broker named broker?

Quick update. Followed the steps

and realized my log file has literally tens of thousands of lines in it after I mounted the Pi and opened up the logs with Atom. This was by system info binding generated a cpu usage change every 3 seconds. I also noticed big time glitches with my OH install, so I felt it was best to do a fresh install Currently setting iit all back up.

1 Like

Ok I made a quick little light sensor on a different NodeMCU to eliminate the possibility of bad hardware. Used this person’s tutorial, which does not really matter but credit should be given: Light Sensor
Like my garage door, I can subscribe and publish commands through MQTT.fx, but any item with OH does not work. I believe this is coming down to a typo or something in one of my files.
Here is what I have in my .items file:

//Garage Door
String  GarageDoorState "Door State" { mqtt="<[ohmqtt:/garage/door:state:default]" }
Switch GarageDoorButton "Garage Door" { mqtt=">[ohmqtt:/garage/button:command:ON:default]" }
String Light_Sensor "Light Sensor" { mqtt="<[ohmqtt:/OsoyooData:state:default]" }

I am confused to which items config I should use provided by you two.


I can subscribe and see the light and garage door readouts. Still can’t see values besides NULL in my sitemap or HABPanel.

To check this, even though I am pretty sure you can have a broker named broker, I changed my mqtt.cfg. I of course changed all values I am using.


Thanks to all of you who are spending time out of your day helping me. I really appreciate it.
Here is my /var/lib/openhab2/config/org/openhab/mqtt.config:


Here is my /services/mqtt.cfg:


Does it need to be tcp or ssl? What about the ports? Are those all correct? Would anyone like to show me their two config files?
I think they are correct because of my log showing

2018-01-19 13:57:26.284 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-01-19 13:57:26.287 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'ohmqtt'

UPDATE!!! I got it! Changed everything, and removed the / before my garage/door topic. Thanks to all for the help, I changed a ton of stuff. It was not just the /. Thank you everyone.

1 Like

Would be nice if you posted your working code here for future reference…

My bad Johan, I should of done that.

Here is what I did to fix this, and to some this info may be common sense or whatever, but I am new to all this so hopefully someone can learn something from this.
First, check out MQTT Binding (v1.11) Getting Started 101
To access your log viewer, don’t click the log viewer at the IP of your openhab install. Instead, type in the ip followed by :9001.


I couldn’t figure out why I couldn’t see the log for my install when clicked in the UI. This may not apply to everyone, but if someone runs into this, here you go.
Next check two files.


I am not using QOS so I have it commented out until I want to use it. My two files look like:




For both of these, the “ohmqtt” on each line is the name of your broker. If you change this, change it on every single line, and remember it is the very first value in mqtt channel for items. The user does not have to be the same as the broker name, I just kept mine as ohmqtt.
For this configuration, your .items should look like:

String GarageDoorState "Door State" { mqtt="<[ohmqtt:garage/door:state:default]" }
Switch GarageDoorButton "Garage Door" { mqtt=">[ohmqtt:garage/button:command:ON:default]" }

Again, to many some of the stuff I said is common sense, but I am very new to this and hope someone else can benefit from this as well.

By using ohmqqt.retain=true you are telling your Broker to save a copy of the last message sent to every topic you ever send from openhab, and pass this on to any device that may connect and subscribe to that topic.

For some things, that’s good. For others, that may be bad. For example if you sent “Open” to your garage door via openhab, and then closed it using a button on the door itself (which didn’t send a “Close” command back to the same topic), if the power went out to your garage door device, it would re-subscribe to the MQTT broker & topic, and immediately be given the “Open” command - and your garage door would open. This probably isn’t your intended behaviour!

Thank you for pointing that out to me. I have changed my code to fix this.

I have the same problem. Sice reboot my virtual machine with centos (openhab) the mqtt is not working. The two directories have the same configuration :roll_eyes: