Openhab not publishing to MQTT - Please help!

Hello all, I cannot find out what I am doing wrong, although I’m sure it is just a dumb mistake I’ve made somewhere, so any help is massively appreciated!

This is what I have put in the openhab.cfg file under MQTT Transport:

#mqtt:mosquitto.url=tcp://192.168.1.68:1833
(I have left the rest unchanged as they are optional)

Here is my items file:

LEDswitch [mqtt='{mqtt=">[mosquitto:/LEDstatus:command:ON:1],>[mosquitto:/LEDstatus:command:OFF:0]"}

and my sitemap:

sitemap label="Test"
{
Frame label="MQTT"
{
Switch item=LEDswitch label="LED Switch"
}
}

When I hit the switch in openhab nothing happens. I know the LED (which is attached to esp8266) is subscribed to the LEDstatus topic and when 1 or 0 is received on topic it goes on or off, so I am certain the problem here is something I’ve done in OpenHab, but I can’t figure it out :frowning:

Hi Craig,

first thing that catches my eye is the # in front of the mosquitto.url. This is uncommenting the configuration string, so it would not be interpreted by OH. Next thing is the surplus square bracket in your items definition right after LEDswitch.

Regards,
Marcel

Hi Marcel,

Thanks so much for the reply. I’m a bit confused though. In my config file every line has ‘#’ in front of it. Do I need to go through my config file and remove them? Seems odd, or am I missing something?

I’ve attached an image of my MQTT config file if that helps.

Thanks,
Craig

Hi Craig,

the # just states that everything following in this line is just a comment. So you would at least need to remove the # from the lines where you are providing config values specific to your environment. I.e. at least for the mqtt:mosquitto.url=… line you would need to remove the #.

Regards,
Marcel

Thanks again for the reply.

I have removed the # for the mqtt line, am I right in assuming all the others aren’t needed to be remove unless I am specifically using on of those functions? So the optional ones can stay as they are?

I changed the square bracket (thanks for spotting it). Looks like I mean to do a ‘{’ instead.

All uploaded now, but still nothing comes through to the MQTT server…

Do I need to do anything with rules? Or am I still missing something in my code? (see attached for screenprint of my items and config file in one pic).

Again, any help is really appreciated!

Hi Craig,

in the items file you are referencing “mybroker” as the MQTT server/broker, but in the config file you are defining your mqtt broker as “mosquitto”. They should have the same name, I suppose.

Regards,
Marcel

Thanks for the response, think I’ve solved it! Looks like the capital letters had thrown something off. Put everything in lower case (LEDstatus) and it all works.

1 Like