MQTT v2 -> subscribe to topic *and* getting topic names

I’d like to use MQTTv2 as a kind of mqtt-eventbus replacement. The docs are a bit low on examples and the forum is a bit confusing.
What I’d like to have:

  • subscribing to mqtt topics
  • getting the sent values
  • getting the topic to update an item

I know, I could use this on an item-based configuration, but I like the idea laid out in:

Problem is: it doesn’t work as intended… :wink:

my things:

Bridge	mqtt:broker:synology	"MQTT-Synology"	[host="192.168.x.y", port=1883, secure=false, clientID="OH2Utilities", qos=1 ] 
	// subscribing
		Type	publishTrigger : MQTT_TriggerOHMainState	"MQTT-Eventbus OHMain receive"		[ stateTopic="openHAB/OH2Main/#", seperator="#" ]

	// publishing
	Thing  mqtt:topic:Comfoair	"die ComfoAir Topics" (mqtt:broker:synology)  @ "Technikraum"  {                         
			Type    number : MQTT_Comfoair_Filterperiod	"MQTT_ComfoAir Filterperiode"	[ stateTopic="openHAB/OH2Utilities/Comfoair_Filterperiod/state", commandTopic="openHAB/OH2Utilities/Comfoair_Control/command"]
			Type    number : MQTT_Comfoair_Fan_Level	"MQTT_ComfoAir Lüfterstufe"		[ stateTopic="openHAB/OH2Utilities/Comfoair_Fan_Level/state", commandTopic="openHAB/OH2Utilities/Comfoair_Fan_Level/command"]

my rule

rule "Receive all"
	Channel "mqtt:broker:synology:MQTT_TriggerOHMainState" triggered
	//The receivedEvent String contains unneeded elements like the mqtt topic, we only need everything after the "/" as this is were item name and state are
	logInfo("MQTT OHMain", receivedEvent.getEvent())
	//val parts1 = receivedEvent.toString.split("/").get(1)
	//val parts2 = parts1.split("#")
	// sendCommand(parts2.get(0), parts2.get(1))

If I send a item-name to openHAB/OH2Main/# with a value, I only get the value:

2020-11-26 14:47:15.418 [vent.ChannelTriggeredEvent] - mqtt:broker:synology:MQTT_TriggerOHMainState triggered test
2020-11-26 14:47:15.428 [INFO ] [e.smarthome.model.script.MQTT OHMain] - test

So I never get the topic of the item, I send…? Is there a something I missed?

@rlkoshak has already made this:

1 Like

still, in the docs it says:

The event payload (in receivedEvent) will be the received MQTT topic and its value, separated by the hash character (#).

so I guess it’s a bug? or did i miss some configuration option?

		Type	publishTrigger : MQTT_TriggerOHMainState	"MQTT-Eventbus OHMain receive"		[ stateTopic="openHAB/OH2Main/#", seperator="#" ]

after reading this:

I did configure the Broker via PaperUI for once and now it worked, so I guess, despite me having Latin in school i misspelled separatorand seperator doesn’t work…
Working PaperUI configuration: note the “#” in the “separator character” part

and my .thing file also works with that:

		Type	publishTrigger : MQTT_TriggerOHMainState	"MQTT-Eventbus OHMain receive"		[ stateTopic="openHAB/OH2Main/#", separator="#" ]
1 Like

You set it up as a thing channel. In paper ui you set it up as a bridge channel so it should work.