Help openHAB2 MQTT Mosquitto

Dear all,

I setup openHAB2 and Mosquitto on my Synology NAS.
Everything is working, I can Subscribe an Publish.
I have a ESP8266 with ESP Easy setup and a relay on gpio 4.
But I have some issue with the command to get openhab2,
to turn on/off a Relay. The switch is visible, but nothing happens
when I turn it on/off. My setup looks like this:


Frame label=“MQTT Test”{
Switch item=MQTTLED label=“LED”

Switch MQTTLED {mqtt=">[localbroker:/openhabdemo/gpio/4:command:ON:1],>[localbroker:/openhabdemo/gpio/4:command:OFF:0]"}

But when I try with putty with the command:
curl --silent,4,1
curl --silent,4,0
I can turn the relay on/off. How can I implement this command in demo.items
Or wich command do I need to use? I have not setup any “Device” on ESP Easy

kind regards,

That is probably your error.

You need to set up a Switch item and bind it to one of the gpio’s (in your case gpio 4), your MQTTLED Switch setup looks correct.

Thanks for your quick reply!
As you can see I setup the “Task” but steel no joy :cry:

I am lost…

You should setup at first on ESP EASY the MQTT Login, etc.

Those commands do not use MQTT, but http, so you should first check if your broker and your MQTT connection is working.
You will find a lot of hints for this in other threads …


I’m not sure if this is the main reason, but you’ve said you are using OpenHAB 2, and you have openhab.cfg as an example of your setup. In OpenHAB 2, you should set your MQTT parameters in MQTT.cfg (located in conf/services folder).

Best regards,

Good catch :slight_smile:

I do have MQTT.cfg setup, with:

My ESP Easy log display:

INIT : Booting Build nr:147
IP : Static IP :
WIFI : Connecting… 1
WIFI : Connected!
INIT : SPI not enabled
MQTT : Connected to broker
Subscribed to: /openhabdemo/#
INIT : Boot OK
INIT : Normal boot

I’m going insane, I really need help…I have been trying for days to get this working.
I have to admit, that I’m just a beginner to this :disappointed_relieved:

You should carefully read the docs, there is no “mqtt:” prefix in mqtt.cfg:

Try to see this

Its very easy to get a relay working in openhab2 with mqtt espeasy .

Just follow this video

In your items file your item should look like this(just replace the names of your device broker etc)

Switch MQTTLED "LED" (FF_Living,Lights) ["Switchable"] {mqtt=">[mosquitto:/BathroomLightSwitch/gpio/5:command:ON:1],>[mosquitto:/BathroomLightSwitch/gpio/5:command:OFF:0]"}

MQTTLED is would be the name you give the item in openhab , “led” is the name you see in sitemap , (groups it belongs to) . Bathroomlightswitch is the name of the esp and relay is on gpio5