# Mqtt in and out topic

**URL:** https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565
**Category:** General
**Created:** [10 December 2023 02:03 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565 "2023-12-10T02:03:30Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mohammad-torabi-84](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mohammad-torabi-84/32/85686_2.png) [@mohammad-torabi-84](https://discourse.nodered.org/u/mohammad-torabi-84)
#### Post date: [10 December 2023 02:03 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/1 "2023-12-10T02:03:31Z")

</div>

Hi,

I have a very simple flow that contains an mqtt-in node, two mqtt-out nodes and two function nodes.

the topic of the mqtt-in node is home/Garage/# and the topic of mqtt-out nodes are home/Garage/door/status and home/Garage/door/command.

obviously this simple flow has an issue which causes an infinite loop.

how can I fix the issue?

Thanks,

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [10 December 2023 02:14 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/2 "2023-12-10T02:14:06Z")

</div>

Hello @mohammad-torabi-84

Either subscribe to `home/garage/+/status`  
Or (probably better) use `command/home/garage/door` and `status/home/garage/door`

---

<div class="post-metadata">

### Author: ![mohammad-torabi-84](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mohammad-torabi-84/32/85686_2.png) [@mohammad-torabi-84](https://discourse.nodered.org/u/mohammad-torabi-84)
#### Post date: [10 December 2023 02:33 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/3 "2023-12-10T02:33:46Z")

</div>

So, these two topic of command/home/garage/door and status/home/garage/door have the same result. because the mqtt-out node has the same topic of the mqtt-in node. this will cause an infinite loop in the flow.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [10 December 2023 07:26 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/4 "2023-12-10T07:26:06Z")

</div>

I misinterpreted your question.

1. Presumably the messages that your flow sends on home/garage/door/command are instructions to the door -"Open", "Close" etc. ?

2. Why does your flow send messages on home/garage/door/status?  
What device subscribes to these messages?  
I assumed that these messages would be sent by the door to indicate it's current state - "Opened", "Closed" etc.

3. What device publishes the message that your mqtt-in node is intended to receive?  
Do you have control over the topic this device uses?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [10 December 2023 07:35 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/5 "2023-12-10T07:35:22Z")

</div>

Add a Filter node in front of each mqtt out node. That should break the loop.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [10 December 2023 07:37 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/6 "2023-12-10T07:37:13Z")

</div>

Your MQTT-In node is subscribing to the topic `home/Garage/#`  
The hash ` #` symbol is a wildcard which means the node will accept anything from that point onwards.

Your MQTT-Out nodes are publishing to the topic `home/Garage/door/status` and  
`home/Garage/door/command`

If you write the topics out as a list you can see the overlap.  
`home/Garage/#`  
`home/Garage/door/status`  
`home/Garage/door/command`

So your **MQTT-In** will react everytime you **send** a message. An infinite loop has been created.

As @jbudd said you need to adjust the topic names or as @Colin says add a 'Filter'node.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [10 December 2023 08:06 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/7 "2023-12-10T08:06:36Z")

</div>

If you tell us what is in the function nodes, and why, there may be a better way of handling the problem.

---

<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: [24 December 2023 08:06 UTC](https://discourse.nodered.org/t/mqtt-in-and-out-topic/83565/8 "2023-12-24T08:06:51Z")

</div>

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