MQTT - full topic alias

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.

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.

I see. Are there any drawbacks?

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. :grinning:

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?

You mean this, correct?

image

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.

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.

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

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.

Perfect! Thank you.