[SOLVED] Mosquitto MQTT cannot get service to run

Thanks, Peter. I am seeing some other details that will help me later but it is not helping my current problem.
I am thinking it is something to do with the Client ID (or at least that is one problem). I’ve seen a number of different names used in .items files but I continue to get an error with any entry I provide:
Session does not exist. CId=openhab
for example when I list clientID=“openhab”
Is this client ID entered somewhere else? The only other place I see it listed is in the MQTT broker configurations, but it’s not allowing me to enter a value there. Also does this correspond to a setting on the Sonoff?
Thanks again,

Each device has to have its own ClientID, in other words the same ClientID must not be used by two devices.

1 Like

As Jürgen said

I think the clientID is not mandatory in the Bridge/Thing so omit it.

1 Like

Within the MQTT Broker thing, some text beneath the Client ID setting states:“Use a fixed client ID. Defaults to empty which means a user ID is generated for this connection.” So that must be hapening because when deleting the clientID within the Bridge statement of the .things file, I get the following error:

Session does not exist. CId=paho51621326352350

So now I have to believe something else is holding this up. Perhaps something in the “MQTT Embedded Broker” service or the “MQTT system broker connection” service? There aren’t much for settings in those services however…

I’m going through everything I have installed and verifying their settings:

  1. Under Services/MQTT I have MQTT Embedded Broker and MQTT system broker connections installed. The only field filled under the embedded broker is the name of the persistence file (mqttembedded.bin).

  2. The following things are installed:
    The first is a thing that I tried installing via PaperUI, but am now unable to install (when I try I get Error: 409 - Conflict).
    The MQTT Broker configuration settings are:

  • Broker Hostname/IP:
  • Broker Port: 1883
  • Client ID: paho51621326352350 (system generated)

And that’s all that I can see. I was “hoping” to find some conflict but I can’t find any differences from online guides.

Not sure if you have a special case and this is in purpose, but right now you have two MQTT brokers configured, which will be rather challenging to configure.
Remember, the basic information flow is device <–> MQTT broker <–> OH2

In the best case you have now:
device1 <–> MQTT embedded <–> OH2
device2 <–> MQTT Mosquitto <-------^

While OH2 can likely handle two brokers, it will be challenging to remember who does what (unless you have a special case and this is on purpose). OH2 provides an embedded broker for convenience and hence, maybe you want to delete the Mosquitto broker you had set up (or vice versa if this is your preference).
A few more things to remember:

  • always points to the local machine (whichever that is); if you are unsure, just use the real IP address in all cases.
  • Clear the Cache can be your friend if you work on configs a lot and get weird results
  • in any case, do it step-wise: first check if you device connects to the broker, than check if OH2 connects to the broker; and if both, check then you get to content and items, etc. You can use a separate program to connect to your broker with your computer and see what is happening: MQTT Exploration App (as well as read incoming commands or post MQTT messages)

I’ve made the change to 2.5.0.M3, removed and reinstalled the embedded broker and binding. I did not install the auto-generated thing and am configuring it in a thing file. As of today my device (TH16 with SI7021 sensor) is at least partially working; I can control the switch (super happy about that!) but cannot pull the sensor data out. The current entries in the .things files are:

Bridge mqtt:broker:mqttbroker "MQTT Broker" [ host="", secure=false, port=1883, qos=0, retain=false, clientid="openhab", keep_alive_time=30000, reconnect_time=60000 ]
     Thing topic Sonoff_Coop "Sonoff Coop" @ "openhab" {
        Type switch : power "Power" [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]

and a .item as:

Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop:power"}

I can control the switch remotely any all is happy. When I begin to attempt to create a Channel to pull out the temperature, any configuration I try either does nothing or messes up the operation of the switch.
The Sonoff TH is sending out the following string from its sensor, seen from the Sonoff console:

06:45:32 MQT: tele/Sonoff_Coop/SENSOR = {"Time":"2019-10-06T06:45:32","SI7021":{"Temperature":77.0,"Humidity":53.6},"TempUnit":"F"}

I’ve tried the following channel configurations (separately of course) without luck (I have the JSON transformation installed):

Type number : Temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR:SI7021:Temperature"]
Type number : temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]

I’ve found some variations out there in the community pages but none work to pull the temperature number over.

Have you installed the JSONPATH transformation service?

Yes, and uninstalled/reinstalled JSONPath after the 2.5.0.M3 update to be sure the latest was there

The second version should work. I have it working like that with the AM2301 sensor.

I agree, I think it should! But it immediately breaks the switch and still doesn’t transmit the temperature! I’d actually be ok without the switch working and in fact tried leaving the temperature channel and removed the switch channel, and it still doesn’t transmit…
Could the JSON transform be malfunctioning somehow?

