Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding

No and actually i dont have a switch in paper ui, cause i dont have a functionally config.

Copy as much you need from my config and you will have a working config!
I would start of with a single device!

Why? Random combinations won’t help.
Understand how it works, and you can make the correct settings.

Let’s do the easy part

Here the channel name mqtt:topic:sonoffcorin1:power that you give needs to match the channel name that you set up in your your Thing.

The channel name is built from two parts.
First part is in your topic Thing. mqtt:topic:sonoffcorin1
Last part is the name you give to your switch type channel, power
Put them together and of course you get
mqtt:topic:sonoffcorin1:power
which is what you put into your Item definition.
mqtt:topic:sonoffcorin1:Power for an example, does not match and will not work.

So, make sure your Item channel name matches your Thing name and then leave that part alone.


getting the MQTT topics sorted out is essentially the same idea.

Here, the stateTopic is the MQTT topic that openHAB listens for and uses to send a state update via the channel to your Item
That means that your Sonoff ought to report its status out using topic buero/sonoffcorin1/POWER
Does it? We can’t see from here, you need to look in your Sonoff settings.

Then the commandTopic is what openHAB uses to send out commands. That means that your Sonoff needs ro be listening to the topic buero/sonoffcorin1/POWER and use the message as a command.
Does it?

Certainly one or both of these are wrong because they would not be the same. Find out what your Sonoff is doing, and make your Things match.

1 Like

@corin_corvus there was once an advertisement of IBM on television were the 5 year old son said to his dad he should thirst plug in the power.

With this in mind my suggestion is again cut your problem in pieces:

  • Keep in mind that case sensitive can be your enemy!

  • goto the IP address of your Sonoff and verify the MQTT settings (as suggested by @rossko57)

  1. your topic is likely “sonoffcorin1” (in my further example “Sonoff1”)
  2. Full topic should remain untouched: “%prefix%/%topic%/”
  • Forget for a moment OH and go to your MQTTbox (or what you prefer to listen/publish to MQTT)
  1. add a topic to publish: cmnd/Sonoff1/Power
  2. add a topic to subscribe: stat/Sonoff1/#
  3. you allready subscribe to: tele/Sonoff1/#
  • all set? publish payload “1” or “0”
  • play with it, see what happens
  • Only if you can switch your sonoff you may continue to OpenHAB

The correct syntac off the channel in thing is:

    Type switch : power          [ stateTopic="stat/Sonoff1/POWER",  commandTopic="cmnd/Sonoff1/Power"]

And I am using the following item:

Switch whatever_item  "whatever text"  { channel="mqtt:topic:Sonoff1:power" }

But I am already repeating myself, @rossko57, @kriznik and others.

BTW when OH introduced the MQTT things some time ago we all needed to RTFM to change our configuration and make it work again. This was not painless and sometimes we needed help. Most of us are willing to help but I hope you reached the point you have enough information :wink:

1 Like

without your mosquitto output (which does not need OH) we can’t help you.
This is clearly an issue with wrong topics and so on in OH nothing really can happen.

So step number 1: get into your MQTT broker and actually determine which topics is your device publishing to.
step number 2, correct your OH by knowledge from step 1

:slight_smile:

my setup: (you have to know IP of your device and open http://youdeviceip/ in your browser!)
SONOFF: → Configuration → MQTT

topic: home/workroom/light
fulltopic: %topic%/%prefix%/ 

OH my thing:

Thing mqtt:topic:WallSwitchWorkroom "WallSwitch Light Workroom" (mqtt:broker:home) @ "WorkrRoom" {
Channels:
    Type switch : switch "Workroom Lights" [ stateTopic="home/workroom/light/stat/POWER", commandTopic="home/workroom/light/cmnd/POWER", on="ON", off="OFF" ]
    Type string : wifi-ssid     "Wifi SSID"     [ stateTopic="home/workroom/light/tele/STATE", transformationPattern="JSONPATH:$.Wifi.SSId" ]
    Type string : wifi-rssi     "Wifi RSSI"     [ stateTopic="home/workroom/light/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
    Type string : uptime        "Uptime"        [ stateTopic="home/workroom/light/tele/STATE", transformationPattern="JSONPATH:$.Uptime" ]
    Type string : time          "Time"          [ stateTopic="home/workroom/light/tele/STATE", transformationPattern="JSONPATH:$.Time" ]
    Type string : devicestate   "Device State"  [ stateTopic="home/workroom/light/tele/LWT" ]
} 

use it as reference, as I changed Full Topic in my sonoff device, i do have cmnd/stat/tele at the end. Which suits my needs better.
Your config may vary, but … nothing really major.

2 Likes

Your Thing solve my problem.
Thanks.

Hi @epicurean,

Do you fix this error:

Error during the execution of rule ‘Sonoff Maintenance’: Instance is not an MQTTActions class.

I’ve this error in the rules.

Best Regards,
Fernando Gomes

I think I overcome that. I have updated my maintenance rule to to that suggested in the tasmota wiki page

You’ve the same error?