MQTT issues

Try as I might no variation or posted example seems to get OpenHab2 to see and control a switch that is operated by MQTT and report its state from MQTT.

Here are my Items:

Number Watts_3 “Red Phase Watts [%s]” (Energy) { mqtt="<[mosquitto:emon/emontx3/power3:state:default]" }
Switch testSwitch “My Switch” [“Lighting”] { mqtt="<[mosquitto:/home/sonoff/living_room/1:command:ON:1],>[mosquitto:home/sonoff/living_room/1:command:OFF:0],<[mosquitto:home/sonoff/living_room/1/stat:state:MAP(onoff.map)]", autoupdate=“false” }
String testSwitch2 (Energy) { mqtt="<[mosquitto:/home/sonoff/living_room/1/stat:state:default]" }

and here are my Sitemap entries:

Text item= Watts_3
Switch item=testSwitch
Text item=testSwitch2

Watts_3 displays the current reading, testSwitch and testSwitch2 do not display anything useful and certainly not the current state or carry out any control. The Topic in MQTT works because ‘Home Assistant’ display the state and allows control whilst an MQTT monitor displays MQTT subscribes and publish but not from OpenHab.

What am I doing wrong?

Hi, @rjstott, it can be done! I struggled at first but got there in the end. I don’t know how to link directly to my post about it, but I think if you follow my username to other posts, you will find it.
I think you are close, but check the syntax of your mqtt statements, make sure that the “arrows” face the right way,
You’ll see the example which works for me in my post. Please ask if you have any more questions. Good luck!

I don’t know if it makes a difference or not but some of your mqtt statements differ, like in “testSwitch” and “testSwitch2” where you use mosquitto:/home and sometimes mosquitto:home. It shouldn’t have a leading / ?

Thanks to you both. It is a key element to know that it can work as this removes the most important variable. I now have the first item working and it does at last drive MQTT and the switch that is subscribed. The premature / was one of my attempts to get it working and I was probably unlucky setting it on the item that now works!! No initial / is required. The problem seems to have been the mapping function AND the <> (pub/sub) settings. The look up failed and nothing was sent to MQTT.

Now I can see it operating I will play with the testSwitch item and sitemap until it is persuaded to display the current state, which perversely it has done once and then gave up!!??

I think I am falling over this problem Strange String behaviour on ‘ON’ / ‘OFF’. There is a long discussion that is barely intelligible to mere mortals and a complete failure of anyone to add caveat into the MQTT binding description. I haven’t a clue how to do that so the warning here is to avoid strings that can be confused with binary conditions or as the OP discovered to add a space in front of the string.