Sonoff Tasmota with MQTT Binding 2.4 (using config files)

I’d be interested in a report / post / rant about your experiences with the mqtt 2.4 binding and where and why the migration failed for you.

Cheers, David

hey guys,

i just upgraded my openhab to latest version with apt… after that my mqtt setup do not work anymore ?

i’m liitle bit confused about the mqtt binding ut wasn’t installed anymore and i had to install the mqtt binding. now i have mqtt.cfg and mqtt-eventbus.cfg.

do you have any advise how to configure correctly ?

Thanks in advance

Lars

Hey David,

I just updated by accident to OpenHAB2 2.4 and my MQTT did not work anymore. SO I decided to switch to the new binding.
Thanks you that you posted this. It helped me a lot to get it running again!!

I have only one remark. First my Items didn’t work than I added the broker name in the items configuration and they are online again and I can switch my tasmota switches!!

For example:

>  Switch GF_Sonoff_S20_Power  "Sonoff S20"  <sonoff_s20_uk> (GF_Sonoff_S20) { channel="mqtt:topic:mosquitto:sonoffs20:power" }

Is this wrong in your example?

Another question. For what do I need “mqttActions” lines. I added them in the startup code. But what are they doing?

Thanks a lot
Oliver

No problem. Hope it helps.

In the example, all of the Things are defined inside curly braces “{ }” that are directly after the square brackets “” that define Bridge parameters. My understanding is that those curly braces are telling OpenHAB that any Things defined within them are associated with that Bridge. That is why I have not added the broker name to the channels.

The example reflects settings that are working in my OpenHAB installation. Are your Things inside the curly braces that define your Bridge?

They are required if you have rules that will send MQTT actions. You do not need those lines in the startup code, unless the action of starting OpenHAB is supposed to send an MQTT action.

That’s part of why this thread exists! :wink:

The MQTT Binding was significantly updated from version 1.13.0 to version 2.4. The new version does not require those files. It does require that you do some re-configuring though.

:neutral_face:

Read the first post in this thread? Also, if you don’t want to use the .items and .things approach, you can always use the GUI.

Actually your post helped me a lot! So again: Thank you!

I understand your argument that the bridge must be defined by placing the thing name inside the bridge config, but in my case it did not work!? Anyway after after adding the bridge name to the channel it worked fine.

Sorry for the dummy question. But do you know where can I read something about the MQTT actions and what I can do with them? A short google search did not help much.

:slight_smile:

This is only one way to do this. You can also define the bridge and thing in different lines:

bridge.things

Bridge mqtt:broker:broker “MQTT Broker: Mosquitto” [ host=“192.168.2.1”, port=1883, secure=false]

other_things.things

Thing mqtt:topic:miTemp (mqtt:broker:broker) {
Channels:
    Type number : tempObyvak “Air Temperature” [ stateTopic=“sensor/teplota/obyvak”]
}

(as also posted here: MQTT Generic Thing: java.lang.Exception: No MQTT client - #5 by Ales_Macoun)

1 Like

I was typing up a convoluted response to explain this. Yours is much more concise. Response trimmed, cheers!

You can read about rules here. MQTT actions are used within custom rules to send commands. For instance:

rule "<RULE_NAME>"
when
    <TRIGGER_CONDITION>
then
    val mqttActions = getActions("mqtt", "mqtt:broker:mosquitto")

    if (Some_Item.state != 0) {
        mqttActions.publishMQTT("cmnd/sonoff-pow/POWER", "ON")
    }
end

:slightly_smiling_face:

1 Like

thank you very much for responding, i started with the gui…

i have an ESP8266 (smart plug with energy meter) with espurna firmware an MQTT support

  1. configured a broker connection
  2. configured generic mqtt thing

as far as good, i do not get my switch item updated, may be you may help once again, in my item file i had:

{mqtt="

[openhab:avatar-plug2/relay/0/set:command:*:default],
<[openhab:avatar-plug2/relay/0:state:MAP(onoff.map)]
"}

the command direction is working, get the state does not work… i think is related to the mal i will dive into …

thanks in advance

Lars

I am also experiencing the same issue. I have a device that accepts upper or lower case on/off as command, but returns only lowercase as state: on or off.
With the old binding, I guess I used the same transformation as you did (MAP() ) to translate upper- to lowercase and vice versa.
The new binding seems to ignore my attempts with “transformationPattern” and also with on=“on” as the switch state is never updated to on. When using the OH app or web interface, i can toggle the device on and off, if I do not update the page/app in between (the switch changes to the on position, but the icon does not show the on state; refreshing resets the switch to off). So I know, that the commands are sent correctly.
@David_Graeff do you know about this behaviour?

Edit: as the item state does not change, rules based on this are also no longer executed.

The sonoff firmware uses two distinct mqtt topics to report the state. Are you sure you are subscribing to the correct one? (Use any mqtt client to verify)

i could not get it working with ma(). I used the extend menu (show more) in channel definition, there i could pass my values for on and off. now they state gets updated…

Thanks again. Unfortunately I needed to switch bach to openHAB 2.3. 2.4 was totally unstable in my environment, Not because MQTT. In got in general, exceptions over exceptions and on this morning nothing works anymore… :-(.
Back to 2.3 I have a totally clean log… I hope there will be some fixes soon.

Regarding your “totally unstable in my environment”, I had just that until I removed entries in * /var/lib/openhab2/config/org/openhab/addons.config which were not needed anymore ( in my case binding mqtt1 and action mqtt) .
Consider doing that!

openHAB 2.4 in a fresh environment works without any errors in the log. You might want to backup your user data, do a clean install and move your custom files and paperui json files back.

Thanks for the hints! I will consider doing a fresh installation when I have more time and patience. I just did this a few weeks ago when I switched to Debain Stretch…
Currently I am happy with 2.3. No problems at all! It was only a lot of stupid clicking to delete over 80 devices in Alexa and install them again. First for 2.4 and than for 2.3 again… :wink:

@Jürgen: My proplems are not coming from MQTT. There is a problem with my Homematic rollershuters in the sitemap. It crashes in kind of a loop and more and more homematic erros occur.

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.