Concat in mqtt topic variable plus text

Hi, I'm trying to publish and subscribe on several topics that have the same first part. I include this first part in a subflow using a variable. I am not able to add the final part of the topic. For example, I want the following themes:
MicrodesysRed/f/entradasDig
MicrodesysRed/f/salidasDig

Consulting the forum and the internet and I saw that it should be written as:

&{mqtt_topic} & "entriesDig"

where mqtt_topic = MicrodesysRed/f/
But it does not work. The variable does recognize it well.

I leave here the screenshots of the creation of the variable and the topic

topic
topic3
topic2

Thank you very much and greetings

Hi.

You can leave the topic blank and create it in a prior node, and pass the topic in msg.topic
e.g

[{"id":"aa026e7dddedecc7","type":"subflow","name":"Subflow 1","info":"","category":"","in":[{"x":180,"y":120,"wires":[{"id":"9ab78c8c6e46d6b1"}]}],"out":[],"env":[{"name":"mqtt_topic","type":"str","value":"MicrodesysRed/f/","ui":{"label":{"en-US":"mqtt topic"},"type":"input","opts":{"types":["str","bool"]}}},{"name":"mqtt_end","type":"str","value":"test","ui":{"label":{"en-US":"mqtt ebd"},"type":"input","opts":{"types":["str"]}}}],"meta":{},"color":"#DDAA99"},{"id":"2b7f30fc05ca40a2","type":"mqtt out","z":"aa026e7dddedecc7","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"e8ba3ef5.22f4a8","x":550,"y":120,"wires":[]},{"id":"9ab78c8c6e46d6b1","type":"change","z":"aa026e7dddedecc7","name":"","rules":[{"t":"set","p":"start","pt":"msg","to":"mqtt_topic","tot":"env"},{"t":"set","p":"end","pt":"msg","to":"mqtt_end","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":60,"wires":[["261b55b08d58dc2a"]]},{"id":"261b55b08d58dc2a","type":"template","z":"aa026e7dddedecc7","name":"","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{start}}}{{{end}}}","output":"str","x":460,"y":60,"wires":[["2b7f30fc05ca40a2","0007781504e401b1"]]},{"id":"0007781504e401b1","type":"debug","z":"aa026e7dddedecc7","name":"debug 2466","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":410,"y":200,"wires":[]},{"id":"e8ba3ef5.22f4a8","type":"mqtt-broker","name":"testb","broker":"192.168.1.25","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"6bfb6de15b27e2c1","type":"subflow:aa026e7dddedecc7","z":"d1395164b4eec73e","name":"","x":460,"y":3480,"wires":[]},{"id":"508728d4a9148935","type":"mqtt in","z":"d1395164b4eec73e","name":"","topic":"MicrodesysRed/f/test","qos":"2","datatype":"auto-detect","broker":"e8ba3ef5.22f4a8","nl":false,"rap":true,"rh":0,"inputs":0,"x":260,"y":3560,"wires":[["d3e3a8c179685bc6"]]},{"id":"d3e3a8c179685bc6","type":"debug","z":"d1395164b4eec73e","name":"debug 2465","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":3560,"wires":[]},{"id":"51a2de387bd8320c","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":3480,"wires":[["6bfb6de15b27e2c1"]]}]

There are other ways but this is using low code option.

1 Like

What you gave me works great, thank you very much for the quick response, however, I don't want the second part to be a variable, I need it to be a text.

topic4

Thanks!

Then delete {{{end}}} and add the text you require
{{{start}}}anytextyouwish

You could drop the change node to, as the template uses env vars( i forgot)
{{{env.mqtt_topic}}}anytextyouwish

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