Espeasy Openhab MQTT Issue

Good Evening Everyone

Just flashed a sonoff basic with espeasy and have got it running through mqtt on my openhab server.
I can switch the device on with the openhab app and also use gpio0 on the device. what im struggling with is having openhab read mqtt to change the state of the device when i use the gpio button. so i know if it is currently on or off.

Switch Sonoff1 "Rhys Lamp" <lightbulb> [ "Switchable" ] {mqtt=">[broker:/Sonoff_1/gpio/12:command:ON:1],>[broker:/Sonoff_1/gpio/12:command:OFF:0]"}
Switch Sonoff2 "Bedroom Light" <lightbulb> [ "Switchable" ] {mqtt=">[broker:/Sonoff_2/gpio/12:command:ON:1],>[broker:/Sonoff_2/gpio/12:command:OFF:0]"}

I Have tried a few incoming lines and non have worked so the code above just includes the outgoing mqtt code.

This is the code im using on the espeasy rules secton.

on LightSwitch#Switch do
if [LightState#Switch]=0
gpio,12,1
else
gpio,12,0
endif
endon


And this is how my devices are set up.

Can anyone please advice thank you.

Hi,

Please find below my working setup; in your case you have subscribe to mqtt topic like […]/LightState/Switch for gpio12, task 2, and translate mqtt payload with map transformation file

Switch LG_Sallon_Celling "Saloon Celling Lamp" (gEE226,gPomSalon,gLights) ["Switcha
ble"] {mqtt=">[wrt:easy/226/gpio/12:command:ON:1],>[wrt:easy/226/gpio/12:command:OF
F:0], <[wrt:easy/226/status/relay:state:MAP(onoff.map)]"}

Related onoff.map file:

1=ON
0=OFF

Hope this helps to solve your problem.

2 Likes

Thank you very much for the working config code, openHAB is now reporting the state of the relay. Working like a dream. Thanks again

Could you mark the thread as solved, please?