Help with MQTT please

Hi All

I’m very new to OH, so please be gentle :slight_smile:

I have OH 2 running on a Pi3.
I’ve setup a demo page with a few switches and a site map.

I’m using a H801 RGBWW and SonOff basic both reflashed with Tasmota firmware.

The devices are definitely sending messages to the MQTT server on the Pi. I can see the messages appearing on there.

If I use mosquitto_pub I can send commands successfully to the units.

However, no matter what I do, I can’t seem to get any messages to appear from OpenHAB.

I can’t find a guide that goes through the basics step by step to setting it up.

I installed Mosquitto manually, but I’m confused with the plugin and options in paperui.

Any ideas, suggestions and help gratefully received :slight_smile:

Welcome to OH. Having just deployed mqtt yesterday, I’ll try to help (though I’m still learning). To get a basic deployment started you need to install the Matt binding (don’t install the actions binding) and edit the mqtt.cfg file in your conf/services directory to point OH at your mqtt broker.



Then you can start defining items as per the binding page or just sync your OH event bus (basic config below) to have all OH commands/state changes go to mqtt and subscribe to any commands/state changes you want to retrieve from Matt (though you will need OH items ready to receive those commands/state changes.



From there you can move on to configuration passwords or customize qos or other settings.


Does that mean I didn’t need to install mosquitto itself manually? Just through paperui?

Mosquito is a mqtt broker that runs independent from OH. From your first post I assumed you already had an mqtt broker running ?

If you were referring to the mqtt binding, yes you install that from PaperUI but since it is an OH 1 binding you have to configure it from text files

Yes I have a broker running.

I can send messages and it receives them.

Is the integration with openHAB that is not working.

I will follow the information above and see if that helps :slight_smile:

I’ve checked all that as best I can :-





I have some demo items and demo sitemap I have been playing with.


Frame {
Switch item=SonOff-1

Switch SonOff-1 {mqtt=">[mosquitto:cmnd/SonOff-1/POWER:command:ON:1],>[mosquitto:cmnd/SonOff-1/POWER:command:OFF:$

I’m not seeing anything in the Mosquitto broker when I press the button:

Just stuff like this

Client mosqsub/4804-openHABian received PUBLISH (d0, q0, r0, m0, ‘/openhab/out/ImageURL/state’, … (34 bytes))
Client mosqsub/4804-openHABian received PUBLISH (d0, q0, r0, m0, ‘/openhab/out/ImageURL/state’, … (35 bytes))
Client mosqsub/4804-openHABian received PUBLISH (d0, q0, r0, m0, ‘/openhab/out/ImageURL/state’, … (34 bytes))
Client mosqsub/4804-openHABian received PUBLISH (d0, q0, r0, m0, ‘/openhab/out/ImageURL/state’, … (32 bytes))

Any advice where to go next?

First try is it looks like you are missing the closing bracket in your item definition unless that was a cut-and-paste error

Thanks, you are correct, I missed a couple of bits when I pasted it.

Any suggestions on troubleshooting?

Does this look correct?

bundle:list | grep openHAB
9 | Active | 80 | | openHAB LightwaveRf Binding
167 | Active | 90 | 2.1.0 | openHAB Core
168 | Active | 80 | 2.1.0 | openHAB Karaf Integration
170 | Resolved | 80 | 2.1.0 | openHAB Sound Support, Hosts: 112
171 | Active | 80 | 2.1.0 | openHAB Dashboard UI
184 | Active | 80 | 1.10.0 | openHAB MQTT Binding
188 | Active | 80 | 2.1.0 | openHAB 1.x Compatibility Layer
190 | Active | 80 | 2.1.0 | openHAB Cloud Connector Bundle
191 | Active | 80 | 1.10.0 | openHAB MQTT Transport Bundle
192 | Active | 80 | 1.10.0 | openHAB MQTT Persistence Bundle
193 | Resolved | 75 | 2.1.0 | openHAB Basic UI Fragment, Hosts: 179
194 | Active | 75 | 2.1.0 | openHAB Classic UI Fragment
198 | Resolved | 75 | 2.1.0 | openHAB Paper UI Theme Fragment, Hosts: 181

I have just started looking at logs, from Karaf:

22:26:03.540 [INFO ] [] - Received HTTP POST request at ‘items/SonOff’ for the unknown item ‘SonOff’.
22:26:03.816 [INFO ] [] - Received HTTP POST request at ‘items/SonOff’ for the unknown item ‘SonOff’.
22:26:04.064 [INFO ] [] - Received HTTP POST request at ‘items/SonOff’ for the unknown item ‘SonOff’.
22:26:04.321 [INFO ] [] - Received HTTP POST request at ‘items/SonOff’ for the unknown item ‘SonOff’.
22:26:04.573 [INFO ] [] - Received HTTP POST request at ‘items/SonOff’ for the unknown item ‘SonOff’.

I can’t see an item called Sonoff.

My only item is:

Switch SonOff-1 {mqtt=">[mosquitto:cmnd/SonOff-1/POWER:command:ON:1],>[mosquitto:cmnd/SonOff-1/POWER:command:OFF:$]"}

I believe hyphens in names have a special significance within openhab UI’s - they are used to select icons e.g. light-on, light-off etc.
For that reason you should avoid hyphens in Item names.
Use an underscore if you wish

1 Like


I will give that a try :slight_smile:

Thats worked!!

Sometimes its the simplest of things…

Now I just need to understand how to update the OpenHAB web interface if i manually switch the unit on/off from the on-board switch?

My understanding (I’m just coming up the learning curve myself) is that you’ll want to configure an incoming subscribe for your item using the ‘<’ in your item definition.

1 Like

No trailing slash on the MQTT URL, as it’s not HTTP.

Hey all. Sorry to pick this thread up with the same problem: I just can´t get openhab2 on my old Raspi B to cause any effect on the mqtt topic. Using Putty Mosquitto works just fine, so does MQTT.fx.
I did a fresh install of openhab, installed the MQTT binding from the binding menu inside Paper UI.

Here is the contents of my mqtt.cfg:

And eventbus

I tried to have a switch on a demo.sitemap
sitemap default label=“My first sitemap”
Switch item=myswitch label=“Light”


the switch is: myswitch.item
Swtich myswitch {mqtt=">[mosquitto:/test/hello:command:ON:1],>[mosquitto:/test/hello:command:OFF:0]"}

Bear with me. I had to figure out what it actually means when someone write “We just create a switch item”. I have little to no knowledge about what I´m acutally doing :wink:

your openhab.log should be giving you an error about the misspelled Swtich
If this was a copy/paste error… check the contents of /var/lib/openhab2/config/org/openhab/mqtt.config

Ps: You don’t really need the mqtt-eventbus integration. You could comment out all the settings there.

Yep. Meanwhile I´ve found this typo too and changed around the variables. But I still have a problem while looking at the openhab log. Can´t get my head around this simple syntax. The log states:

Cannot retrieve item ‘cmd1’ for widget org.eclipse.smarthome.model.sitemap.Switch

Here is the items file:
Switch cmd1 {mqtt=">[mosquitto:/test/hello:command:ON:1],>[mosquitto:/test/hello:command:OFF:0]"}

and the sitemap:
sitemap test label=“test sitemap”
Frame label=“Stuff”{
Switch item=cmd1 label=“LightSW”


When I try to use the swtich that shows up in the Basic UI, the log says:
Received HTTP POST request at ‘items/cmd1’ for the unknown item ‘cmd1’

I think mqtt binding is actually working, but there is something wrong in my syntax that is just very simple. I´ve read through a lot of examples and pages, but can´t figure it out.

Damn … got it now! It was a simple “s” that was missing from the .items. It was named .item. Stupid me!

1 Like