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

@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?

25%20AM

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:

28%20AM

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

22%20AM

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

58%20AM

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)

00%20PM

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.

21%20AM

ANd the broker is in a separate file
06%20AM

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:

39%20AM

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):

58%20PM

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

any hints?

Did you try the syntax for separated files as posted by @kriznik early in this thread?
If yes, what did the logs show?
Anyhow, we all can’t keep track what your actual settings are. Without you posting the contents of your actual .things files (only the formatted contents, not screenshots!!) we are unable to give usefull guidance!

@Jean_Saifi please take a deep breath and read this post once again.
in there you have ALL you need to get this working properly

there is broker, there is thing example and item example, please make sure you are following syntax and naming…
good luck

1 Like

Deep breath helped,

All online, Sonoff things, Channels and rules working great.

@kriznik thank you

glad I helped, m8