Toggling nodeMCU built in LED with ESP Easy switch

I’m getting started with mqtt, and using version 2.4 (I’m flooded of 1.x docs) I’m trying to get the LED of a nodeMCU been toggled from a Switch.
I tried using mosquitto broker and kind of works but then I see openhab 2.4 comes with it’s own so I removed mosquitto and installed that one instead, seems to behave equally.

I have this switch:
Switch nodeMCULed { channel=“mqtt:topic:localBroker:mything:switchChannel” }

I have this things:
Bridge mqtt:broker:localBroker [ host=“10.0.1.203”, secure=false ]
{
Thing topic mything “My Thing” {
Channels:
Type switch : switchChannel “Switch 00” [ stateTopic="/dor_sur/sw0/Switch", transformPattern=“MAP(binary.map)”, transformationPatternOut=“MAP(binary.map)”, commandTopic="/dor_sur/cmd", formatBeforePublish=“gpio,2,%s” ]
}
}

my device name is dor_sur, it has 1 sw0 switch, which is the gpio 2 state

the binary map is:
key=value
1=ON
0=OFF
ON=1
OFF=0
=default

I have two main issues:
1st it works when openhab starts, then if I change something in the things file and save it, I get in the log that the file changes, that the thing goes to OFFLINE and then ONLINE again, but then it does not receives updates from mqtt and it does not send (publishes) changes when changing the switch, I might need to enable some log? (log:set DEBUG …?) but I don’t know what logger to use. It starts working again after “systemctl restart openhab2.service”
2nd The switching is not working ok, it is, e.g. off, then I click the switch and it goes on but led keeps off, then click again and led goes on, but switch goes off, etc.
The payload of the subscription is 0 means off, 1 means on, this is inversed in the ESP Easy as the led is on when pin is low (0) and led is off when pin is high (1), so sending mqtt message gpio,2,0 turns leds on, and gpio,2,1 turns led off.

I could post openhab log in a few hours, but there are only blue and white lines, no errors or warnings.

Thanks.

I think this is a known bug that has been fixed in the 2.5 Milestone 1 release.

Add the state topic so the device sends feedback.

Then look in events.log and see what states your Item is going through.

you mean this one https://github.com/openhab/openhab2-addons/issues/4393?

Seems to be the issue, could they add this known bug in the docs? There is a troubleshooting section with no mention to this.

There is a link at the bottom of the docs page that takes you straight to the page where you can edit the page and submit a PR.

Typically bugs like this don’t get put into the docs as they are transitory. This one only remained a bug for about a week before it was fixed.

Ok. 1 fixed by snapshot of 2.5

Number 2 still no go.
My thing here has feedback, it is 0 for off and 1 for on. If I change the esp easy by sending the mqtt message from another publisher the feedback updates properly on the switch in oh.
What I need to publish in the payload for on is “Gpio,2,0” and for off is “Gpio,2,1”
What is this events.log file? Should be there somewhere or should I enable it?
I am puzzled. There is transformationPattern trabsformationPatternOut formatBeforePublish, what would be the best way to solve this?

It’s a file that lives in the same folder as openhab.log that lists all the events on your Items and Things. For apt installed OH on Linux its in /var/log/openhab.

It’s enabled by default.

Currently the MQTT binding does not support outgoing message trqansformations. And neither do Profiles.

If you need to transform your outgoing messages, you need to create a Rule and use the publishMQTT Action as documented here.

Create a proxy Switch, trigger the Rule on that switch, and send the appropriate command based on whether the switch received an ON or OFF command.

Still having issues with openHAB 2.5.0 Build #1512 if I do bundle:stop the mqtt and then start, it works again, but after saving mqtt file it stops working
No errors logged

I ended up using Paper UI for this, as #1 was still giving me issues.
For the 2.5 seems that transformationPatternOut is working and formatBeforePublish works too (why do you guys document stuff that does not work?)
The thing state is/dor_sur/sw0/Switch
on = 1, off = 0

command topic is/dor_sur/cmd
outgoing value transformation is map:binary.map
outgoing value format is gpio,2,%s

now, the map is applied after the transformation which does not make sense to me so my maps ended up being something like:
gpio,2,1=gpio,2,0
gpio,2,0=gpio,2,1

(if the map were applied before it would have been 1=0, 0=1)