Sonoff Tasmota with MQTT Binding 2.4 (using config files)

Hey @max-e-moose, All

Thanks for the update. I just verified it and it works also in my case fine!
All error/warning messages gone and the all switches and temperature and humidity items work fine.

Again all the best for the new year and thanks for the help and all the work for this project!
Very impressive that different kind of syntax still ends up in a working functionality. I like if something works error tolerant!

Oliver

Can this be promoted to the manual? This is absolutely a top post!

After trying myself clueless for 2 days I found this post and I got the MQTT upgrade issues solved in about 3 hours.

Go to the docs, scroll down and click the edit button :slight_smile:

This is mega, thank you!!!

Where can I find info on:

  1. Pre-defined sonoff group tags (in your example you have; Sonoff_S20, Sonoff_B1, Sonoff_POW, Sonoff_SC, Sonoff_RF), i.e. in the round brackets
  2. Pre-defined sonoff icon labels (in your example you have; sonoff_s20_uk, sonoff_b1, sonoff_pow, sonoff_sc, sonoff_rf), i.e. in the triangular brackets

Cheers

After struggling a lot I will give this a try, thanks.
I might be wrong but shouldnt the line:

String GF_Sonoff_S20_Reachable "Reachable: [%s]" <contactable> (GF_Sonoff_S20) { channel="mqtt:topic:sonoffs20:reachable" }

be .String GF_Sonoff_S29_Reachable ..................{ channel="mqtt:topic:mosquitto:sonoffs20:reachable" }

Correct, but … See this Thread

1 Like

The group name can be set to any string you like. Setting groups is not necessary.
The used icons are most probably images or icons created by the user. I use a picture of a sonoff basic, the name is file name of the image/icon.

After you helped me here to get everything running, I wrote down my complete MQTT setup process here:
I hope its a help for someone:

https://albold-home.de/setting-up-mqtt-on-openhab2/

3 Likes

You are not wrong. Missed that when editing. I’ll fix that, cheers.

As @opus correctly pointed out, the Sonoff group tags and icons are ones that I defined. You can find out more about custom icons here. A collection of the pre-defined OpenHAB icons can be found here.

1 Like

Continuing the discussion from Sonoff Tasmota with MQTT Binding 2.4 (using config files):

Uninstalling and re-installing the app fixed the issue, not rule related ; weird though ; thank you

Hello i used to have this rule send me broadcast notification whenever an item turns on or off, how can i make it work using mqtt 2.4 noting that mqtt action binding is no more available
Many thanks,

