Binding sonoff with MQTT

Platform information:

  • Hardware: Resp pi 4
  • OS: openhabian 2.5.1

Hi All
I’m trying to bind a sonoff device to openhab with mqtt.
There are lots of posts on the net and I am kind of lost in the forest of the information…
I would be more than appreciate if someone can light my way…

My current state:
I flashed Tasmota on sonoff basic module.
The module is up and running and I can access it by the IP address.
Via paper UI I installed

  1. MQTT Broker Moquette
  2. MQTT Binding


I can see in “Things” the MQTT Broker online.
I also can see the broker via MQTT.fx software.
I can send commands ON and OFF to the sonoff via MQTT.fx.

I configured the mqtt configuration as follow:

I put at the host IP the IP of the Resp Pi - is that correct?
I put at the client “openhab2” - is that correct?
What should I put at the rest of the fields?

In the item.things I created a bridge:

Bridge mqtt:systemBroker:embedded-mqtt-broker "MqttBroker" [ host="localhost", port=1883, secure=false , clientID="openhab2"/* username="", password="", clientID="openHAB2"/*/ ]
    Thing mqtt:topic:sonoffbridg {
        Type switch : PowerSwitch  [ stateTopic="stat/sonoff1/POWER" , transformationPattern="JSONPATH:$.POWER" , commandTopic="cmnd/sonoff1/POWER", on="ON", off="OFF" ]

I added an item:

Switch Sonoff1 "Sonoff1"  { channel="mqtt:topic:sonoffbridg:PowerSwitch" }

I am sure that I am doing something wrong as the switch is not changing the module state.

Can anyone share with his knowledge?

Thanks a lot,


Nope. A systemBroker is for managing embedded broker. It will not handle traffic to/from remove MQTT devices.

Make a regular broker Bridge Thing

Thanks a lot !
Now I am able to send commands to the sonoff!!
But for some reason I don’t get any feedback on OH when switching the module.
In the logs I get:

Executing the JSONPATH-transformation failed: Invalid path '$.POWER' in 'OFF'

Any idea?

FYI, the embedded broker is no longer supported and most will recommend to use mosquitto. Mosquitto can be installed via openhabian-config tool.

You may not need the transformation, give it a try without it. Below is an example of one sonoff device I have that works fine.

Thing topic sonoff2 "Couch Light" @ "Couch Light" {
//    Channels:
//        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
//    }

The // are where I have commented this out and moved to creating my Things via PaperUI and use files for items. This is also the recommended way for most users.

I removed it and it’s working!
Thanks a lot!

How do you create things via paper UI? Through the inbox?
BTW I am sorry that I can’t mark your post as a solution as the first problem solved by someone else. I should have open new thread:(