[SOLVED] MQTT binding + Homie

I’m trying to use the Homie convention with the MQTT binding and am having trouble with the items file I think.
I’m using a nodeMCU with the LightOnOff example from the Homie library.

I have installed mosquitto to my raspberry pi which is also running openhab.

I have used MQTT.fx and have confirmed that openhab is connecting to mosquitto as a client by stopping the openhab service and monitoring the number of clients connected to mosquitto.

I have also seen the number of clients increase or decrease when removing power from the nodeMCU (and the serial monitor shows it is connecting to mosquitto).

Having seen all of this I’m (fairly) satisfied that openhab mqtt binding is working and the nodeMCU running the Homie example sketch is working. This leads me to believe that my problem is in the way I am writing the items file.

Here is my mqtt.cfg





And my items:

Switch LED {mqtt=">[openhabmqtt:devices/a002a6124dfd/light/on/state:ON:true],<[openhabmqtt:devices/a002a6124dfd/light/on/state:OFF:false],>[openhabmqtt:devices/a002a6124dfd/light/on/set:command:ON:true],>[openhabmqtt:devices/a002a6124dfd/light/on/set:command:OFF:false],"}

Have I declared the item correctly?

When you switch on the light from your nodeMCU, what topic is published from it?
Also you shouldn’t need mosquitto.retain=true unless you want to use the mqtt persistence service

Here is the sketch I loaded to the nodeMCU:

#include <Homie.h>

//const int PIN_RELAY = D5;
#define PIN_RELAY D5

HomieNode lightNode("light", "switch");

bool lightOnHandler(const HomieRange& range, const String& value) {
  if (value != "true" && value != "false") return false;

  bool on = (value == "true");
  digitalWrite(PIN_RELAY, on ? HIGH : LOW);
  Homie.getLogger() << "Light is " << (on ? "on" : "off") << endl;

  return true;

void setup() {
  Serial << endl << endl;
  digitalWrite(PIN_RELAY, LOW);

  Homie_setFirmware("awesome-relay", "1.0.0");



void loop() {

Sorry but, Not the answer to my question.

I was hoping you could see from that code what is being published, as I’m not sure :frowning:

Github says property topic.

Just had a quick look at the homie mqtt convention. Complicated!

But your item should be, I think:

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

In your transormation folder you will need to create a file called homie.map with the following content:


Thanks for looking. I tried what you suggested and unfortunately it hasn’t worked.

I’ve been bashing my head against this for around 5 hours now and am starting to think about looking at other solutions :confused:

Don’t you are close
You have mqtt.fx
Connect to your broker and subscribe to # to see all the traffic
What do your nodeMCU send when you turn it on?

The traffic looks like this:

homie/a020a6124dfd/$online   -    false

homie/a020a6124dfd/$homie   -   2.0.1

homie/a020a6124dfd/$name   -   awesome-relay

homie/a020a6124dfd/$mac   -    <MACADDRESS>

homie/a020a6124dfd/$localip  -

homie/a020a6124dfd/$nodes   -   light

homie/a020a6124dfd/$stats/$interval  -   0

homie/a020a6124dfd/$fw/name - awesome-relay

homie/a020a6124dfd/$fw?version  -  1.0.0

homie/a020a6124dfd/$fw/checksum   -   <A CHECKSUM NUMBER>

homie/a020a6124dfd/$implementation   -   esp8266

homie/a020a6124dfd/$implementation/config  -  {"wifi":{"ssid":"<MYSSID>"},"mqtt":{"host":"","port":1883,"auth":false},"name":"awesome-relay","ota":{"enabled":false}}

homie/a020a6124dfd/$implementation/version   -   2.0.0

homie/a020a6124dfd/$implementation/ota/enabled   -   false

homie/a020a6124dfd/light/$type   -   switch

homie/a020a6124dfd/light/$properties   -   on:settable

homie/a020a6124dfd/$online  -  true

homie/a020a6124dfd/$signal  -  88

Then it repeats stats/uptime and stats/signal

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

or if it doesn’t work:

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

Neither of those worked (I also captured and corrected a typo in my device id number)

Is there a way that I can send a mqtt command from openhab, just to prove that I can see that traffic on MQTT.fx ?

put the switch on a sitemap and turn it on and off

You can also try to publish to the topics above the value true or false to see if your homie device reacts

Sorry, that’s what I already have, and have been switching from my sitemap in the BasicUI.

I just need a basic mqtt message format that I can send using a switch item to see that traffic in MQTT.fx. This will prove the openhab MQTT binding is working correctly.

I don’t see any other traffic on MQTT.fx other than when I first connect my nodeMCU!

I’ve tried replacing my switch item with:

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

This is straight from the MQTT binding page from openhab website.

I have subscribed to myhouse/office in MQTT.fx and can confirm that I don’t see any traffic there when I switch it on and off in the Basic UI page.

This leads me to believe that I haven’t got the openhab mqtt binding working correctly.

I installed the mqtt binding in openhab through the paperUI (version 1.10.0)

Your mqtt binding is not working.
Can you show me the content of the mqtt.cfg in your conf/services folder, please?