rule “Present”
when
Member of gDual changed or
Member of gSingle changed
then
if(previousState == NULL) return;
logInfo(“Sent”, “Test”)
sendBroadcastNotification(triggeringItem.name.toString +" changed to " + triggeringItem.state.toString)
end```

If you could post the topic and payload we could show you how to use the " mqttActions" as posted by @max-e-moose.
Although that should be possible for yourself.

Oliver, thanks for sharing your post.
For your future reference, and maybe somebody else who might use it, there’s a typo in your post:

sudo nano /etc/mosquitto/mosquitto.con
should read sudo nano /etc/mosquitto/mosquitto.conf (it’s missing a final F)

Thanks again for taking the time to write all that up.

Hey Alex! Thanks for the feedback. I just corrected it! Was a bit busy during the week.
But I am happy that it is a little help!

I also tried to change to the new 2.4 (2.5) mqtt binding. Nearly everything works because this helpful solution.
But i have problems with the sonoff RF bridge (newest Tasmota Firmware).

With mqtt 1 it was possible to send the RFKey with this command:

Switch Sw_it_licht_r88          "Hauptbüro"                  <light>            (G_sonoff,G_licht) ["Lighting"]    { mqtt=">[localbroker:cmnd/so_rfb_1/Backlog:command:ON:RfCode #004015], >[localbroker:cmnd/so_rfb_1/Backlog:command:OFF:RfCode #004014]" }
Switch Sw_it_licht_r11_west     "Buero West"                 <light>            (G_sonoff,G_licht) ["Lighting"]    { mqtt=">[localbroker:cmnd/so_rfb_1/Backlog:command:ON:RfCode #005015], >[localbroker:cmnd/so_rfb_1/Backlog:command:OFF:RfCode #005014]" }
Switch Sw_it_licht_r11_ost      "Buero Ost"                  <light>            (G_sonoff,G_licht) ["Lighting"]    { mqtt=">[localbroker:cmnd/so_rfb_1/Backlog:command:ON:RfCode #001015], >[localbroker:cmnd/so_rfb_1/Backlog:command:OFF:RfCode #001014]" }
Switch Sw_it_licht_r11_nacht    "Nachtlicht Büro"            <light>            (G_sonoff,G_licht) ["Lighting"]    { mqtt=">[localbroker:cmnd/so_rfb_1/Backlog:command:ON:RfCode #000415], >[localbroker:cmnd/so_rfb_1/Backlog:command:OFF:RfCode #000414]" }

I tried it with:

Type switch : button1       "Button 1"             [ stateTopic="stat/sonoff_rfb_1/RESULT", commandTopic="cmnd/sonoff_rfb_1/BACKLOG RfCode #000014" ]

But it do not work!

i also tried the “learned keys” but get some negativ entrys in the log:

2019-01-22 20:30:43.811 [nt.ItemStatePredictedEvent] - mqtt_topic_r88_brunnen_r88_aus predicted to become {"RfKey2":"Learned sent"}

==> /var/log/openhab2/openhab.log <==

2019-01-22 20:30:43.813 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfKey2":"Learned sent"}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfKey2":"Learned sent"}

2019-01-22 20:30:43.819 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey1' in '{"RfKey2":"Learned sent"}'

2019-01-22 20:30:43.823 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfKey2":"Learned sent"}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfKey2":"Learned sent"}

Can anybody help?

The mqtt topic is cmnd/so_rfb_1/Backlog according to your old configuration. A switch can only send “ON” and “OFF” to a topic, if you don’t define custom ON/OFF parameters. (see documentation)

That means actually: Send ON/OFF to this topic: cmnd/sonoff_rfb_1/BACKLOG RfCode #000014 which is not what you want :slight_smile:

You will need to change the channel type to String and create an item and a rule
Thing channel:

Type string : command       "Button 1"             [ commandTopic="cmnd/sonoff_rfb_1/Backlog" ]

items:

String Sw_it_licht_command  { channel="mqtt:xxx:xxx:command }
Switch Sw_it_licht_r88          "Hauptbüro"                  <light>            (G_sonoff,G_licht) ["Lighting"] 
Switch Sw_it_licht_r11_west     "Buero West"                 <light>            (G_sonoff,G_licht) ["Lighting"]
Switch Sw_it_licht_r11_ost      "Buero Ost"                  <light>            (G_sonoff,G_licht) ["Lighting"]
Switch Sw_it_licht_r11_nacht    "Nachtlicht Büro"            <light>            (G_sonoff,G_licht) ["Lighting"]

rule:

rule "G_sonoff"
when
    Member of G_Sonoff received command
then
    if (receivedCommand == ON) {
        switch triggeringItem.name.toString {
            case "Switch Sw_it_licht_r88" : Sw_it_licht_command.sendCommand("RfCode #004015")
            case "Switch Sw_it_licht_r11_west" : Sw_it_licht_command.sendCommand("RfCode #005015")
            //etc...
        }
    } else {
        switch triggeringItem.name.toString {
            case "Switch Sw_it_licht_r88" : Sw_it_licht_command.sendCommand("RfCode #004014")
            case "Switch Sw_it_licht_r11_west" : Sw_it_licht_command.sendCommand("RfCode #005014")
            //etc...
        }
    }
end

Quick question:
Can I run Mqtt 1.x and MQTT 2.4 Binding simultaneously?
That way I could migrate step by step.

Help is appreciated.
Thanks.

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" {
        Channels:
            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"} //reachable.map
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!!!

Hi,
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
“tele/sonoff-9D3C16/STATE”
to
“stat/sonoff-9D3C16/RESULT”

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" ]