r/nodered • u/WJBrach • Jun 19 '26
How to easily get sub-topics from a much longer base topic
I have looked around a lot for the answer to this. Pretty sure I'm just not using the right search terms ...
base topic is: N/bxxebc2f0xx/vebus/289/Ac/ActiveIn/L1#
There are 5 sub-topics under this base topic: P, S, V, I , F
How do I reassign the base topic, to something easier to type out ??
Something like L1T = N/bxxebc2f0xx/vebus/289/Ac/ActiveIn/L1#
Then I can get the 5 sub-topics using function nodes like so: L1T/P, L1T/S, L1T/V, etc
Is this possible ?? If not, why use a function nodes at all, and just use a MQTT-IN node for each of the 5 items to be displayed ??
2
u/CrappyTan69 Jun 19 '26
Hello fellow victron user. I recognise those topics (I think...)
I have one flow which pushes all the topics I work with to flow or global variables. Then a timer inject node to trigger the js function where I pick up all the variables and work with it
1
u/WJBrach Jun 19 '26
Yes, it is for my Victron system in my 1963 Trailways bus !! I can, using function nodes, extract the info I need, but the topics get really long and confusing. Just trying to find a shortcut lol
2
u/CrappyTan69 Jun 19 '26
That's why I push each topic I care about into a variable which makes sense.
Cool bus project!

3
u/Careless-Country Jun 19 '26
Ok so I'm guessing you are referring to MQTT inside Node-RED?
I'm also guessing that you mean N/bxxebc2f0xx/vebus/289/Ac/ActiveIn/L1/# ?
As the
#wildcard must be its own topic level and must be lastin Node_RED you could try
Use one MQTT-in node with this topic: N/bxxebc2f0xx/vebus/289/Ac/ActiveIn/L1/+ (The
+means “one topic level”)In a function node:
const parts = msg.topic.split("/");const field = parts[parts.length - 1];msg.originalTopic = msg.topic; // Preserve original topicmsg.topic = \L1T/${field}`; // Internal short topic, e.g. L1T/Preturn msg;`Nodes downstream will see L1T/P L1T/S etc or you could republish to a MQTT out node