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.