MQTT Openhab 2.4, initialize Switches

i need help to initialize an Switch after OH restart, with the new MQTT-Binding (OpenHab 2.4).

A Switch in my old .Items file looks like:

Switch	Schlafzimmer_Beamer			"Beamer"					(GrpSchlafzimmer, GrpSZMultimedia)	["Lighting"]	{mqtt=">[mosquitto:/sonoff/SZMultimedia/cmnd/sonoff_SZMultimedia/POWER2:command:ON:ON],>[mosquitto:/sonoff/SZMultimedia/cmnd/sonoff_SZMultimedia/POWER2:command:OFF:OFF],<[mosquitto:/sonoff/SZMultimedia/stat/sonoff_SZMultimedia/RESULT:state:JSONPATH($.POWER2)],<[mosquitto:/sonoff/SZMultimedia/tele/sonoff_SZMultimedia/STATE:state:JSONPATH($.POWER2)]"}

In the last part of the switch i received the Telemetrie from the Sonoff and Update / Initialized the Switch automatically after an Openhab restart, because the Sonoff will send the Telemetry Data all few minutes.


How can i receive the Telemetry additional to the stat with the new MQTT binding?

As far as I understood you will have to define another channel and additionally link this channel to the same item, would look like:

Type switch : ch1 "Channel 1" [ stateTopic="/sonoff/SZMultimedia/stat/sonoff_SZMultimedia/RESULT", transformationPattern="JSONPATH($.POWER2)", commandTopic="/sonoff/SZMultimedia/cmnd/sonoff_SZMultimedia/POWER2" ]
Type switch : ch1_tele "Channel 1 Tele" [ stateTopic="/sonoff/SZMultimedia/tele/sonoff_SZMultimedia/STATE", transformationPattern="JSONPATH($.POWER2)" ] 

and the item would be something like that:

Switch Schlafzimmer_Beamer "Beamer" (GrpSchlafzimmer, GrpSZMultimedia) ["Lighting"] {
 channel="mqtt:topic:bridge:thingname:ch1", channel="mqtt:topic:bridge:thingname:ch1_tele" }

(given the bridge is named bridge and the thing is named thingname)

EDIT: I’m not sure about the correct channel parameter for incoming value transformation, there is no hint in the documentation yet.

Maybe you should consider to purify your topic :wink:


should suffice. full topic at sonoff would be like


and topic would be


Hi Udo,
i tested your Solution and had Linked a second channel to my Item.

Switch	Schlafzimmer_Beamer			"Beamer"					    <Poweroutlet>   (GrpSZMultimedia)       {channel="mqtt:topic:Schlafzimmer_Steckdosen:BeamerLeinwand",channel="mqtt:topic:Schlafzimmer_Steckdosen:Tele_Beamer_Leinwand"}

unfortunately i have now two Read Only Swiches in the Paper Ui.


I solved this by adding a second telemetry item and a rule:


Switch Schlafzimmer_Beamer "Beamer" <Poweroutlet> (GrpSZMultimedia {channel="mqtt:topic:Schlafzimmer_Steckdosen:BeamerLeinwand"}
Switch Schlafzimmer_Beamer_tele {channel="mqtt:topic:Schlafzimmer_Steckdosen:Tele_Beamer_Leinwand"}


rule "Item Schlafzimmer_Beamer_tele changed"
        Item Schlafzimmer_Beamer_tele changed
        if (Schlafzimmer_Beamer_tele.state != NULL && !Schlafzimmer_Beamer_tele.state.equals(Schlafzimmer_Beamer.state)) {
1 Like

Isn’t it possible to use a second “stateTopic”? IMHO such would work!

Something like:

  Thing topic sonoff_TH_Thing "Light_TH" @ "Sonoff" {
        Type switch : PowerSwitch  [ stateTopic="stat/sonoff_TH/POWER",  stateTopic="tele/sonoff_TH/STATE",transformationPattern="JSONPATH:$.POWER", commandTopic="cmnd/sonoff_TH/POWER", on="ON", off="OFF" ]

That may work but these two state topics stat/sonoff_TH/POWER and tele/sonoff_TH/STATE have different transformation paths ($ and $.POWER respectively), so I’m not sure this exact example will work.

Nope that doesn’t work. Each configuration can be applied once only. Two channels is the way to go.

Paper UI will show both channels, yes. But Paper UI is really bad at presenting controls and is really meant to be used for configuration. Use HabPanel or the Android/iOS apps, they base their presentation on Items, which is the right thing to do.

Your solution with the rule is also viable of course. Just be aware that openHAB slows down a bit with every additional (old style) rule.

now i played around with the Basic Ui and Linked a second Channel at my Switch item.
It works fine for me. Thanks
@David_Graeff and @pussinboots


I ran into nearly the same issue. I found a simple workaround that was suitable for me. I created a rule that sends the “POWER” command without an argument to my Sonoff/Tasmota devices. It looks like this:

rule "Systemstart"
	when System started
		then logInfo("Haus", "--- SYSTEMSTART ---")
			val actions = getActions("mqtt","mqtt:broker:broker")
			actions.publishMQTT("cmnd/sonoff-9D7XXX/POWER1","")		//Licht GWC
			actions.publishMQTT("cmnd/sonoff-9D7XXX/POWER2","")		// LĂĽfter GWC
			actions.publishMQTT("cmnd/sonoff-740XXX/POWER","")		// Licht Hobbykeller

Hope that it is useful :slight_smile:

Kind regards