[SOLVED] MQTT-Homie-Switch won't work

I have an MQTT-Device (ESP8266) with the following MQTT-States (under Homie-Convention):

homie/eg-bad-licht/$homie -> 3.0.1 (Retained)
homie/eg-bad-licht/$name -> EG - Bad - Licht (Retained)
homie/eg-bad-licht/$nodes -> light (Retained)
homie/eg-bad-licht/$state -> ready (Retained)
homie/eg-bad-licht/light/$name -> Light (Retained)
homie/eg-bad-licht/light/$properties -> power (Retained)
homie/eg-bad-licht/light/$type -> switch (Retained)
homie/eg-bad-licht/light/power -> ON 
homie/eg-bad-licht/light/power/$datatype -> enum (Retained)
homie/eg-bad-licht/light/power/$format -> ON,OFF (Retained)
homie/eg-bad-licht/light/power/$name -> Power (Retained)
homie/eg-bad-licht/light/power/$settable -> true (Retained)

In the Paper-UI the Thing will discover automatically and I can add it to the things. I have add the power-item as an switch:

Switch BadLampeSwitchLight “Bad - Lichtschalter:” (mqtt,Schalter,OrtBad) {channel=“mqtt:homie300:embedded-mqtt-broker:eg-bad-licht:light#power”}

The problem is, that when homie/eg-bad-licht/light/power change, nothing happens with the item. And when I change the item (toggle switch), nothing are published under homie/eg-bad-licht/light/power/set.

What is wrong?

Thanks for your help.

PS: My Openhab-Version is openHAB 2.5.0 Build #1485 under Debian.

1 Like

Have you looked up the channel ID (and the Log)? Because dashes are not allowed in channel ids if I recall correctly. I know that node/properties without dashes work perfectly. If dashes don’t work, that’s a bug that need to be reported.

1 Like

Thank for your fast replay and your help.

Same behavior without dashes:
Switch BadLampeSwitchLight "Bad - Lichtschalter:" <light> (mqtt,Schalter,OrtBad) {channel="mqtt:homie300:embedded-mqtt-broker:egbadlicht:light#power"}

In the openhab.log I see no warning or error releated to this topic.

When I edit the thing in the paper ui, the channel-type of power is string and not switch.

Ok that helps. A homie enum is usually mapped to a string. Multi state switches are not yet a Thing in openHAB.

What you want is either a type “boolean” or a type enum but with predefined states. See https://www.openhab.org/addons/bindings/mqtt.generic/#supported-things. For a raw button you need PRESSED,RELEASED.

1 Like

OK, now it works, with boolean and without dashes. With dashes it not work, this was the reason, why i have change to enum.
Can you open the issue with dashes?

Thanks for your help.

The issue exists at

1 Like

So if I understand correctly, so in Adduino terms you cant use HomieNode type switch with Openhab currently? What type should be used?

Let me explain my problem a bit more. I have homie 3.0.1 running and trying to get a switch working in OH 2.4. I have this in my Arduino:

HomieNode doorbellNode("doorbell", "switch", "switch");
doorbellNode.advertise("pressed").setDatatype("enum").setRetained(false).setFormat("PRESSED,RELEASED").settable(boorbellPressedHandler);
doorbellNode.advertise("onoff").setDatatype("enum").setRetained(false).setFormat("PRESSED,RELEASED").settable(boorbellPressedHandler);
doorbellNode.setProperty("pressed").send("RELEASED");
doorbellNode.setProperty("onoff").send("PRESSED");

This is what i’ve come up with, with my interpertation of docs and examples. However this generates two dummy channels in the Homie MQTT thing. They are not of type switch. Any idea what I could be doing wrong here?

It must be a property of type boolean in oh2.4 to become a switch. With oh 2.5 it can also be an enum.

I use boolean and it works. But it not work with the autodedected device, for that a bug is open. When you add the device manualy, it works.

PS: I use an NodeMCU with https://github.com/homieiot/homie-esp8266/tree/develop-v3
With this Device you will have WLAN included.

Thanks Manuel, do you have the github issue for this autodiscover bug for the boolean/switch?

I use an Wemos D1 mini china clone. Works perfectly.

Hi I see you guys say that in OH 2.5 you can use an ENUM for MQTT discovered swtiches but I’m not able to get this to work. I’ve used the format to set the enum options as on:off and ON:OFF etc. no matter what it detects as a string type. Any suggestions or is this still not possible and requires a boolean?

The OpenHAB Homie implementation use true/false for switch devices - unless something changed recently.