Binding 2 sonoff devices on same bridge

Platform information:

  • Hardware: Resp pi 4
  • OS: openhabian 2.5.1

I’m having problem on sending commands after setting up 2 mqtt devices.
For configuration of one item - everything is working good.

The steps I performed:
I flashed Tasmota on two sonoff basic modules.
The modules is up and running and I can access both by the IP addresses.
The mqtt configuration of both items:
First sonoff:

Second sonoff:

Via paper UI I installed

  1. MQTT Broker Moquette
  2. MQTT Binding


In the things file:

Bridge mqtt:broker:5fcd5bfe "MqttBroker" [ host="localhost", port=1883, secure=false , clientID="openhab2"/* username="", password="", clientID="openHAB2"/*/ ]
    Thing mqtt:topic:sonoffbridg  "MQTT Thing: SonOff"
     (mqtt:broker:5fcd5bfe) @ "Living Room"
        Type switch : PowerSwitch  [ stateTopic="stat/sonoff1/POWER"  , commandTopic="cmnd/sonoff1/POWER", on="ON", off="OFF" ]
        Type switch : PowerSwitch2  [ stateTopic="stat/sonoff2/POWER"  , commandTopic="cmnd/sonoff2/POWER", on="ON", off="OFF" ]

In Items file:

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

Now the problem is like that:
When switching on sonoff1 switch - the sonoff2 device is turned on.
When switching on sonoff2 - the sonoff2 device is turned on.
The same problem is when sending commands via MQTT.fx.
BTW - the status is receiving good, if I am turning on the sonoff1 device itself , the sonoff1 switch is turned on.

It seems that sonoff1 device not receiving commands - it only get the device if I am removing the settings of sonoff2.

What am I doing wrong?


Try changing your Tasmota config for each device. Both Devices have the same client name - openhab2, they should be different. Just leave the default values - that is what I did with my devices.

1 Like

The ClientID is definition in the Bridge.
So I need 2 different bridges?

No, the ClientID is defined for each device, go to each Sonoff device’s WebUI and change the ClientID to default value or different values.

By way of explanation, the client ID is used for the device connecting to the MQTT broker.
So openHAB, sonoff-1, and sonoff-2 all need different client IDs

If you re-use client ID the broker will think you are the same box making another connection.

So do I need to define 2 different bridges? Each one with different CilentId?

No. On the Sonoff devices ONLY, change the ClientID of the first one to sonoff1, and the second one to sonoff2 in their respective MQTT settings.

With MQTT there is a broker application sitting in the middle.
Nobody talks directly to each other, they all talk to the broker.
Everybody talking to the broker needs a unique client ID.
openHAB is just another client from the broker’s point of view.
openHAB needs only one connection to the broker no matter how many different topics it wants to listen to or publish.

If it helps, here is a part of my Sonof config file:

Bridge mqtt:broker:mosquitto “Mosquitto” [ host=“localhost”, port=1883, secure=false, username=“USERNAME”, password=“PASSWORD”, clientID=“openHAB2” ]
// Sonoffs
Thing topic sonoff-2250 “Sonoff 2250” @ “Dining Room” {
Type string : 2250-reachable “2250-Reachable” [ stateTopic=“tele/sonoff-2250/LWT” ]
Type switch : 2250-power “2250-Power” [ stateTopic=“stat/sonoff-2250/POWER”, commandTopic=“cmnd/sonoff-2250/POWER” ]
Type number : 2250-rssi “2250-WiFi Signal Strength” [ stateTopic=“tele/sonoff-2250/STATE”, transformationPattern=“JSONPATH:$.Wifi.RSSI”]

Thing topic sonoff-1766 "Sonoff 1766" @ "Dining Room" {
    Type string : 1766-reachable "1766-Reachable"            [ stateTopic="tele/sonoff-1766/LWT" ]
    Type switch : 1766-power     "1766-Power"                [ stateTopic="stat/sonoff-1766/POWER", commandTopic="cmnd/sonoff-1766/POWER" ]
    Type number : 1766-rssi      "1766-WiFi Signal Strength" [ stateTopic="tele/sonoff-1766/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]