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

  • Platform information:
    • Hardware: Raspberry Pi

    • OS: _what OS is used and which version_R

    • openHAB version: 2.4.0

  • Issue of the topic: I have the following:
  • Sonoff Basic DIY with Tasmota flashed.

  • MQTT configuration on Sonoff Tasmota updated.

  • MQTT broker installed in things on OpenHab and Online

  • In Configuration / Services I can also see " MQTT Embedded Broker (org.eclipse.smarthome.mqttembeddedbroker) available.

  • I want to add the Sonoff switch and have it visible in the Paper UI but via the config files (Items, things or maybe both needed?) but I am not sure what code to add in these files.

  • Once this is available, I would like to add this to a rules file where I can read the state of the added Sonoff and also send commands to it if needed but also I am not sure what to add.

  • I have the Topic of the sonoff that I use Sonoff_BBB and I am able to add this as item and thing via the
    MQTT things bindings and Generic MQTT Thing (manually) but I would like to have those only created via the config files in order to have better control and expand the items / things in the future.

PS: yes I’ve installed Mosquitte when installing openHab on the PI but I dont think it’s in use (unless it’s the embedded one) and yes my broker is online and tried MQTT.fx to connect to it etc.

Please stay simple and give me a brief example.
I appreciate your help in advance

Did you try the search function? Searching for " sonoff tasmota mqtt files" I get this thread.
Your description is unclear, what mqtt broker did you install. You need EITHER the embedded mqtt broker OR mosquitto!
Additionally you need a broker thing (which acts as bridge between the mqtt broker and openHAB). It sounds as if you migth have that already.

Once you have setup mqtt things and linked items ( either via file or via via PaperUI) they will show on PaperUI!

EMbedded brocket
and yes as decribed above I have the MQTT broker installed in things.
Do I need to search in it after inputting the code ? I estimate that it should be automatically generated from the config files

If you have the broker thing setup (this one does not need any channel), you can create generic mqtt things for your devices. They need the mqtt broker thing as the bridge and do need the creation of channels. No things will be created automatically!

I have the following in the items file and the related group is created under items and inside it 2 items

Group FF_Sonoff_B1 “Sonoff B1” <sonoff_b1> (Sonoff_B1)
String FF_Sonoff_B1_Reachable “Reachable: [%s]” (FF_Sonoff_B1) { channel=“mqtt:topic:sonoff_test:reachable” }
Switch FF_Sonoff_B1_Power “Power” (FF_Sonoff_B1) { channel=“mqtt:topic:sonoff_test:power” }

The related switch is not present though on the control in PaperUI nor in classic UI.

Any hints?

Did you create the “sonoff_test” thing?

I am using the following code in the Things file:

Bridge mqtt:broker:mqtt “Mosquitto” [ host=“localhost”, port=1883, secure=true, username=“mqtt”, password=“PASSWORD”, clientID=“JS1” ]
{
// Sonoffs

Thing topic sonoffb1 "Sonoff B1" @ "Some 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" ]

}

Thanks for the help

I can only create it via paperUI and create the channel then state and command topic or can I do it in the things file?

I preferably want to do it via the things file

I have a doubt regarding the following as embedded broker is used and not mosquitto:

Bridge mqtt:broker:mqtt “Mosquitto” [ host=“localhost”, port=1883, secure=true, username=“mqtt”, password=“PASSWORD”, clientID=“JS1” ]

You can do it via files. It wasn’t clear that you are using files already.

I can not say wether you have more then one mqtt broker running, you need to check that yourself. What did you install?

In the Services I have

In the things, I have:

52%20PM

when first installing openhab on PI, I’ve installed Mosquitto from SSH configuration but I dont think it’s configured

When I add a chennel to the SOnof_Code with the following in the configuration:
stat /sonoff_test/power and cmnd/sonoff_test/power the MQTT thing will become offline saying No MQTT client

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