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

Yes, that’s right I struggle really hard. :sob:

I watched MK-SmartHouse and BK Hobby videos and I try to do them but It doesn’t look like in the video when I do it, I guess I’m doing something wrong. :expressionless:

I will try this video again. If I can’t do it, We do it with Anydesk session? I live in UTC+3.

It’s going to help a lot if you recognize that openHABs MQTT has changed over the years.

The version 1 binding has no things or channels, is set using a special file mqtt.cfg and Item configuration {mqtt="..."}
A lot of old postings and tutorials will of course talk about this way. And they probably will not say they are for “version 1” because there was only one version back then.

The version 2 binding is set up with Things, and Item configurations {channel="..."}

These two methods are totally incompatible and it will never work if you try everything from both. Take care to choose the right help - look out for mention of Things or .cfg files.

1 Like

Also the JSONPATH transformation is wrong.

it should be JSONPATH:$.AM2031.Temperature (based on the output from the screenshot).

Also I would suggest you to drop this textual thing definition. Use PaperUI to define Things (and in particular MQTT channels here). It is more straighforward for beginners and every text entry has a description in the UI.

I’m not very experienced in the technical ways too. But when I look in your first post I see, that you got a string from mosquitto

For me it looks like i fyour JSON-Transformation is not correct. So the first question is if you have installed the JSONPath-Transformation-Service ?

The next point I observed is the way how you handle your topics. I don’t know really, but as I understand there three ways to communicate with a Tasmoata-flashed devices: tele, stat, cmnd. You’re using something like this “sonofftele” and the syntax of the Transformation-String seems to be not correct and you are mixing mqtt2 (.things) and mqtt1 (.items)

There are some examples of @H102 how to deal with that and hints from Jürgen, Udo, Rolf, rossko57 and Elias of which I have my knowings too.

I already have installed Mosquitto as Broker, as I came from MQTT1. So for me there was nothing else to do (I think) only installing the MQTT2-Binding.

As I have a TH16 with AM2301-Sensor, will give you my setup here:

mqtt2.things:

Bridge mqtt:broker:hans "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="OH2_hans" ]  
{
    //Gruppe TH10/16 Monitoring WiFi Smart Switch
    Thing topic TH1601 "Sonoff TH16 01" @ "MQTT2" {
    Channels:
        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-File:

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 63[%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" }          

and a screenshot of my MQTT-Setup of the TH16

Hope this can help you for your additional tests.

Thank you for your replies.

@fibu-freak Th16 and Th10 are same.
There is sonofftele in Mqtt Explorer and Mqtt.fs, So I use sonofftele, I will change it to “tele”.

@rkrisi I tried JSONPATH:$.AM2031 too but I will change it should be right.
I couldn’t solve my problems on paperui, so I switched to the code.

Thanks all of you. Aspecialy @fibu-freak :slight_smile:

I erased all of things about mqtt and I started at the beganing.
I solved something on papergui.


I changed sonofftele to tele and JSON-Transformation. I can see numbers now. :slight_smile:

Now how can I add °C, % and graphic of history and how can I change update period on papergui?

You got it, great!

This are three question:

  1. In order to get the “° C” after the temperature use the label format as @fibu-freak posted above.
  2. In order to get a graphic of history data ( a chart) you need to set up persistence. There are lots of examples in forum. I do use rrd4j for such.
  3. Which update interval are you trying to change? The one from the sonoff/tasmota device needs to be done one the device.

I want to change the data update period.

That can be done on the web-interface of the sonoff/Tasmota device. You reach that with the IP of that device, then browse to Logging configuration and change the period for the telemetrie.

I set up telemetrie. Thank you very much @opus.