[SOLVED] MQTT binding + Homie






Or in mqtt.config:


Try this first:

Switch LED {mqtt=">[mosquitto:myhouse/office/light:command:ON:1],>[mosquitto:myhouse/office/light:command:OFF:0]"}

You should see something on mqtt fx. The broker name was wrong in the item
Your broker name is mosquitto
The clientId openhabmqtt is to identify the client to the broker. We don’t use that in the items

If that works then:

Switch LED {mqtt=">[openhabmqtt:homie/a020a6124dfd/light/power/set:command:ON:true], >[openhabmqtt:homie/a020a6124dfd/light/power/set:command:OFF:false], <[openhabmqtt:homie/a020a6124dfd/light/power:state:MAP(homie.map)]"}


Switch LED {mqtt=">[openhabmqtt:homie/a020a6124dfd/light/on/set:command:ON:true], >[openhabmqtt:homie/a020a6124dfd/light/on/set:command:OFF:false], <[openhabmqtt:homie/a020a6124dfd/light/on:state:MAP(homie.map)]"}

Device Id typo corrected!
Should trigger your homie device
PS: Are you using the wemos D1, if you do I suggest that you change to tasmota firmware


I can now see traffic in MQTT.fx from switching that switch from within openhab basicUI.

OK, replacing ‘openhabmqtt’ with ‘mosquitto’ in the above code now works!

Switch LED {mqtt=">[mosquitto:homie/a020a6124dfd/light/on/set:command:ON:true], >[mosquitto:homie/a020a6124dfd/light/on/set:command:OFF:false], <[mosquitto:homie/a020a6124dfd/light/on:state:MAP(homie.map)]"}

This is great! Thanks for your help :+1:

Now I need to try to and implement this into a more complex project (TFT touchscreen for door access control) :sweat:

I am glad we got it working. I didn’t know homie at all. So I had to look it the docs.
My advice is the following: read the docs.

All we have done today was in the docs…
Mqtt binding doc for the syntax of the item:


Homie docs for the topic

There is no magic here

It’s a great feeling when we get our first devices to work
I now 3 years later have more than 800 items in my OH and countless rules and bindings…

Don’t try to bite more than you can chew. Implement things bit by bit. Test, test and retest. Read the docs and read them again and when you finished read them again.

Enjoy and good luck

PS, please mark the thread as solved

When learning mqtt, this tool is very handsome:

Connect to your mqtt server ans subscribe to # (this is: grab all)
It’s very simple to identify new topics and the needed path, you can even submit messages to mqtt to see, if you got the right information.

I have tried both mqtt-spy and MQTT.fx and can monitor the traffic. I’ve now learned how to use openhab to transmit over mqtt to my nodeMCU.

But, even with monitoring the messages using these 2 tools, I can’t seem to get openhab to respond to mqtt messages. I’ve read the MQTT binding document and the homie convention document, but to a novice like me they don’t make for easy reading. I need to see examples in conjunction with these documents, the ones I have seen don’t seem to work for me.

For instance:

String LEDs "MQTT Switch 1 Status [%s]" {mqtt="<[mosquitto:homie/a020a6124dfd/light/on:state:default]"}

in my items file.

When I toggle the light on/off, LEDs (status text item) does not change.

What do you see on mqtt-spy?

Each time I toggle the light I get:

homie/a020a6124dfd/light/on/set   -->   true
homie/a020a6124dfd/light/on        -->   true


homie/a020a6124dfd/light/on/set   -->   false
homie/a020a6124dfd/light/on        -->   false

You need to tell OH to change “true” into “ON” and “false” into “OFF”
You can do that with a MAP transformation
Create a homie.map file in your conf/transform folder with the following content:


and chage your item to:

String LEDs "MQTT Switch 1 Status [%s]" {mqtt="<[mosquitto:homie/a020a6124dfd/light/on:state:MAP(homie.map)]"}

Good luck

Thanks again!

I tried this but nothing changed now I see the following:

It should work
What files are in your conf/transform folder?
Try putting spaces after { and before } in the item binding

In my transform folder i have:


I tried spaces after { and before } but still the same.

Is the MAP transform installed?

Now it is :blush:

And that has fixed it!

Thanks again :wink: