[SOLVED] Switch not communicating via MQTT

Hello! I am new to openHAB but so far am quite excited about the possibilities! However, I have run into a bit of a problem which I cannot find a solution for. There are many threads which seem to address a similar issue but I just cannot find a working solution.

I have the following things in place

  • OpenHAB2 install on my Mac
  • Mosquitto install on my Mac
  • MQTT.fx running.
  • A Sonoff basic switch flashed with tasmota.

I can successfully control my sonoff/tasmota switch using the MQTT.fx program, by sending an “ON” or “OFF” command to: cmnd/sonoff/POWER

I have the following configuration files.

[File is default with the expeption of the following]
NB: the above detials are the same as set up in MQTT.fx which is working

sitemap home label=“SmartHome”
Frame label=“Demo”
Switch item=DEMOSW
Switch item=MQTTDEMO

[file is empty]

switch DEMOSW “Demo Switch”
Switch MQTTDEMO “MQTT Switch 1” {mqtt=">[broker:sonoff:command:ON:1],>[broker:sonoff:command:OFF:0]"}

but no matter what I seem to try in the home.items file, sonoff, cmnd/sonoff, cmnd/sonoff/POWER etc… the switch MQTTDEMO will not communicate with my sonoff.tasmota. I have been through thread after thread but cannot see what I am obviously missing. I am sure I am not the only one who has come across this. any help/guidance is appreciated!

Well… As is often the case, I figure out the solution after I have posted!

So incase anyone else is having the same problem, this is what I did to solve the problem

Firstly I uninstalled the MQTT action add-on

Then I realised that the main cause of my problem was with the casing on some of my definitions, mainly switch instead if Switch! - how annoying…

So all of my configuration with the exception of my home.things file remain the same but the home.things now looks like this.

Switch DEMOSW “Demo Switch”
Switch MQTTDEMO “MQTT Switch 1” {mqtt=">[broker:cmnd/sonoff/POWER:command::default],>[broker:cmnd/sonoff/POWER:command::default]"}

and works as expected.

I hope this helps at least someone!

ON ro OFF switch


status of tasmota relay



Switch MQTTDEMO “MQTT Switch 1” {mqtt=">[broker:cmnd/sonoff/POWER:command:*:default],<[broker:stat/sonoff/POWER:state:default]"}

Thanks mpampinos! the ON or OFF switch works for me. but, the getting the openhab switch to respond to the status of the relay is still beating me.


does not seem to work. I have seen various threads talking about mapping the response from the relay. I also get an error. NULL response received from topic if I operate the switch manually. so it seems that its working in part but not receive the correct message from the stat/ topic for some reason.

it works
restart openhab please, or refresh browser

Yes is does work! the problem I seem to be having is large packet loss between Network and Sponoff! Not sure if you have come across this in the past? feels like this is a new thread item.


A Follow up on this. The problem I was experiencing with packet loss was solved when I moved my OpenHAB installation from my Mac to a dedicated Raspberry Pi. - I do not know why these issues were present. but either way, for me at least having dedicated hardware solved the issue.