Payload Condition in channel trigger

Hello all,

Trying to configured a channel trigger on the mqtt broker so that it triggers when a specific event is received

The event that needs to serve as a trigger is a single push of a zigbee button coming through MQTT
Here is the message

'zigbee2mqtt/0x00158d0006ffd89c', payload '{"action":"single","battery":100,"click":"single","linkquality":30,"voltage":3145}'

In the trigger channel screen I don’t know how to capture the “action”:“single” value from the payload. I believe the payload condition seems to be a fit however I am not sure what to put in there. I tried single, action:single but nothing worked

The trigger works when I only put the topic as shown below

Open the Advanced options, then scroll down to “Transform Values”.

As you can see in the example, you can apply a JSONPATH transformation to the incoming message (you’ll need to install JSONPATH if you haven’t already done so).

This will isolate “single” as the incoming message, which you can then use in the payload to trigger the switch. However, I haven’t personally tested if that works.

Hello Russ,

There is no advanced options in the MQTT broker channel trigger page as you see in my screenshot. This is when you configured a trigger channel on a thing. I can see the transformations there but I don’t see how can this capture the signle condition I want to trigger channel to use which is “action”:“single” in the payload.
As far as I understand this is just to modify the incoming payload to something else

Any ideas ?

Hang on, are you trying to add a channel to the broker? If so, that’s not how it works.

The MQTT broker is just there to serve as a bridge and provide the connection. Once you’ve set it up, you need to add a Generic MQTT THing for your specific device.

That’s where you’ll add channels.

Sorry, I missed your earlier reference to the broker.

These are of fairly limited utility, with all or nothing functionality.

You can capture MQTT messages to topic xx where the payload matches a predefined string, don’t think that helps as it is a full match intended to see “online” for example.

Do as @rpwong says, create a Generic topic Thing and set up a channel with any transformation you like. Use trigger option to make it generate an openHAB event instead of the usual Item update.

Yes, that is exactly what you asked for.
{"action":"single","battery":100,"click":"single","linkquality":30, ... etc
for which JSONPATH is the purpose made tool.

thanks @rossko57

OK I know that in the guide it says that trigger channels on MQTT broker should rarely be used but that’s the only place I saw that I could do what I wanted.
I can manipulate the payload with JSON as you correctly described but what I really wanted is to distinguish between “action”:“single” that corresponds to a single push of a button and “action”:“double” that corresponds to a double push of the button.

This is where I got stuck.I found the section in the MQTT broker trigger channel page very relevant since it has this Payload Condition parameter but I never figured out how to use it (if there is any use for it). The trigger works fine by the way, just wanted to distinguish between those two values

Well, as described so far it’s a way to generate openHAB events with event payload single or double or banana or whatever is sent. It’s the more generally useful way to go about this.
You may then choose which payload to trigger from in a channel triggered rule, or trigger from any and examine the payload in the rule body.

If you simply want to ignore any messages unless they contain "action":"single" use a REGEX filter/matcher.

Actually you can add Channels to the Broker. You would do so in just this case, where you want to trigger an event (think the Astro event Channels) instead of link it to an Item.

You need to add a Separator Character, something like “#”. Then in your rule that triggers from the channel you can get both the topic and the message using event.event. That will be a String <topic>#<message> so you can split that String to get at the message.

Unfortunately there is no way to transform the message in this type of Channel so you’ll have to parse that payload message in a rule. If the message were always the same you could use the Payload Condition but I see a battery level as part of the message and that will change over time.

Or, as has been recommended you can use a regular old Generic Thing where you can use the JSONPATH transformation to extract the value and link that to a Switch.

1 Like

Reminder; a channel of a regular generic topic Thing may be configured to provide openHAB events (instead of state updates) by use of channel trigger option.
All the usual transformations may be applied to incoming MQTT message to produce event payload.

Does that only exist on Switch type Channels? I do not see that option in any of my Generic MQTT Thing Channels, but I also don’t have any switch type Channels.

No idea; trigger is supposed to be selectable for all channels

but is maybe missing from GUI, although that should have been sorted in OH2

Perhaps they moved trigger Channels to only exist in the Broker? If I recall, the ability to add trigger Channels on the Broker Thing was something added around 2.5.6 timeframe. Maybe the trigger flag was removed from Generic Thing Channels at that point.

That would make little sense. Reading David’s old note more closely, he has a PR to fix documentation (where trigger is plainly described to this day) but not for fixing the binding ‘stuff’ (XML I think?) that describes it for GUI.

Trigger on generic channel is exactly suited for this purpose, button clicking.

EDIT - ah, here we go, revisted just 9 days ago maybe?

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.