EasyESP Mosquitto bidirectional

Good evening everybody,
I finally have managed to flash a Sonoff-touch (ESP8285) with EasyESP. I can connect to Mosquitto. After hours of googling I was able to control the switch through the openHAB user interface. However, the other way around is not working. When I press the button on the Sonoff-touch, the switch in the user interface is not updated. I know that my .items file is wrong as this “>” seems to define outbound messages and “<” seems to define inbound messages.
So this is my .items file:

Switch sTest { mqtt=">[mosquitto:/sonoff_hallway/gpio/12:command:ON:1],>[mosquitto:/sonoff_hallway/gpio/12:command:OFF:0]" }

Here is the config screenshot from the Sonoff device
**Edited... I don´t know how to upload pictures...

I have studied the docs but unfortunately I am not experienced enough to find a solution.
Has this something to do with MQTT-eventbus?
I am stuck here…


You need to add incoming (i.e. “<”) mqtt configs to that Item or some other Item to receive incoming messages.

If you add them to the same Item make sure you use “state” and not “command” or else you might end up in an infinite loop.

Also, it is far easier to manage if your device publishes to some other topic than the one openHAB publishes to. Otherwise you need to figure out how to filter out the messages OH sent from those your ESP8285 sent.

Thank you,
I tried this:

Switch sTest { mqtt=">[mosquitto:/sonoff_hallway/gpio/12:command:ON:1],>[mosquitto:/sonoff_hallway/gpio/12:command:OFF:0],<[mosquitto:/sonoff_hallway/gpio/12:state:ON:1],<[mosquitto:/sonoff_hallway/gpio/12:state:OFF:0]" }

Doesn´t work but you are right with the infinite loop… This thing was going crazy! :joy:

This sounds more complicated than your first suggestion, swapping the arrows and changing “command” for “state”. All my MQTT knowledge, which is close to zero, is from HowTo´s, Wiki´s and Docs. But it is by far not enough to implement your second suggestion.

I didn’t say to just swap the arrows around and change command to state. The format for incoming messages is different. When I said “add the incoming mqtt configs” I meant for you to go back to the readme to see the proper format.

Actually, it will be far far far less complex than trying to deal with all messages going to the same topic.

Hip hip hurray, I got it working.

here is what I came up with:

Switch sTest { mqtt=">[mosquitto:/sonoff_hallway/gpio/12:command:ON:1],>[mosquitto:/sonoff_hallway/gpio/12:command:OFF:0],<[mosquitto:/sonoff_hallway/button/state:state:MAP(onoff.map)]" }

In the folder “transform” I created a file “onoff.map”


This post helped me with the transformation thing

Thank you @rlkoshak for pointing me into the right direction!

P.S. I had an MQTT message reader running that showed me that the topic is /sonoff_hallway/button/state instead of /sonoff_hallway/gpio/12