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?
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?
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.