Item with inbound MQTT binding corrupts file

I have a simple items file setup, I have a switch item which i’d like to control via mqtt, however when configuring the switch item as soon as I hit the ‘<’ in the binding section the item below becomes corrupt. If I tag the binding the opposite way ‘>’, or remove the binding, all is fine.
Am I missing something obvious?

Here with the corrupt number item:

Group All
Group Office (All)

Switch Office_mainlight <switch> (office) {mqtt="<[mymosquitto:office/mainlight:command:ON:1]"}
Switch Office_sidelight <switch> (office)
Number office_temp <temperature>

And here with the binding removed it is fine:

Group All
Group Office (All)

Switch Office_mainlight <switch> (office)                                                    
Switch Office_sidelight <switch> (office)
Number office_temp <temperature>

You can’t just swap the > with a <. The format for the incoming MQTT is different from the outgoing MQTT.

See

http://docs.openhab.org/addons/bindings/mqtt1/readme.html#item-configuration-for-inbound-messages

1 Like

But for an incoming message should my item read?:

Switch Office_mainlight <switch> (office) {mqtt="<[mymosquitto:office/mainlight:command:ON:1]"}

However doing this seems to break the formatting of some of the items below, example all the autoformatting dissapears and the item doesn’t work.

OK, so looking closer that should work. Assuming your sender is publishing a 1 *with no leading or trailing white space or other characters.

I see nothing wrong with the line but if you load it into ESH Designer it should tell you what is wrong with that line. It might be a hidden character or something wrong from a line before.

So the line itself works and the item Switch Office_mainlight works over MQTT
however it throws out of action the item below it.
It doesn’t show the formatting very well if I dump the code in here so i’ve grabbed some screenshots instead to show what i’m experiencing.

I’ve not used eclipse, but i’ll download that and give it a try, see if that brings anything up.

Use codefences or the </> button:

code goes here

Could you clarify what you mean by “corrupt” and “throws out”? Are you referring to the code highlighting as in your screenshot or is the item Office_sidelight in fact missing from your system (check via remote console)

@ sihui, I did try that initially, however the embedded codefences were reformatting and not showing the issue correctly.

Tom, yes both the formatting/highlighting changes as shown on my screenshot, and also the item Office_sidelight becomes missing from the system.

No problem, sometimes software goes nuts …

What he meant is log into the console and execute:

openhab> smarthome:status Office_sidelight

Do you get an ON or OFF or does it say
Error: Item 'Office_sidelight' does not exist.

1 Like

Those gray rectangles give me pause. Did you just happen to have the cursor there or are they part of the file? If part of the file they indicate some hidden character and could absolutely be causing your problems.

1 Like

Thats just the cursor causing chaos, they’re not in the items file.

Im not sure how to do that, i’m running my Openhab setup on a headless PI and when I try remotely via SSH it doesn’t let me connect to the console, when I hookup my PI to a display the screen is blank (please bear with me as i’m relatively new to all of this)

I thought i’d cracked it by leaving a space after the Office_mainlight item, as the screenshot below shows - the formatting is all good, however when I copied the code into the code fences below, the formatting went funny again. Its got to be a way i’m typing the code in somehow!

Group All
Group Office (All)
Dimmer Office_mainlight <switch> (office){mqtt="<[mosquitto:home/light:command:$

Switch Office_sidelight <switch> (office)
Color Office_led <colorpicker> (office)
Number Office_temp <temperature>
Number  Office_id <party>


On top of this, I don’t think my MQTT binding is working either. Could OH not be seeing my mqtt binding which is causing the formatting issue too?

Im running OH 2.0.0-1, on a Pi 3 model B
Installed OH using the openhabian image.
Installed the MQTT binding via the paper UI ( Addons > Bindings > MQTT)
Installed Mosquitto via

sudo openhabian - config

and scrolled down to item 22| Optional Mosquitto and installed.

I setup my mqtt configuration file at

sudo nano /etc/openhab2/services/mqtt.cfg

And the lines I changed are

mosquitto.url=tcp://localhost:1883
mosquitto.clientID=openhab2

I checked that mosquitto is running - it is.
And i’m able to subscribe to a topic then publish to that topic from a different SSH window, but if i publish a ‘1’ or ‘0’ onto the topic home/light, I get nothing.

The reason the formatting got messed up when you pasted in the code is because you truncated your Dimmer Office_mainlight Item definition. My deleted post was all about that being your problem until I noticed that you have a full and what looks to be correct mqtt config on that Item in your screenshot.

Almost always when the formatting gets messed up in the Forum it is because of a missing or extra ' or ".

Do you have the MQTT Action installed along with the MQTT Binding? There was an error, and since you are running one full release early of a version of OH behind the current that bug almost certainly is there for your, where you may have to uninstall and reinstall the MQTT Action or else the MQTT Binding will not work.

You should be seeing log statements in openhab.log that OH has connected to the Broker when the Binding is working correctly.

Please see MQTT Binding (v1.11) Getting Started 101 for step by step instructions for setting up MQTT and make sure you followed all of those steps.

But to answer your main question, a broken MQTT binding config would not cause problems in your .items files. Only syntax errors in the .items file itself can do that.

You haven’t yet mentioned if you tried ESH Designer. If there is a syntax error it will point directly to it.

There is nothing obviously wrong with your .items file. Perhaps it would be worth while moving the lines over to a new file, one at a time. And retype them, don’t copy and paste. This will eliminate any hidden stray characters that may be hanging about. With what we know right now its a complete mystery.

1 Like

Thanks for your replies. Ive spent a few hours playing round with this today…
If I leave a space between each item type in the items file it all formats as desired, i’m not sure why It doesn’t work otherwise but this is a workable solution for me.

However I still don’t seem to have the MQTT binding working (sorry that this has been brought up so many times.

Ive gone as far as setting up a new SD card, with the openhabian image available as of today.
I followed your tutorial below to the latter,

Fresh openhabian install,
Setup Mosquitto, I opted not to enter a password and left the box blank*
Edited the file

/etc/openhab2/services/mqtt.cfg 

the only changes I made were

mosquitto.url=tcp://localhost:1883

I didnt edit the userID and password section * as I left this blank when setting up mosquitto, should this effect anything?

Used MQTT Lens from a remote computer to test the connection, both ways works fine.
I then went ahead and installed the MQTT binding via the paper UI
Created the single item as noted in the MQTT tutorial to test the connection.

Switch MQTT_Test "Testing..." { mqtt="<mosquitto:testing/mqtt/topic:state:default], >[broker:testing/mqtt/back-topic:command:*:default]" }

Using MQTT lens I publshed “On” to the topic testing/mqtt/topic

On the openhab log viewer I get nothing to indicate the items state has changed

2017-10-12 17:20:00.283 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.0.199:8080
2017-10-12 17:20:00.285 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.0.199:8443
2017-10-12 17:20:00.908 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-10-12 17:20:01.046 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-10-12 17:20:01.192 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2017-10-12 17:20:01.400 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-10-12 17:20:01.405 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

I have tried with and without MQTT action installed, It doesn’t seem to make a difference either way.

Any ideas?

Thanks for your help thus far

Switch MQTT_Test “Testing…” { mqtt=“<[mosquitto:testing/mqtt/topic:state:default], >[broker:testing/mqtt/back-topic:command:*:default]” }

You are missing the opening [ in your first MQTT binding config.

You are using mosquitto as your broker name for the first binding config and broker as your broker name for the second binding config. Based on your log you should be using mosquitto in both places.

Thats fixed it! Thanks for your help!