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…
my things:
Bridge mqtt:broker:synology "MQTT-Synology" [host="192.168.x.y", port=1883, secure=false, clientID="OH2Utilities", qos=1 ]
// subscribing
Channels:
Type publishTrigger : MQTT_TriggerOHMainState "MQTT-Eventbus OHMain receive" [ stateTopic="openHAB/OH2Main/#", seperator="#" ]
}
// publishing
Thing mqtt:topic:Comfoair "die ComfoAir Topics" (mqtt:broker:synology) @ "Technikraum" {
Channels:
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"
when
Channel "mqtt:broker:synology:MQTT_TriggerOHMainState" triggered
then
//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))
end
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?
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