# MQTT topic help please Wild card use

**URL:** <https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366>\
**Category:** General\
**Created:** [10 August 2020 06:58 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366 "2020-08-10T06:58:36Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 06:58 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/1 "2020-08-10T06:58:37Z")

</div>

With another project in which some one pointed out a _problem_ with how I was controlling **tasmota** devices.

I have 2 bulbs.  
They are called (from MQTT) `BULB-1` and `BULB-2` Which kind of made sense for me, but it is flawed if I want to control all of them.

It would be better if I called them:  
`BULB/1/` and `BULB/2/`

Then I could listen to `BULB/#` to listen for bulb _changes_.

B-u-t......

I wrote a flow that doesn't seem to be liked by Node-Red.

I'm not sure it is the same thing for both the `IN` and `OUT` nodes, but they both have an error on them when I send a message to/through them.

 ![Screenshot from 2020-08-10 16-47-22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55c4bc375a83ba2051289b8084825a88dd411c84.png)

 ![Screenshot from 2020-08-10 16-53-46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c850cee93440a439dd6a3621d10aae4f96cda486.png)

 ![Screenshot from 2020-08-10 16-53-58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1ffe77d52d2ccc413d5c0a7768b24121dd318ded.png)

Now, maybe the `IN` node is not happy that I sent out a bad message.

So if I want to send a message to all the `BULB/` devices I can't post a message to `BULB/+/cmnd/power1/` a value of `ON` or `OFF` and expect all the devices to decode that messages.

A bit of help on this would be appreciated.

I have since been told _You can't publish to wild cards_.

So, that means I will have to create a bit of stuff so it publishes to all the bulbs.  
In this case only 1 and 2. But when I get more bulbs.......

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 07:48 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/2 "2020-08-10T07:48:48Z")

</div>

You can listen to wildcard topics, the output shows the full topic, so you know to which bulb to send the command to. Leave the topic in the output mqtt node empty and use the topic that you received.

 ![Screenshot 2020-08-10 at 09.48.21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/3858bd20680c510fde35d12ef3dd757ab8062be8.jpeg)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 07:50 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/3 "2020-08-10T07:50:28Z")

</div>

Thanks.

I have been pointed towards _group topics_. So that may be of some help for this problem.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 07:51 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/4 "2020-08-10T07:51:46Z")

</div>

That should also work, never looked into it myself.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 07:52 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/5 "2020-08-10T07:52:44Z")

</div>

I just need to find a good reference to group topics.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 08:03 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/6 "2020-08-10T08:03:20Z")

</div>

This video shows how it works (starting from the timestamp that is relevant)

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87089d6aa16349b193528744e19f98f908e539c9.jpeg "How to Sync Lights and Switches with Device Groups - Tasmota Tips Episode 7") ](https://www.youtube.com/watch?v=Bp1BsTe2zyY)

---

<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:** [10 August 2020 08:22 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/7 "2020-08-10T08:22:03Z")

</div>

> [@Trying\_to\_learn](#):
>
> I just need to find a good reference to group topics.

Have you read thru this:

> **[MQTT Topics, Wildcards, & Best Practices – MQTT Essentials: Part 5](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/)**
>
> Learn about MQTT Topics, naming conventions, MQTT $SYS topics, MQTT Prefix, MQTT Topic Wildcards, and more in this MQTT Essentials article.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 08:23 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/8 "2020-08-10T08:23:55Z")

</div>

Yeah, but it kind of confused me.

The link @bakman2 posted seems to be good. Still applying the changes.  
Not done yet.

Woo Hoo! It seems to work!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 08:37 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/9 "2020-08-10T08:37:09Z")

</div>

It is called a grouptopic, but in reality it has nothing to do with mqtt, as it works via UDP directly between the tasmota devices.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 08:44 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/11 "2020-08-10T08:44:03Z")

</div>

yes, but that link filled most of the gap I still had.

Dumb question about topics......

In the `switch` node...... What is the wild card for there? `*`?

eg:  
This is what I have:  
`BULB/+/tele/LWT`

But the `+` is a wild card. So what do I put in the field of the `switch` node?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 08:44 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/12 "2020-08-10T08:44:43Z")

</div>

Look what the topic looks like when you receive it in a debug node.

is it called `blbla/+` ?

---

<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:** [10 August 2020 08:45 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/13 "2020-08-10T08:45:29Z")

</div>

FYI from the Hivemq post:

> ## Wildcards
> 
> When a client subscribes to a topic, it can subscribe to the exact topic of a published message or it can use wildcards to subscribe to multiple topics simultaneously. `A wildcard can only be used to subscribe to topics, not to publish a message.` There are two different kinds of wildcards: _single-level_ and _multi-level_ .

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 08:46 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/14 "2020-08-10T08:46:31Z")

</div>

Well, I get multiple replies from all the devices and the `+` is replaced with their names.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 08:48 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/15 "2020-08-10T08:48:42Z")

</div>

Yes, thanks.

And now using `grouptopic` and a bit of trickery shown in the clip:

I have another `topic` which controls all the bulbs. So I can turn them all off/on/etc.  
But now how to parse the _replies_.  
There is on _guarantee_ to which bulb/s will/may be on when the command is sent.  
So I don't know if it is a good idea to pick specifically one.

But I guess for now if I am saying **all bulbs** (and I have only two) number 1 will be replying.

---

<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:** [10 August 2020 08:55 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/16 "2020-08-10T08:55:44Z")

</div>

Try not to mixup what you are doing in NR with MQTT and what you are doing in Tasmota.  
The video looks like it is talking about things you do in Home Assistant

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 August 2020 08:56 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/17 "2020-08-10T08:56:10Z")

</div>

You will confuse yourself with grouptopics (device groups) and mqtt.

You say you have another "topic", but is this device also a tasmota device ? If yes, I would suggest to solve it there directly, instead of mixing up mqtt with the group topic control.

Or all via mqtt or all via grouptopics, you are entering a labyrinth.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 August 2020 09:07 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/18 "2020-08-10T09:07:03Z")

</div>

> [@bakman2](#):
>
> You say you have another "topic", but is this device also a tasmota device ? If yes, I would suggest to solve it there directly, instead of mixing up mqtt with the group topic control.

Well, what I did on each bulb was set a `grouptopic` and set the extra stuff about _receive but don't transmit_.

Then in Node-Red, I set a whole new `topic` and I send a message to it and both bulbs turn on or off.

But I can control each bulb on their own topic.

So I think I have it nutted out.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [11 August 2020 01:45 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/19 "2020-08-11T01:45:58Z")

</div>

I always use the source of the topic as the first element of the topic path. I can then establish a 1 to 1 or many to 1 publish/subscribe pairs. The '+' at the subscriber topic head, is an easy way to do a many to 1 model, then you can add flow logic to qualify how you want to route message from any unique publishers. I find it easier create new topics, rather than parse existing topics with deeper elements in a given topic.

ESP8266 Temperature Module //ambient/data - \> /+/ambient/data Example of a universal receiver, or subscriber.

ESP Temperature Module /\<Host\>/ambient/control \<- /\<Host\>/ambient/control Example of send, or publisher. (1 to 1).

So I can send a demand for immediate measurement, or have a loop that say every 15 minutes sends temperature data to a universal collector (many to 1).

Do I generate a lot of traffic with unique topics? Yes, but with MQTT you always do, either unique topics or parsing data from fewer topics, it amounts to the same thing in effect.

---

<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:** [25 August 2020 01:46 UTC](https://discourse.nodered.org/t/mqtt-topic-help-please-wild-card-use/31366/20 "2020-08-25T01:46:10Z")

</div>

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