[SOLVED] I Have A Problem About MQTT And Sonoff Th But What Is It I Don't Know

I installed Openhab on Pi3.
I installed Mosquitto on first installation setup secreen but There is nothing in mqtt.cfg.
After that mqtt binding (2.4) and Embedded mqtt broker (2.4) installed on paper ui. but there is nothing in mqtt.cfg again.
I don’t have different device for mqtt. So openhab and mqtt ips are same. There is nothing in my inbox. I added manually Mqtt Broker. Is it normal?

I am trying add Sonoff Th with am2301. And I added but It is’not seen right;


I haven’t done anything other than adding channels in Paper ui.
Where am I wrong? What do I not do now?

Welcome to the openHAB Forum :wave:

I hope that was not your complete question!

1 Like

Thank you for your nice wishes.
I’m new to the forum and I tried to understand the system. I’m sorry about that.
Message fixed. :slight_smile:

You only need one of those brokers, either Mosquitto or embedded (which is actually moquette)

Read MQTT documentation and the subpage for “MQTT Things and Channels Binding”. If you have understood that process and you do have further questions don’t hesitate search in the forum (this has been asked and answered several times) or ask again.

Dear Opus,

I read MQTT documentation but there is no detailed information. And I searched in the forum but I didn’t find anything about my problem. And then I asked here.
If you know the topics you mentioned, you can send the link

Exactly, you question states that you try to edit a mqtt.cfg which is not even needed in mqtt 2.4.
You need to configure a bridge. Docs again MQTT - Bindings | openHAB

Please read the documentation carefully and checkout other topics Search results for 'Mqtt2 Tutorial' - openHAB Community

1 Like

I think I configured a bridge, don’t I?

Well, if you set up all the settings correctly, as described in the documentation, then yes. Configuring also means you have to click the “Configure” button and fill in the fields there :slight_smile:

I use default setup it. I clicked Congigure and I don’t fill anything and I clicked save.

Is it openHABian? Then the setup screen would be openhabian-config.

Yep, that’s right, configuration for mosquitto is to be found in /etc/mosquitto/ (mosquitto.conf and maybe additional configuration in ./conf.d/)

That’s perfect.

Don’t install both mosquitto and Moquette (that’s the embedded broker) as both will try (and one will fail) to use the same port 1883

Correct. The file mqtt.cfg is for mqtt1 Binding only.

If there is a running broker and avahi does work as expected, the broker should be found by autodiscovery, but as far as I remember, I had to create the bridge manually, too. What is mqtt ips? Do you mean openHAB and the MQTT Broker are both on the same machine? That’s a common installation.

First you have to create at least one mqtt generic thing (or use homie or homeAssistant compliant devices - afaik tasmota does provide homie standard).
Channels are created as part of the Thing (or are autodiscovered when using homie or homeAssistant).

1 Like

If it helps here’s a few examples of my files with mqtt.

Things:

Bridge mqtt:broker:pibroker "pibroker" [ host="10.0.1.11", port=1883, secure=false, username="myusername", password="secretPassword" ]
{
    // Sonoffs
    Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

    Thing topic sonoff2 "Couch Light" @ "Couch Light" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
    }

Items:

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

Switch CouchLight "Couch Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff2:power" }
2 Likes

AFAIK the bridge has to be created manually, for sure if one is using the Generic Things.

@onkal
As you see in the example files from @H102 you do need a bridge (the broker thing you have created on PaperUI, hopefully with correct settings) AND you need a generic MQTT thing (representing your actual sonoff device) which connects to this bridge. Using files this connection is done by the above used syntax, on PaperUI you need to select the already created broker thing.
On this generic MQTT thing you need to create the channels ( switch and two numbers).
Having done that via file you would need to restart openHAB or at least the mqtt bundle ( that is a known bug of 2.4 which is already solved in more recent versions).

1 Like

Thanks @opus for adding the info about steps needed in PaperUI and the need to restart OH after making a change in files. I was looking to see the best way to give an example but you summed it up very well.:wink:

I’ve actually made all the suggestions. There was a problem like the screenshot I added in my first message.
But I guess my first wrong that I installed both mosquitto and Embedded mqtt brokers. I will edit it and write it back.
Thank you, everybody.

Correct, In PaperUI > Addons > Misc click uninstall on the Embedded mqtt broker. Under the Bindings tab scroll down and uninstall the Mqtt binding. With both uninstall I would stop OH from command line with sudo systemclt stop opanhab2 then clean the cache with sudo openhab-cli clean-cache then either restart with sudo systemctl start openhab2 or reboot sudo reboot. I mentioned the reboot b/c there have been times a reboot fix my issue.

After that you can return to PaperUI and install mqtt from the addons > bindings tab. If you have the “include legecy bindings” option turned on and want/need the mqtt 1.x version you can install it as well. Also, as mentioned above, if you plan to use the 1.x version you will also need to configure the mqtt.cfg file. Using the 1.x version IMHO would be b/c you just want to and not something that’s required (I say this but there may be some odd situation that needs 1.x version).

Your suggestions didn’t solve my problem. I still can’t. :frowning:
I add some pic. Where am I wrong?

49

In your Items;
... { mqtt="<[ ...
is the syntax for MQTT binding version 1.
This will never work with MQTT binding version 2, which works with Things and channels.
You had channel links configured before, don’t know why you changed that.

I am not tecnic-man :frowning:
I am trying everything.
I installed only Mosquitto right now.

Can someone tell me what to do step by step according to the photos and what codes to write?

Hey @onkal it seems you struggle really hard.
I don’t know which timezone you live in (I’m UTC+1).
If you want to we can arrange a screen sharing or Anydesk session so I can assist you.


BUT

I am sure with careful reading of the docs of the mqtt binding 2 it can be done.
Even a simple YouTube the search “openHAB mqtt binding 2” gives you full german/english tutorial.
@MK-SmartHouse in this example tutorial even uses your tools (MQTT.fx).
It’s a full STEP BY STEP tutorial!

Cheers,
Elias and big thanks to @MK-SmartHouse for making such amazing YouTube tutorials! :heart:

1 Like