# List of topic choices in mqtt-in

**URL:** https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001
**Category:** General
**Created:** [22 March 2021 12:30 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001 "2021-03-22T12:30:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)
#### Post date: [22 March 2021 12:30 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/1 "2021-03-22T12:30:36Z")

</div>

I'd like to have a fixed list of available topics for the mqtt-in node. As far as I can see, using a subflow is not option, or maybe I am missing something.  
In other words, I need that the user - upon deploying the node - has not to type in the topic but should make a choice from a dropdown list.

---

<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: [22 March 2021 13:14 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/2 "2021-03-22T13:14:39Z")

</div>

The `mqtt-in` node needs the topic hardcoded. If the topics being published have a formal format that they all abide by, you code subscribe to the main topic and then filter the results with switches.

Lets say you have 5 weather stations and you want tp pick the data from station 5. If the topics were arranged like  
weatherstation/office/bme280  
weatherstation/home/bme280  
weatherstation/farm/ds18b20

you could subscribe to 'weatherstation/#' and you would get the data from all the stations. Then you could filter it by the second level in the topic

If you haven't read the [MQTT Topics & Best Practices - MQTT Essentials: Part 5](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/) I suggest you spend some time and read it

---

<div class="post-metadata">

### Author: ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)
#### Post date: [22 March 2021 14:20 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/3 "2021-03-22T14:20:19Z")

</div>

I have read very well the mqtt essentials, and I know that the mqtt-in need the topic hardcoded. I was just wondering if there could be a possibility not to leave this to the user, who can mistype the topic.

---

<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: [22 March 2021 14:23 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/4 "2021-03-22T14:23:38Z")

</div>

Is the user editing the node? or are they just using a dashboard and picking from a list.

It they are picking it from a list, you can programatically limit what gets to them.

If they are editing the node then, yup tehy can mistype the topic (heck, I've done that multiple times 😁)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [22 March 2021 14:42 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/5 "2021-03-22T14:42:51Z")

</div>

This would, in my opinion, need a different node. MQTT is so flexible that adding this to the standard mqtt-in would add complexity to it that most people would not use.

The nice thing (one of many of course 😉 ) about Node-RED is that it is easy enough to create a new, more specialist node from an existing example.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [22 March 2021 16:10 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/6 "2021-03-22T16:10:09Z")

</div>

You can use a subflow to do this.

1. Set the mqtt-in topic to `${TOPIC}`
2. Wrap that node in a subflow.
3. Edit the subflow properties and define a property called `TOPIC`. By expanding the row in the properties table, you can customise the UI for how the property will be shown. One of the options is a select box where you can predefine a set of options.

---

<div class="post-metadata">

### Author: ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)
#### Post date: [22 March 2021 16:39 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/7 "2021-03-22T16:39:56Z")

</div>

You made my day, Nick! Thank you.

---

<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: [5 April 2021 16:40 UTC](https://discourse.nodered.org/t/list-of-topic-choices-in-mqtt-in/43001/8 "2021-04-05T16:40:50Z")

</div>

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