New MQTT 2.4 Channel based triggers how to link?

I am trying to link two OH systems using MQTT and the new v2 MQTT binding.
Specifically I have items in the source system that have event trigger channels, for example when the paddle on a light switch is tapped it triggers a channel event “ON”.

I know how to link items to MQTT but how do I link a channel trigger to MQTT? Since there is no item definition, there is nowhere to link a channel trigger to a channel on an MQTT thing.
I know I could do this with rules but that would require creating a dummy item, linking the dummy to the MQTT channel then writing a rule to capture the channel trigger event, and command the dummy item. Messy and time consuming to set up.

Also, on the other end, the OH instance that will consume the MQTT events, I see how I can add an event trigger channel to a broker but this makes no sense to me since the event is clearly a ‘property’ of a specific thing.
For example, in addition to raising events when a paddle is pressed on a light switch, the light switch also reports it’s state linked to a standard item. On the consumer instance I set up a topic representing the light switch and add a channel to consume the status updates, but as far as I can see I cannot add an event trigger ‘type’ channel to this topic thing. Instead I would have to add all of these triggers to the base broker which will be very messy and fragments the channels that are all actually part of the same base thing.
How do I add an event trigger channel to an MQTT topic to avoid this mess?

So really two questions in one. Thanks in advance.

For the receiving side

Just add a normal channel to your Generic MQTT Thing and tick the checkbox “Is trigger”. The channel will send trigger events from there on, instead of updating items.

For the sending side

Not possible without a rule unfortunately. openHAB is not prepared to “route” a trigger event directly to a channel.

I added a ‘Text value’ channel but I can’t see an “Is Trigger” check box. I assumed (maybe incorrectly) that by ‘normal’ channel you meant any channel type?

Also, I prefer to configure everything via files. Do you have an example of a .things file with a trigger channel?

Ah, that is a shame, but I understand. Thanks for the fast reply btw!

Nope, I don’t use files.

Hm, shame on me. It is not even part of the latest documentation (not yet published I guess):

Looking at the code smarthome/extensions/binding/org.eclipse.smarthome.binding.mqtt.generic/src/main/java/org/eclipse/smarthome/binding/mqtt/generic/internal/generic/ChannelConfig.java at master · eclipse-archived/smarthome · GitHub
it seems that you have to set “trigger” to “true”.

Apparently I forgot to add that to the UI description file and the documentation. Interesting.

FYI:
https://github.com/openhab/openhab2-addons/pull/4734

Thanks! Got it working. For any future readers, here is my .things file:

Bridge mqtt:broker:mqttBroker [ host="192.168.x.x", secure=false ]
{
	Thing topic mqttTest "mqttTest" {
		Channels:
			Type switch : mqttSwitch "MQTTSwitch" [ stateTopic="MQTTSwitch/State", commandTopic="MQTTSwitch/Command" ]
			Type switch : mqttTrigger "MQTTTrigger" [ stateTopic="MQTTSwitch/Trigger", trigger=true]
	}
}

Log file output when publising hello world to topic “MQTTSwitch/Trigger”:

[vent.ChannelTriggeredEvent] - mqtt:topic:mqttBroker:mqttTest:mqttTrigger triggered hello world

@David_Graeff an innocent question: Looking at the documentation you linked, I was interested to see an example .things file showing how to add a ‘publishTrigger’ Type channel to a broker Bridge.
Having added a “trigger” channel to my topic thing I am left wondering why not allow the publishTrigger type as a channel type of a topic Thing?
Wouldn’t this remove the need for the “trigger” property?
Also, it would correctly render the channel as a channel-based trigger (grey icon, unlinkable) in Paper UI vs the current that shows as a standard (blue) ‘linkable’ channel but behaves like a channel-based trigger.

2 Likes

I ended up exactly the same place as @mcqwerty for a somewhat different use case. I am adding wall switches to my setup through zigbee2mqtt, and need the press on the wall switch to end up in a trigger channel.
It seems very strange that we can not handle trigger channels somehow more directly. @David_Graeff, please consider adding this in an upcoming version :slight_smile:

That’s already in :smiley: I can’t help the fact that oh releases only every 6 months ^^

2 Likes