[SOLVED] ESPEasy Mega MQTT to control relay issue

Hello, I am very inexperienced with openhab and have an issue with the MQTT binding.

I want to set up a wireless relay switch using an ESP-01 module and control it from openhab using my RaspberryPi 4.
So far I’ve flashed my ESP-01 module with ESP Easy mega, configured it to a static ip and set up a controller for it, which is my RaspberryPi. I can turn the relay on/off with the Http commands [relay-ip]/control?cmd=GPIO,0,1 or GPIO,0,0 . That turns my relay on or off as expected.
But in my controller, when I set up my MQTT binding I can reliably send messages to Openhab via ESP Easy’s “Controller publish” topic, by setting this topic the same as openhabs “MQTT state topic”. Using MQTTLens, I can see that my relay DOES send a 0 or 1 to Openhab, and the item switch in Basic UI changes respectively.
However, I can’t control the relay from openhab. I’ve configured the relay to be a switch, and using Openhab’s “MQTT command topic”, my MQTTLens does display that I should be sending the relay a 0 or 1. The relay does not change state. Retain message is ON.
So far I haven’t found a post that has the same issue, and am quite lost.
What is clear :

  • Im definitely sending Openhab the state of the relay, with the switch turning on/off in basic UI
  • Im NOT able to conrol the relay via openhab, but seemingly am sending the relay 1’s or 0’s

Could it be that I should instead somehow be sending it a command looking more like “GPIO,0,1” or “GPIO,0,0”? If so, how do I change the message I send to the relay?

Thanks in advance

I’m pretty sure that your command topic is wrong.

That might be it. In the screenshot the topic is currently set to the switch device in ESP Easy. Using these 3 parameters (I think thats what you call them) -

  • System name - relay
  • Device name - switch
  • Device value - State

Do you have any idea what it should be set to instead or where I can look for it?

I’m not familiar with ESPeasy (nor ESPeasy Mega). Maybe it’s cmd or something similar (instead of state).

So the full topic maybe would be /home/esp01/switch/cmd

In fact, ESPeasy is not as easy as promised by the name. In the wiki I get a command reference, but there is only abstract information, no example…

Yes, I also found this to be true. Seems like /cmd is the way to go.
As far as I can tell, openhab should be sending an actual command to /cmd (which does stand for command in this case. )
When i set the openhab mqqt format to “GPIO,0,%s” (which outputs the command/message “GPIO,0,1” or “GPIO,0,0” in MQTTLens), the whole thing desynchronises and the buttons in Basic UI stop updating according to the state of the relay.
Any idea about what I’m doing wrong? Did I maybe somehow change how openhab registers the input to the previously mentioned format?

I have to quote myself… :stuck_out_tongue_winking_eye:

I have no idea in how to solve this “input format is different to output format”.

Maybe the solution is to implement an outgoing transformation pattern.
I’m using Tasmota, which doesn’t provide as much possibilities as ESPeasy, but is also less complex.

1 Like

This is how I control relays in ESPEasy:

Note the custom On/Off values.

My on/off values are also 0/1. Could your command topic /GPIO/0/ be the key factor in controlling the relay itself? Could you maybe show what topic your ESP Easy relay is subscribed to?

My example is for turning an LED on and off, but it works the same way for a relay:

Switch LED_Red (gRestore) { channel="mqtt:topic:esp8266two:gpio0" }

Relay example:

Switch Relay <switch> (gRestore) { channel="mqtt:topic:esp8266two:gpio4" }

BTW, you are configuring a relay as a switch input, that is wrong. A relay is an output, you don’t need to configure anything in ESPEasy: just create an mqtt channel and configure your item with that channel and put the switch on your sitemap.

Huge and sincere thanks to you, I was able to get it to work and am able to control it via openhab.
Just 1 more question about the item syntax

Why is there no “/” between “gpio” and “4”? When there is a “/” in both my openhab mqtt topic and yours aswell?
Thanks again,

That’s just a channel name.