# How to trigger two separate functions based on mqtt topic

**URL:** <https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497>\
**Category:** General\
**Created:** [13 February 2024 18:26 UTC](https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497 "2024-02-13T18:26:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [13 February 2024 18:26 UTC](https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497/1 "2024-02-13T18:26:06Z")

</div>

I have two MQTT topics ending with DATA and EVENT,  
e.g. `device/deviceId/DATA and device/deviceId/Event`

How can I perform two separate internal flows based on DATA and EVENT?  
Current I able to do by parsing topic in function node and than using switch node. Is there any better way to do so?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 February 2024 18:51 UTC](https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497/2 "2024-02-13T18:51:04Z")

</div>

Have the mqtt-in node use the topic `device/deviceId/#` and feed that to a switch node that checks if the topic contained `DATA` and check if it contains `Event`

Then you can connect the two outputs to the two flows you want

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [13 February 2024 19:27 UTC](https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497/3 "2024-02-13T19:27:46Z")

</div>

Or just have two MQTT inputs set to each topic.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 May 2024 19:28 UTC](https://discourse.nodered.org/t/how-to-trigger-two-separate-functions-based-on-mqtt-topic/85497/4 "2024-05-13T19:28:14Z")

</div>

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