Hi @sihui
I got it working thanks so much for all your help it looks like it was a mix between having the wrong spelling and/or missing capital letters and possibly a poorly named map file. After I changed the name from relay.map to onoff.map it started working.
As far as ESP Easy and I think I’ve read this somewhere too but it seems you need the device that’s sending the MQTT status message as the first device on the ESP devices page.
So anyone out there having the same trouble syncing a physical switch with the Openhab software switch here is my working setup.
Here is my OH Item Don’t forget to set the IP to the IP of your ESP.
Switch Lamp1 "Living Room Lamp" <poweroutlet_us> {http=">[ON:POST:http://XXX.XXX.XXX.XX/control?cmd=GPIO,5,1:on] >[OFF:POST:http://XXX.XXX.XXX.XXX/control?cmd=GPIO,5,0:off]", mqtt="<[broker:ESP_377E2F/Relay/Switch:state:MAP(onoff.map)]" }
Here is my Sitemap nothing special here.
Frame label="SmartPlugs"{
Switch item=Lamp1
}
Here is my 1st device on the ESP Easy setup.
Here is my 2nd device on the ESP Easy setup.
And here are the rules I’m using on the ESP Easy firmware.
On SwitchIn#Switch=0 do
if [Relay#state]=1
GPIO,5,0
else
GPIO,5,1
endif
endon
Here is the MQTT Controllers setting on ESP Easy. (Again be sure to change the IP to your controller.)
And here is the mqtt.cfg I’m using on OpenHab. I only made one small change to the default generated at the install. (Be sure to change the IP to your MQTT server.)
broker.url=tcp://XXX.XXX.XXX.XXX:1883
I hope this will help anyone else looking to control something with a relay using a ESP 12 running ESP Easy and still have a Physical Switch option and have it show the correct state of the device in the OpenHab user interfaces.