Sonoff Tasmota with MQTT Binding 2.4 (using config files)

yes you can.

Hi @max-e-moose ,
maybe you want to add the Working Configuration for Sonoff Basic Switch:

Thing topic sonoffbasic "Sonoff Basic" @ "Some Room" {
            Type switch : power     "Power"                [ stateTopic="stat/BasicSwitch/POWER", commandTopic="cmnd/BasicSwitch/POWER"]
            Type string : reachable "Reachable"            [ stateTopic="tele/BasicSwitch/LWT" ]
            Type number : rssi      "WiFi Signal Strength" [ stateTopic="tele/BasicSwitch/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
            Type string : version   "Firmware Version"     [stateTopic="stat/BasicSwitch/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]

            Type string : info1     "Info1"                [stateTopic="tele/BasicSwitch/INFO1"]
            Type string : status2   "Status2"              [stateTopic="stat/BasicSwitch/STATUS2"]
            Type string : result    "Result"               [stateTopic="stat/BasicSwitch/RESULT"]

And the Items File:

Switch SonoffBasic_Power "Sonoff Power" (ggroup) {channel="mqtt:topic:mosquitto:sonoffbasic:power"}
String SonoffBasic_Reachable  "Sonoff: reachable" (ggroup)  {channel="mqtt:topic:mosquitto:sonoffbasic:reachable"} //
Number SonoffBasic_RSSI  "Sonoff: RSSI [%d %%]" (ggroup) {channel="mqtt:topic:mosquitto:sonoffbasic:rssi"}
String SonoffBasic_CurrentFW "FW Sonoff [%s]" (ggroup)  {channel="mqtt:topic:mosquitto:sonoffbasic:version"}

String SonoffBasic_Info1 "Sonoff: MQTT Info1 [%s]"   (ggroup) {channel="mqtt:topic:mosquitto:sonoffbasic:info1"}
String SonoffBasic_Status2 "Sonoff: MQTT Status2 [%s]" (ggroup) {channel="mqtt:topic:mosquitto:sonoffbasic:status2"}
String SonoffBasic_Result "Sonoff: MQTT Result [%s]"  (ggroup){channel="mqtt:topic:mosquitto:sonoffbasic:result"}

Hope this helps.

BTW: Make sure to restart openhab everytime you change the .things file that cointains your mqtt things!!!

i get " JSONPATH-transformation failed" with the Sonoff B1 mqtt definitions

   Type switch   : fade       "Fade"                 [ stateTopic="tele/sonoff-9D3C16/STATE", commandTopic="cmnd/sonoff-9D3C16/FADE", transformationPattern="JSONPATH:$.Fade" ]
   Type dimmer   : dimmer     "Dimmer"               [ stateTopic="tele/sonoff-9D3C16/STATE", commandTopic="cmnd/sonoff-9D3C16/DIMMER", transformationPattern="JSONPATH:$.Dimmer" ]
  Type string   : mode       "Mode"                 [ stateTopic="tele/sonoff-9D3C16/STATE", commandTopic="cmnd/sonoff-9D3C16/SCHEME", transformationPattern="JSONPATH:$.Scheme" ]
  Type colorHSB : colour     "Colour"               [ stateTopic="tele/sonoff-9D3C16/STATE", commandTopic="cmnd/sonoff-9D3C16/HSBColor", transformationPattern="JSONPATH:$.HSBColor" ]

JSONPATH-transformation failed: Invalid path '$.Dimmer' in '{"Time":"2019.01.28 19:59:39","Uptime":20,"Vcc":3.680,"POWER":"OFF","Wifi":{"AP":1,"SSId":"xxxxx","RSSI":100,"APMac":"7C:FF:4D:F6:45:FC"}}'

i changed

no errors in log file, but i am not sure if this is correct

        Type switch   : fade       "Fade"                 [ stateTopic="stat/sonoff-9D2E42/RESULT", commandTopic="cmnd/sonoff-9D2E42/FADE", transformationPattern="JSONPATH:$.Fade" ]
    Type dimmer   : dimmer     "Dimmer"               [ stateTopic="stat/sonoff-9D2E42/RESULT", commandTopic="cmnd/sonoff-9D2E42/DIMMER", transformationPattern="JSONPATH:$.Dimmer" ]
    Type string   : mode       "Mode"                 [ stateTopic="stat/sonoff-9D2E42/RESULT", commandTopic="cmnd/sonoff-9D2E42/SCHEME", transformationPattern="JSONPATH:$.Scheme" ]
    Type colorHSB : colour     "Colour"               [ stateTopic="stat/sonoff-9D2E42/RESULT", commandTopic="cmnd/sonoff-9D2E42/HSBColor", transformationPattern="JSONPATH:$.HSBColor" ]

The use of Tasmota telemetry (tele) output is intentional. I noticed that numerous MQTT commands in Tasmota use the state or “stat” topic in the reply. Here are example replies from sending “power on” and “dimmer 55” or “ct 326” commands:

MQT: stat/sonoff-b1/RESULT = {"POWER":"ON"}
MQT: stat/sonoff-b1/RESULT = {"POWER":"ON","Dimmer":55,"Color":"0000004545","HSBColor":"0,0,0","Channel":[0,0,0,27,27],"CT":326}

If you are using the same state command for switches, dimmers, or color pickers then this would result in JSONPATH-transformation failures. For example, the reply to a power on command as shown above would cause the transformation for the dimmer/channel/color/color temperature to fail.

My bulbs are all running Tasmota v6.3.0.5 and when I look at the telemetry output in the Tasmota web GUI console I see this:

MQT: tele/sonoff-b1/STATE = {"Time":"2019-01-28T21:46:48","Uptime":"3T01:10:54","Vcc":3.361,"POWER":"ON","Dimmer":55,"Color":"0000004545","HSBColor":"0,0,0","Channel":[0,0,0,27,27],"CT":326,"Scheme":0,"Fade":"ON","Speed":1,"LedTable":"OFF","Wifi":{"AP":1,"SSId":"SOME_WIFI","BSSId":"SOME_MAC_ID","Channel":9,"RSSI":100}}

So using the telemetry data instead of the state eliminated JSONPATH-transformation errors for me.

What version of Tasmota is your bulb running?

A little tweak, that I suggest:

Add “autoupdate=false” to your Switch items. That way the Item State in your sitemap always reflects the correct setting of the device (the result that you monitor with the back channel of the Switch). In that case the Switch is not indicated “on”, when your device is not reachable.

So if your Thing is:

Type switch : power     "Power"                [ stateTopic="stat/Sonoff_PowSwitch/POWER", commandTopic="cmnd/Sonoff_PowSwitch/POWER", on="ON", off="OFF"]

Your item would look like this:

Switch LivingRoom_SonoffPlug "Licht Pow" {channel="mqtt:topic:mosquitto:sonoffpow1:power", autoupdate="false"}

Item only switches “on” when the you stat Channel returns Power on.


okay the version on my B1s, ist rather old :open_mouth:
"Sonoff-Tasmota 5.11.1 von Theo Arends"
so i do an Update first, and check again …
thanks :+1::+1:

Hi guys, I’m a new openhab2 user trying to figure out how to put all things together and make openhab work fine with my sonoff tasmota devices. I’m just passing by to thank you all for this article, it helped me a LOT and now I’m able to connect to my things, :slightly_smiling_face:

My next step is to play with Rules.

Thank you all!


@max-e-moose you helped me a lot migrating to MQTT Binding 2.4 you had a Mapping ( “Mode: [MAP(]”), could you provide the content of this file?

1 Like

NP. :slightly_smiling_face:

0=Single Color
1=Wake up
2=Slow Cycle
3=Fast Cycle
NULL=Not Set

I should note that these are custom mappings. You can change the values after the equals sign to whatever you like.


Hi all, when I query with:

I only get:

  "Status" : {
    "Module" : 1,
    "FriendlyName" : [ "Sonoff" ],
    "Topic" : "Outdoor",
    "ButtonTopic" : "0",
    "Power" : 1,
    "PowerOnState" : 3,
    "LedState" : 1,
    "SaveData" : 1,
    "SaveState" : 1,
    "SwitchTopic" : "0",
    "SwitchMode" : [ 0, 0, 0, 0, 0, 0, 0, 0 ],
    "ButtonRetain" : 0,
    "SwitchRetain" : 0,
    "SensorRetain" : 0,
    "PowerRetain" : 0

Any idea where I can get the info from which firmware version is running on the device? I have the latest firmware installed…

How about reading the Tasmota documentation for openHAB or simply use the topic with a space between status and 2.

1 Like

I read through the documentation 3 times, but thanks for pointing it out :roll_eyes:

If I sent what you proposed, I get: “Command” : “Unknown”

I used cmnd/sonoff_TH/status 2, my device has sonoff_TH as topic and %prefix%/%topic%/ as full topic.

Thanks opus, doesn’t work for me, still get the above written response…

What I would do in your case:
Go to the web interface of the sonoff device (just put the IP into the adress bar) and open the console.
On the console you can monitor which commands are coming in and see their out. You can also put commands in there directly.
Try the ones posted above and play around with the syntax in order to see how the device is reacting.If you need further guidance post some examples what you see when sending a command via openhab and directly.


on the console:

22:13:14 CMD: cmnd/sonoffBlablabla/status 2

22:13:14 MQT: sonoff/Outdoor/STATUS2 = {“StatusFWR”:{“Version”:“6.5.0(release-sonoff)”,“BuildDateTime”:“2019-03-19T12:24:10”,“Boot”:6,“Core”:“2_3_0”,“SDK”:“1.5.3(aec24ac9)”}}

22:13:24 CMD: cmnd/status 2

22:13:24 MQT: sonoff/Outdoor/STATUS2 = {“StatusFWR”:{“Version”:“6.5.0(release-sonoff)”,“BuildDateTime”:“2019-03-19T12:24:10”,“Boot”:6,“Core”:“2_3_0”,“SDK”:“1.5.3(aec24ac9)”}}

22:13:33 CMD: status 2

22:13:34 MQT: sonoff/Outdoor/STATUS2 = {“StatusFWR”:{“Version”:“6.5.0(release-sonoff)”,“BuildDateTime”:“2019-03-19T12:24:10”,“Boot”:6,“Core”:“2_3_0”,“SDK”:"1.5.3(aec24ac9)“}}

any idea?

Usage in a rule:

      val actionsBroker = getActions(“mqtt”,“mqtt:broker:MyMQTTBroker”) // change to your broker name!
    case “queryFW” :
    actionsBroker.publishMQTT( “cmnd/Outdoor/status”, “2”)

Thing definition:

Bridge mqtt:broker:MyMQTTBroker [ host="", secure=false, username="user", password="password" , clientID="MyMQTTClient" ]

    Thing topic sonoff_3_Thing "Light_3" @ "Sonoff" {  
            Type switch : PowerSwitch  [ stateTopic="stat/sonoff_3/POWER" , commandTopic="cmnd/sonoff_3/POWER", on="ON", off="OFF" ]
            Type string : Version [stateTopic="stat/sonoff_3/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]

Item definition:

String Sonoff3_Version "Sonoff3 Version: [%s]" <sonoff_basic> { channel="mqtt:topic:MyMQTTBroker:sonoff_3_Thing:Version"}

Hey opus, thanks for reposting this, I went over it when I was searching in the forums.

As I am still using the 1.x binding, this might be the wrong thread, but I used several variants, such

String sonoffTV_Version “Kugellampe Version [%s]” (gSwitch) {mqtt="<[broker:sonoff/PowTV/STATUS 2:state:JSONPATH($.StatusFWR.Version)]" }

and they didn’t work :frowning: atm I don’t have any idea how to debug any further…

Sorry, but if you are still on MQTT1 read here

But this is exactly what does not work for me:

case “queryFW” :
publish(“broker”, “cmnd/” + device_id + “/status”, “2”)
-> -> -> cmnd/Outdoor/status2

and I don’t understand why nor how to further debug…

I have checked that:
Full Topic is: %prefix%/%topic%/
Topic: Outdoor

anything else I can do?