[SOLVED] Configure Light to work with wifi switch using esp32s

Hi all,

I am new to open hab and started my first project.

I am trying make twoway switch in openhab

I have ESP32 connected with relay which is subscribed to MQTT toppic (AM_LivingLight1_Channel)

i have created thing that is linked to an item AM_LivingLight1 which is a switch

when i turn on light from openhab UI it published “ON” on (AM_LivingLight1_Channel)
which is then received by ESP and turns on relay.

Its working fine, but i am having issue with by second switch which is a push button switch directly attached with ESP32s when i press it, it turns on/off light but the current status of light is not reflecting on my Openhab UI

since i turned light off using pushbutton it doesnot reflect on Openhab UI,
I tried publishing ON/OFF message from ESP to (AM_LivingLight1_Channel)
but no luck, please assist

Which binding version of the MQTT Binding do you use? I a can only help you with the newer 2x version.
But there you have the possibility to have separate state and command topic.
You would use two topics.
One would be the state topic which is the one the esp32 publishes too whenever it changes the relay state. Openhab listens to this topic as a State topic and also makes the item state dependent of it if you turn the auto update function to false.
The second topic is the command topic which is the one openhab publishes commands to and the esp32 subscribes to it to act accordingly.
It’s is important to have those two separate topics for state and command. For more information have a look here:

I hope this helped, Johannes

Thanks alot for quick response.
i was using similar Topic for both Openhab and esp to publish.

let me test this on my setup, will let u know.

Wooww Man you are awesome!!
it worked for me…!!

1 Like