You have to define your Thing like this:

    //Gruppe TH10/16 Monitoring WiFi Smart Switch
    Thing topic TH1601 "Sonoff TH16 01" @ "MQTT2" {
        Type switch : power       "Power "               [ stateTopic="stat/th16_01/POWER", commandTopic="cmnd/th16_01/POWER" ]
        Type number : rssi        "WiFi Signal Strength" [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version     "Firmware Version"     [ stateTopic="stat/th16_01/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
        Type switch : reachable   "Reachable"            [ stateTopic="tele/th16_01/LWT", transformationPattern="MAP:reachable.map" ]
        Type number : temperature "Temperature"          [ stateTopic="tele/th16_01/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity    "Humidity"             [ stateTopic="tele/th16_01/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
        Type string : ssid        "WiFi"                 [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Wifi.SSId"]
        Type datetime : time      "Time"                 [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Time"]

and the corresponding items look like:

//Gruppe TH10/16 Sensoren
//192.168.x.y                            Steckdosenleiste/Power Strip  TH16

Switch    Sonoff_PowerStrip_01          "Steckdosenleiste 1 [MAP(de.map):%s]"             <poweroutlet>           (EG_Kind1,gPlugSwitch,gSonoff)  { channel="mqtt:topic:hans:TH1601:power"}               
Number    Sonoff_PowerStrip_01_RSSI     "Steckdosenleiste 1 RSSI [%s]"                    <qualityofservice>      (EG_Kind1,gRSSI)                { channel="mqtt:topic:hans:TH1601:rssi" }               
String    Sonoff_PowerStrip_01_Version  "Steckdosenleiste 1 Version [%s]"                 <sonoff_pow>            (gSonoffs,gVer)                 { channel="mqtt:topic:hans:TH1601:version" }            
Switch    Sonoff_PowerStrip_01_Unreach  "Steckdosenleiste 1 Erreichbarkeit [%s]"          <siren1>                (EG_Kind1,gLWT)                 { channel="mqtt:topic:hans:TH1601:reachable" }          
//        For Fun and Test                                                                                                                                  
Number    Sonoff_PowerStrip_01_Temp     "Steckdosenleiste 1 Temperatur[%.1f °C]"          <temperature>           (gSonoffs,EG_Kind1,gRtIstI)     { channel="mqtt:topic:hans:TH1601:temperature"}               
Number    Sonoff_PowerStrip_01_Hum      "Steckdosenleiste 1 Luftfeuchtigkeit[%.2f %%]"    <humidity>              (gSonoffs,EG_Kind1)             { channel="mqtt:topic:hans:TH1601:humidity" }               
String    Sonoff_PowerStrip_01_SSID     "Steckdosenleiste 1 Wlan [%s]"                    <chart>                 (gSonoffs)                      { channel="mqtt:topic:hans:TH1601:ssid" }            
DateTime  Sonoff_PowerStrip_01_Date     "Steckdosenleiste 1 Refresh [ %1$tH:%1$tM]"       <time>                  (gSonoffs)                      { channel="mqtt:topic:hans:TH1601:time" }          
//Number    Sonoff_PowerStrip_01_VCC      "Steckdosenleiste 1 VCC[%.2f V]"                  <energy>                (gSonoffs)    // doesn't work any longer

Thanks, Peter. Your input was the basis for most of my testing but still not functioning.
I did discover one potential conflict: Within my .thing file in defining my thing topic I used Sonoff_Coop but also used this in the Sonoff configuration file and in the .item. I changed the topic line to

Thing topic Sonoff_Coop_Thing "Sonoff Coop" @ "openhab" {

…changing the thing name to include _Thing at the end. It now fixes the conflicts I had with the switch being disabled but am still not getting the temperature feed… :o(

I should mention I correspondingly changed the .items:

Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature> { mqtt="<[mqttbroker:Sonoff_Coop_Thing:SENSOR:JSONPATH($.SI7021.Temperature)]"}

This is a configuration for use with MQTT binding version 2

This is a configuration for use with MQTT binding version 1 (it could never work with Things and channels)

That line needs to be added to the thing definition you posted earlier!

One more try:


Switch Sonoff_Coop_Power "Coop Switch" <switch>                            { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature>  { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:temperature"}


    Thing topic Sonoff_Coop_Thing  "Sonoff Coop" @ "openhab" {
        Type switch : power "Power"               [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]

After you made this changes, pls. restart openhab as I think there is still a bug, when changing your text-files, that changes are not loaded.

your switch:#

Well that worked! I have a temperature coming through!
At least it worked for a few minutes, now my embedded broker is broken, for some unknown reason. Grrr. I don’t think this could get any more ridiculous. Commented out all of my changes, three restarts and still "OFFLINE - COMMUNICATION_ERROR

As the broker attempts to connect, I’m getting these entries in the logs:

2019-10-06 19:45:38.717 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '' with clientid paho69680369956 and file store '/var/lib/openhab2/mqtt/'
2019-10-06 19:45:39.554 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to ''. Next attempt in 10000ms

I don’t somehow have a permissions issue on that folder that I never had before?

Don’t know if it helps or if you already changed it, but I saw that your clientID in the Bridge is written as clientid, but I think it should be clientID.