Add Sonoff Basic (Tasmota) to Things, Items and Rules using config files and MQTT

Tags: #<Tag:0x00007f745fe30910> #<Tag:0x00007f745fe30578> #<Tag:0x00007f745fe30168>

and the bridge in config is as follow:

only when adding / configuring the channel it becomes offline

Don’t mix setup via PaperUI and files!

1 Like

Sure you are right!
Any hints on the things code?
but I keep the MQTT broker as a thing in the UI or the code is enough?

Why don’t you have a look onto this documentation page. It is for the 2.4 Version and shows how to Setup the MQTT Broker Thing and MQTT Generc Thing in a file (scroll down to the end).
Note: Your used version of the MQTT binding has a bug, whenever you change the setting of the MQTT Things you need to restart (either only the MQTT Bundle or openHAB). That migth explain why your things go offline when creating a channel.
I am using this Version as well!

@Jean_Saifi
I’ve posted it here

1 Like

Thank you @kriznik I will give it a try. Good idea!

I will still have to install the MQTT binding in paper UI right?

Yes, but doing it via the addons.cfg is also possible

@kriznik @opus
Hello,

I managed to change addons.cfg and it install the biding.

I’ve created a mqtt.thing file with this in it. Shouldnt create an MQTT broker thing for me automatically in the paper UI?

Also, I use mqtt.fx to simulate the broker (?) with the below settings and user name and password but when I subscribe, it can see the sonoff device I have (with tasmota) but can’t send commands:

As you can see, the status is online when I subscribe and the sonoff_test is present

I managed only to send command from the IP link of the Tasmotta page console and it worked.

Getting close…thanks

Yes, such created Broker Thing should be visible on PaperUI, as any other Thing created by file, however you can’t CHANGE then via PaperUI.
The screenshot doesn’t show the end of the file, I’m missing the closing ].

1 Like

when working with files, it’s always good practise to have /var/log/openhab/openhab.log tailed so you’ll see if you have any errors in your files

2 Likes

@kriznik @opus Solved now.

Thank you guys.

A restart was needed also, log is running in a new tab with OpenHab, I’ve created the things and it went online then decided that the best was create the Items using the Rest API from VS Code by automatically generating the items ( I can develop this if anyone needed)

separate your broker from other things, because when you have it like that -> any change in that file will lead to mqtt broker connection restart

@kriznik Ideally its the right thing to do but when I tried to split it I received the following in the log:

2019-09-14 08:38:36.930 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘Sonoff.things’

2019-09-14 08:38:37.019 [WARN ] [.thing.internal.GenericThingProvider] - Thing topic does not have a bridge so it needs to be defined in full notation like :topic:sonoff_Mini

in the separate thing files I have:

Thing topic sonoff_test “Sonoff_test” @ “Living_Room”
{
Channels:
Type string : reachable “Reachable” [ stateTopic=“tele/sonoff_test/LWT” ]
Type switch : power “Power” [ stateTopic=“stat/sonoff_test/POWER”, commandTopic=“cmnd/sonoff_test/POWER” ]

}

Thing topic sonoff_Mini “Sonoff_Mini” @ “Living_Room”
{
Channels:
Type string : reachable “Reachable1” [ stateTopic=“tele/sonoff_Mini/LWT” ]
Type switch : power “Power1” [ stateTopic=“stat/sonoff_Mini/POWER”, commandTopic=“cmnd/sonoff_Mini/POWER” ]

}

I tried also:

Thing mqtt:broker:home:topic:sonoff_Mini etc. and I got the following:

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

2019-09-14 08:38:37.921 [hingStatusInfoChangedEvent] - ‘mqtt:broker:home:topic:sonoff_test’ changed from UNINITIALIZED to UNINITIALIZED (HANDLER_CONFIGURATION_PENDING)

Maybe as syntex with the definition outside the main MQTT thing file?

just create a file under things called bridge.things and put this into it

Bridge mqtt:broker:home "Mosquitto MQTT Broker" [ 
  host="xx.xx.xx.xx",
  secure=false,
  port=1883,
  qos=0,
  retain=false,
  clientid="someid",
  //certificate="",
  //certificatepin=false,
  //publickey="",
  //publickeypin=false,
  keep_alive_time=30000,
  reconnect_time=60000,
  //lastwill_message="",
  //lastwill_qos=1,
  //lastwill_topic="",
  username="",
  password=""
]

How does your things file then look?

Your syntax of the mqtt-things file is wrong. When seperating the broker from the other things they need a way to know which bridge (broker) to use. @kriznik posted a link above where he showed how to do that.

Only when I split the Sonoff things definition into a new file this happens.
Here is the current situation.

ANd the broker is in a separate file

and the sonoff.things have this code

Thing mqtt:topic:sonoff_test “Sonoff_test” @ “Living_Room”
{
Channels:
Type string : reachable “Reachable” [ stateTopic=“tele/sonoff_test/LWT” ]
Type switch : power “Power” [ stateTopic=“stat/sonoff_test/POWER”, commandTopic=“cmnd/sonoff_test/POWER” ]

}

Thing mqtt:topic:sonoff_Mini “Sonoff_Mini” @ “Living_Room”
{
Channels:
Type string : reachable “Reachable1” [ stateTopic=“tele/sonoff_Mini/LWT” ]
Type switch : power “Power1” [ stateTopic=“stat/sonoff_Mini/POWER”, commandTopic=“cmnd/sonoff_Mini/POWER” ]

}

The log shows this:

There is still nothing there to tell openHAB that this Thing has anything to do with the broker you defined elsewhere as mqtt:broker:home

You need an extra bit in round brackets pointing at the broker Thing, and I think you need to refer to it in this Thing’s UID as well.

Thing mqtt:topic:home:sonoff_test “Sonoff_test” (mqtt:broker:home) @ “Living_Room”
1 Like

I am getting the below when using your convention in the code (last two messages):

Even though I split the files as instructed @kriznik @opus.

any hints?