How to get MQTT Topic in rule triggered by mqtt trigger channel?


Is there a possibility to get the exact mqtt topic that triggered an mqtt channel trigger in a javascript rule?

Why? I just recently introduced Tradfri to my home and I want to write some generic code that sends telegram messages for low battery states or low RF signal of a device in my setup. And I do not want to create dedicated channels for each and every device, when I possibly can make this generic by listening to e.g. zigbee2mqtt/+/battery. But then I’d need to find out what deviceName the + matched.

Thanks, Alex.

In the Event Channel set the “Separator Character”. As the description says

The trigger channel payload usually only contains the received MQTT topic value. If you define a separator character, for example ‘#’, the topic and received value will be in the trigger channel payload. For example: my_topic#my_received_value.

For a Nashorn example of this in use see MQTT Event Bus Subscription [3.2.0;3.4.9] and for a GraalVM example see MQTT Event Bus [;