Openhab 2 raspberry mqtt

Hi There. I am stuck

I have installed openhab 2 on a raspberry pi with openhabian. Everything is running fine. I also have Mosquitto MQTT installed.

I then added a sonoff wifi relay and its connected to Mosquitto MQTT.

When I publish a topic directly using terminal to the queue, my relay works perfectly. this is the command
mosquitto_pub -r -t /relay/newsonoff1 -m “0”

I then add a sitemap, and have an switch item setup using a itme file usiong this command
Switch Sonoff {mqtt="<[mosquitto:/relay/newsonoff1:state:MAP(],>[mosquitto:/relay/newsonoff1:command:ON:1],>[mosquitto:/relay/newsonoff1:command:OFF:0]"}

The switch appears in the Basic UI.
When I toggle the switch using the UI, it doesnt always publish the command to the queue.
When I listen to the topic in Mosquitto, it would work 4 times, and then it doesnt work for 10 times, then work 4 times again.

Can anybody please help me

I had s similar problem when I first used the Arduino IDE and some simple MQTT code and the respective libraries.
The problem was that the debounce time for the switch was not correct.

Since I switched to ESPEasy firmware I never had that problem again.
What firmware are you using on your Sonoff? Although I don’t use the recommended Tasmota firmware, I’m pretty sure that problem would not occur on that firmware …

Hi sihui

Thanks, will give it a try.