# MQTT - full topic alias

**URL:** https://discourse.nodered.org/t/mqtt-full-topic-alias/35255
**Category:** General
**Created:** [3 November 2020 04:16 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255 "2020-11-03T04:16:41Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)
#### Post date: [3 November 2020 04:16 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/1 "2020-11-03T04:16:41Z")

</div>

Hi, I’m building a new server to run Emoncms and NodeRed with MQTT as base com protocol.

I have, at least, 10 relay command to be executed in this system And more 20 sensors inside a container that will be send 500km away.

The idea is to use publish to Topic to drive some loads:

drive/relay1  
drive/relay2  
drive/relay3  
.  
.  
.  
drive/relay10

Is there a way to alias to another topics? Can nodered understand that:

drive/pump = drive/relay1  
drive/fan = drive/relay2  
drive/heater = drive/relay3

If so, I can create a better code and will be easier to understand code in the near future.

Sounds more like a variable than an alias.

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [3 November 2020 05:32 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/2 "2020-11-03T05:32:10Z")

</div>

The easiest way to do this is using pairs of MQTT in and out nodes for each mapping if you don't need further processing of the message.

E.g. MQTT in node with topic `drive/relay1` sends all messages directly to MQTT out node with topic `drive/pump`. And so on.

---

<div class="post-metadata">

### Author: ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)
#### Post date: [3 November 2020 15:59 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/3 "2020-11-03T15:59:29Z")

</div>

I see. Are there any drawbacks?

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [3 November 2020 18:53 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/4 "2020-11-03T18:53:07Z")

</div>

None that I can think of. Scalability _might_ be an issue, if you have many topic mappings, because you'd have to create (copy/paste/edit) one node pair for each mapping. But it is visual programming after all. 😀

There are other solutions, of course, but this is by far the easiest one, if your topic mappings are limited in number.

Do you have specific concerns?

---

<div class="post-metadata">

### Author: ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)
#### Post date: [3 November 2020 19:26 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/5 "2020-11-03T19:26:29Z")

</div>

You mean this, correct?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89d360c809c619879be75db00bc59c5882e3a2f0.png)

By doing so, I'm broadcasting the message two times over the network.  
payload: 1 coming from topic1  
payload: 1 going to pump topic  
payload: 1 coming from topic1

I know that is nothing, but will increase network traffic and also consume some RAM.

I thought that was possible to use some variable like:

pump = topic1

than, just use that variable.

---

<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: [3 November 2020 22:09 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/6 "2020-11-03T22:09:46Z")

</div>

You said initially that you wanted to alias topics, and we assumed you mean that you want them to appear as aliases in MQTT. If you just want to refer to them by different topics once into node-red then all you need to do is use Change nodes to set the topics to whatever you want.

---

<div class="post-metadata">

### Author: ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)
#### Post date: [3 November 2020 22:34 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/7 "2020-11-03T22:34:06Z")

</div>

Can you provide some example to see if I’m correctly understanding you?

---

<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: [4 November 2020 08:46 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/8 "2020-11-04T08:46:07Z")

</div>

All I meant was to feed the MQTT In into a Change node to change the topic to whatever you wanted. However perhaps what you are looking for is to use environment variables. You could set an environment variable called pump, set it to "drive/relay1" and then in the MQTT nodes you can use `${pump}` and node red will replace that with "drive/relay1". How you set environment variables in your OS depends on the OS.

---

<div class="post-metadata">

### Author: ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)
#### Post date: [4 November 2020 12:41 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/9 "2020-11-04T12:41:55Z")

</div>

> [@Colin](#):
>
> environment variables

Perfect! 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: [3 January 2021 12:42 UTC](https://discourse.nodered.org/t/mqtt-full-topic-alias/35255/10 "2021-01-03T12:42:02Z")

</div>

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