so, here we go.
I’ll show you how to configure it via files which suits me better, but you can indeed do it in PaperUI GUI if you like as well.
- configure your MQTT Broker in OH
/conf/things/mqtt-broker.things
Bridge mqtt:broker:home "Mosquitto MQTT Broker" [
host="IP",
secure=false,
port=1883,
qos=0,
retain=false,
clientid="somerandomstring",
//certificate="",
//certificatepin=false,
//publickey="",
//publickeypin=false,
keep_alive_time=30000,
reconnect_time=60000,
//lastwill_message="",
//lastwill_qos=1,
//lastwill_topic="",
username="",
password=""
]
- configure your switch (let’s asume it’s Tasmota)
/conf/things/switches.things
Thing mqtt:topic:WallSwitchDressroom1 "WallSwitch Light Dressroom" (mqtt:broker:home) @ "Dressroom" {
Channels:
Type switch : switch "Dressroom Lights" [ stateTopic="home/dressroom/light/1/stat/POWER", commandTopic="home/dressroom/light/1/cmnd/POWER", on="ON", off="OFF" ]
Type string : wifi-ssid "Wifi SSID" [ stateTopic="home/dressroom/light/1/tele/STATE", transformationPattern="JSONPATH:$.Wifi.SSId" ]
Type string : wifi-rssi "Wifi RSSI" [ stateTopic="home/dressroom/light/1/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
Type string : uptime "Uptime" [ stateTopic="home/dressroom/light/1/tele/STATE", transformationPattern="JSONPATH:$.Uptime" ]
Type string : time "Time" [ stateTopic="home/dressroom/light/1/tele/STATE", transformationPattern="JSONPATH:$.Time" ]
Type string : devicestate "Device State" [ stateTopic="home/dressroom/light/1/tele/LWT" ]
}
Thing mqtt:topic:WallSwitchDressroom2 "WallSwitch Light Dressroom" (mqtt:broker:home) @ "Dressroom" {
Channels:
Type switch : switch "Dressroom Lights" [ stateTopic="home/dressroom/light/2/stat/POWER", commandTopic="home/dressroom/light/2/cmnd/POWER", on="ON", off="OFF" ]
Type string : wifi-ssid "Wifi SSID" [ stateTopic="home/dressroom/light/2/tele/STATE", transformationPattern="JSONPATH:$.Wifi.SSId" ]
Type string : wifi-rssi "Wifi RSSI" [ stateTopic="home/dressroom/light/2/tele/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
Type string : uptime "Uptime" [ stateTopic="home/dressroom/light/2/tele/STATE", transformationPattern="JSONPATH:$.Uptime" ]
Type string : time "Time" [ stateTopic="home/dressroom/light/2/tele/STATE", transformationPattern="JSONPATH:$.Time" ]
Type string : devicestate "Device State" [ stateTopic="home/dressroom/light/2/tele/LWT" ]
}
- configure your items (let’s work with dressroom for now)
/conf/items/dressroom.items
Switch WSwitch_Dressroom1 "Dressroom Lights" <light> (gWSwitch, gLightsHome, gLights, gStoreChange) ["Switchable"] { channel="mqtt:topic:WallSwitchDressroom1:switch" }
Switch WSwitch_Dressroom2 "Dressroom Lights" <light> (gWSwitch, gLightsHome, gLights, gStoreChange) ["Switchable"] { channel="mqtt:topic:WallSwitchDressroom2:switch" }
So this is definition, now, when you publish via NodeRed ON into home/dressroom/light/+/cmnd/POWER ON
both switches will be ON
And indeed OH state will be updated automatically based on MQTT
However this will not do anything when you press button on the switch itself. Here will be handy OH rules or NodeRed rules or Tasmota Group topic, which will trigger button on slave switch whenever needed.
For this take a look in here, I’ve posted it yesterday:
basically you either can use rules in OH or directly in NodeRed which will publish msg into relevant MQTT topic. I do prefer not to use Tasmota group topics, but instead I’m using this:
NodeRed (this is just for a general idea how to put those rules together)
[{"id":"a7769c75.cda58","type":"mqtt in","z":"9d128c8a.994b5","name":"Switch 08","topic":"sonoff-touch-08/stat/POWER","qos":"0","datatype":"utf8","broker":"83323ac5.ab4df8","x":300,"y":4120,"wires":[["134b5b18.61d3e5","88b82873.07df98"]]},{"id":"3a4af89a.3d3d48","type":"mqtt in","z":"9d128c8a.994b5","name":"Switch 09","topic":"sonoff-touch-09/stat/POWER","qos":"0","datatype":"utf8","broker":"83323ac5.ab4df8","x":300,"y":4220,"wires":[["88b82873.07df98","134b5b18.61d3e5"]]},{"id":"a2bb607f.6bd8a","type":"change","z":"9d128c8a.994b5","name":"08","rules":[{"t":"set","p":"status08","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":4120,"wires":[[]]},{"id":"134b5b18.61d3e5","type":"switch","z":"9d128c8a.994b5","name":"08s","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"status08","vt":"flow"},{"t":"neq","v":"status08","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":4120,"wires":[["a2bb607f.6bd8a"],["a2bb607f.6bd8a","48747ed4.c73b2"]]},{"id":"88b82873.07df98","type":"switch","z":"9d128c8a.994b5","name":"09s","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"status09","vt":"flow"},{"t":"neq","v":"status09","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":4220,"wires":[["aacb9062.c6922"],["aacb9062.c6922","27d97c2.8192d84"]]},{"id":"aacb9062.c6922","type":"change","z":"9d128c8a.994b5","name":"09","rules":[{"t":"set","p":"status09","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":4220,"wires":[[]]},{"id":"48747ed4.c73b2","type":"mqtt out","z":"9d128c8a.994b5","name":"to the 08","topic":"sonoff-touch-08/cmnd/POWER","qos":"","retain":"","broker":"83323ac5.ab4df8","x":700,"y":4160,"wires":[]},{"id":"27d97c2.8192d84","type":"mqtt out","z":"9d128c8a.994b5","name":"to the 09","topic":"sonoff-touch-09/cmnd/POWER","qos":"","retain":"","broker":"83323ac5.ab4df8","x":700,"y":4260,"wires":[]},{"id":"83323ac5.ab4df8","type":"mqtt-broker","z":"","name":"MQTT","broker":"IP","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
I’m pretty sure you can do it as you originaly posted, but it’s unnecessary as you already have all needed informations from/in mqtt. And OH will update self based on those informations.