Sonoff Tasmota with MQTT Binding 2.4 (using config files)

Hey Sorry Guys, me again. Happy new year!
I got the hint to increase the JAVA heap size and updated again. Now its much better. No strange exception anymore. MQTT workes also fine. But there is one error/warning in the log

2019-01-01 09:40:56.999 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'mqtt.things', using it anyway:
Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>
Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>
Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>
Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>
2019-01-01 09:40:57.010 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mqtt.things'

My thinks 4 look like this:

Bridge mqtt:broker:mosquitto "Mosquitto" [ host="127.0.0.1", secure=false, clientID="openHAB2"]
{
 // My OBI switches with Tasmota
    Thing mqtt:topic:alexaWohnzimmer "AlexaSwitchWohnzimmer" @ "Wohnzimmer" {
        Channels:
            Type string : reachable "Reachable"            [ stateTopic="Home/Alexa/LivingRoom/tele/LWT" ]
            Type switch : power     "Power"                [ stateTopic="Home/Alexa/LivingRoom/stat/POWER", commandTopic="Home/Alexa/LivingRoom/cmnd/POWER" ]
            Type number : rssi      "WiFi Signal Strength" [ stateTopic="Home/Alexa/LivingRoom/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
    Thing mqtt:topic:alexaEsszimmer "AlexaSwitchEsszimmer" @ "Esszimmer" {
        Channels:
            Type string : reachable "Reachable"            [ stateTopic="Home/Alexa/DiningRoom/tele/LWT" ]
            Type switch : power     "Power"                [ stateTopic="Home/Alexa/DiningRoom/stat/POWER", commandTopic="Home/Alexa/DiningRoom/cmnd/POWER" ]
            Type number : rssi      "WiFi Signal Strength" [ stateTopic="Home/Alexa/DiningRoom/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
    Thing mqtt:topic:alexaSchlafzimmer "AlexaSwitchSchlafzimmer" @ "Schlafimmer" {
        Channels:
            Type string : reachable "Reachable"            [ stateTopic="Home/Alexa/BedRoom/tele/LWT" ]
            Type switch : power     "Power"                [ stateTopic="Home/Alexa/BedRoom/stat/POWER", commandTopic="Home/Alexa/BedRoom/cmnd/POWER" ]
            Type number : rssi      "WiFi Signal Strength" [ stateTopic="Home/Alexa/BedRoom/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
    Thing mqtt:topic:alexaKueche "AlexaSwitchKueche" @ "Kueche" {
        Channels:
            Type string : reachable "Reachable"            [ stateTopic="Home/Alexa/Kitchen/tele/LWT" ]
            Type switch : power     "Power"                [ stateTopic="Home/Alexa/Kitchen/stat/POWER", commandTopic="Home/Alexa/Kitchen/cmnd/POWER" ]
            Type number : rssi      "WiFi Signal Strength" [ stateTopic="Home/Alexa/Kitchen/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
}

Any idea idea whats not OK in the definition?

This is probably copied from the documentation right? Unfortunately that is an incorrect syntax. But I do not know the correct one. There were other people with working examples, look for recent posts.

I’m using the .things file to define my mqtt things.
My broker is set up using the same syntax as yours. Can’t say if the localhost address and using no credentials is making the connection, but you should see that in the logs!
For the device things my working syntax is:

Thing topic sonoff_2_Thing "Light_2" @ "Sonoff" {....  

For the channels I have to state the broker as well, like:

String Sonoff2_Version "Sonoff2 Version: [%s]" <sonoff_basic> { channel="mqtt:topic:opusMQTT:sonoff_2_Thing:Version"}

I do dislike this “second” syntax (without the “:”) but that is another story!

2 Likes

@max-e-moose
Thank you for the tutorial using config files… would you mind posting a Sitemap for your example? I hope this will help me to finalize my config. With PaperUI it’s already working.

I see that error in the logs too. It did not have any effect on the Things so I had been ignoring it. However I have now edited my .things and .items files to follow the correct syntax that @opus posted and that error is now gone. Part of the change involved adding the broker name to the channel in the items file. I will edit the first post and correct the syntax there.

I copied the syntax from the MQTT Generic Thing documentation for my example. At the time it looked like “Thing mqtt:topic:mything” but now looks like “Thing topic mything”. I can confirm that the latter is correct.

I will add one to the first post in this thread.

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: