NEWBIE MQTT Config Help Needed

Suggestion, I/we could walk you through the setup of one of your sonoff switches, that way you should be able to do the others.
Please state which way you prefer, setup via PaperUi or via files?
Please show a screenshot showing the mqtt page of one sonoff switch.

P.S. Sorry for the short and abrupt answer earlier, I had to an oncoming appointment.

I’d greatly appreciate the help @opus.

Based on all the reading I’ve done the files option would be the better way as it will give me the most control, not so?

Both give you the same control! Take your pick, post the screenshot and I’ll write you through later tonight.

Let’s go with files.

I’ll probably try to replicate the process afterwards in PaperUI for another one of the switches just to see if/how it will work.

Here’s the screenshot:

Apparently I’m at my daily limit for replies as a new user but I’ll follow along any instructions given later tonight.

My guess is the first thing you are missing and not understand is the thing that represents the broker connection. It needs to be created as a bridge and all things representing the items should connect to it.
As you have already installed the embedded broker you should use it. I haven’t used it, so my example migth have a problem on that point. You need to set your correct IP for the host of this broker ( since it is the embedded one, the IP of the system your openhab instance is running on). The name “myUnsecureBroker” can be set differently!
The sonoff is represented by “mything” ( again you can set an own name). The device has two channels ( a switch called lamp and a string called Version).
Since you configured your sonoff non-standard, I am not sure on the state- and commandTopics, the “/Lights” might not be needed.

 Bridge  mqtt:broker:myUnsecureBroker [ host="", secure=false ] {

        Thing topic mything {
         Type switch : lamp "Switch" [ stateTopic="stat/Lights/TVLights1/POWER", commandTopic="cmnd/Lights/TVLights1/POWER" , on="ON", off="OFF" ]
         Type string : Version [stateTopic="stat/Lights/TVLights/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]

Save this in a .things file in the things directory, you need to restart openhab ( that is a known bug, already solved in the snapshot version).

Use PaperUI to see the correct channel definition which is needed in the items file ( within the { } after “channel=”. You can copy the syntax on PaperUI.

Let’s see how far you are getting with this.

??? I hope you did not miss understand me. Your question could be answered by anybody at any time, however I had to finish another task before writing back to you.

[Edit:] Missed the word “Bridge” in the .thing file example!!

i recommend Node-red , i am also a noob i was not able to understand MQTT till I have seen it work with Node red, also you will find tons of benefits, i still use OH as my Hub, but node-red give me a powerful rule engine, that can perform complex tasks on is own, for example, i use it to send my IOS notifications

i am a big fan of node red , i think its the best way for non-programmers to get some real work done

@opus I have the bridge up and running, at least that’s my understanding from the MQTTfx readouts when I toggle the switch, both manually and via the Sonoff WebUI - see screenshot below:

Based on the MQTTfx output, I’m thinking that I need to adjust the string line of the code to

Type string : Version [stateTopic="stat/Lights/TVLights/RESULT", transformationPattern="JSONPATH:$.StatusFWR.Version"]

Would that be correct?

The next part that has me stumped is defining the item itself. Based on further reading I’ve put the following as the item:

Switch Test_LED "LED Test" <wallswitch> {channel="mqtt<systemBroker:embedded-mqtt-broker:mything:lamp"}

But it’s yielding this error in the log:

Is the next step go to PaperUI and set up the channel?

In order to get the version info you need to send the …Status2 and not …/Result!
Your syntax for the item is again like version1 and therefor false.
Go into PaperUI and expand the thing representing this sonoff switch, under the channel the correct and only syntax is shown which you need to paste in the curly brackets behind “channel=”.

Screenshot from my system:

You see the three channels ( 2 switches!), underneath the bold type the channel is printed which can easily copied by the symbol behind it.
Paste that into one of your items like
The error shown points to the sonoff.items file containing “mqtt<systembroker” , the “<” is in question.
Please post the contents of that file.

Additionally, you did have the embedded broker with your first post. Only if the broker thing (I named it “myUnsecureBroker”) is online we are one step further!

I found a failure in my posted example (missed the word “Bridge”, already edited). When saving with this change a Restart is required.

Here’s the corresponding screenshot from my system:

I’ve changed the code back to /STATUS2, and copied this (mqtt:topic:embedded-mqtt-broker:mything:lamp) and put it into the item file.

Switch Test_LED "LED Test" <wallswitch> {channel="mqtt:topic:embedded-mqtt-broker:mything:lamp"}

I found a failure in my posted example (missed the word “Bridge”, already edited). When saving with this change a Restart is required.

I picked up on this error and made the necessary adjustment but I actually didn’t restart the OpenHAB service afterwards. Will restart now.

Looking good so far, PaperUI shows the Thing and shows that the channels are connnected to items (the dot is filled).
Is your broker Thing online as well?

Is your broker Thing online as well?

Yes. See below:

Then the final question: Can you switch the sonoff from a GUI (created a sitemap yet?) or from PaperUI-Control?

From PaperUI-Control I have three entries for the Generic MQTT Thing:

But when I manipulate either of the toggles there’s no change in the sonoff module status on the sonoff UI.

This is the output of the log:
2019-02-05 13:57:19.979 [ome.event.ItemCommandEvent] - Item ‘Test_LED’ received command ON

2019-02-05 13:57:20.017 [nt.ItemStatePredictedEvent] - Test_LED predicted to become ON

2019-02-05 13:57:20.030 [vent.ItemStateChangedEvent] - Test_LED changed from UNDEF to ON

2019-02-05 13:57:37.895 [ome.event.ItemCommandEvent] - Item ‘Test_LED’ received command OFF

2019-02-05 13:57:37.916 [nt.ItemStatePredictedEvent] - Test_LED predicted to become OFF

2019-02-05 13:57:37.925 [vent.ItemStateChangedEvent] - Test_LED changed from ON to OFF

2019-02-05 13:57:51.393 [ome.event.ItemCommandEvent] - Item ‘mqtt_topic_embedded_mqtt_broker_mything_lamp’ received command ON

2019-02-05 13:57:51.403 [nt.ItemStatePredictedEvent] - mqtt_topic_embedded_mqtt_broker_mything_lamp predicted to become ON

2019-02-05 13:57:51.416 [vent.ItemStateChangedEvent] - mqtt_topic_embedded_mqtt_broker_mything_lamp changed from UNDEF to ON

2019-02-05 13:57:57.086 [ome.event.ItemCommandEvent] - Item ‘mqtt_topic_embedded_mqtt_broker_mything_lamp’ received command OFF

2019-02-05 13:57:57.097 [nt.ItemStatePredictedEvent] - mqtt_topic_embedded_mqtt_broker_mything_lamp predicted to become OFF

2019-02-05 13:57:57.110 [vent.ItemStateChangedEvent] - mqtt_topic_embedded_mqtt_broker_mything_lamp changed from ON to OFF

Then there is something wrong in the .things file!
Please post what you actually have. Could you make&post screenshots of the MQTT messages sent by openhab when switching either switch?

Do you have the simple mode ON? That way each channel is linked with an automatically created item. That would explain the two switches!

Here’s the .things file:

Do you have simple mode ON?

Yes. Should I take it off?

Could you make&post screenshots of the MQTT messages sent by openhab when switching either switch?

Would this be from MQTTfx or the log?

I find this highly confusing. If everything is setup via textual files, simple mode should be off. Otherwise it will create invisible items for every Thing Channel you add in your text file. And I do not understand why text files and UI is mixed here.

You can perfectly setup everything in GUI first, test if it works and still convert it back to text files if you for whatever reason prefer those.


There’s so much information out there I have been trying to make sense of that I have ended up with a mix of text based and GUI-based set up/configuration. Clearly it has made things more complicated than anything else.

I knew you would be picking on the textual file setup. My reasoning was: User seemed lost in between, so I let him decide which way!
concerning the “Simple Mode”, so far I’m guessing it is on, I would and will suggestion switching it OFF as well!

Yes, that MQTTfy output will do.

Please change to commandTopic: “Lights/TVLight1/POWER”.
We will cover the stateTopic later.