No multiple topics

Hi.
I´m pretty new in Node-Red, but I´m trying to understand it better every day.
Actually I want to transfer MQTT of my heat pump to my PLC with ADS.
But I don´t want to use 100´s of MQTT nodes, just only one with /# and then use only the ones I need.
But how can I do that, to filter for subtopics ?
Thanks.

Regards, Thorsten

That would depend on your topic structure, any answer would be a guess as you do not provide examples of your topics.

you could use a look up object and see if your incoming topic is in the look up object.
Or
you could split your topic on "/" and only pass if a certain array value is something you want to pass.

Hi.
The structure is for example "panasonic_heat_pump/main/Heatpump_Status" or "panasonic_heat_pump/main/Main_Inlet_Temp".
Behind main/ is one of my suptopics and every subtopic has a value.
So I´m using "panasonic_heat_pump/main/# for calling every subtopic.

You can use a Switch node to send the message down the different routes by testing msg.topic in the Switch rules.

so spliting your topic on "/" and selecting an array index would produce a string
msg.topic = msg.topic.split("/")[2];
outputs
"Heatpump_Status"
you could then compare in function or switch node for that value.

Isn't it easier just to test the topic directly in the Switch node?

That depends on how long your topic is, I just prefer not having to type long strings, It's just a personnel choice.

Also it allows for different topics starts with same final section

e.g.
one/two/status
four/five/status

both would be passed

All subtopics just have numbers as a value, no strings.
example

MQTT directly to ADS, no visu with Node-Red

I am not talking about values, I am showing an example of directing message via msg.topic, which holds the mqtt topic.

Switch is working fine for me:
result

You can use one Switch node with multiple rules, sending each topic to its own output.

Yes, I´ve seen it.
For heatpump states I´m having 9 rules and changing numbers to strings. It´s working fine.

How can I do this in the other way ?
Signals are coming from PLC, for example "1", and must be sent to panasonic_heat_pump/main/SetOperationMode.
But I´m also using /# for the MQTT-Out.
With the change node it´s not working.

As described in the help text for the node, leave the topic blank in the Out node and put the topic in msg.topic. In fact I believe that is the original reason that msg.topic is called msg.topic.

1 Like

against missunderstanding:
"ADS Notification" -> "CHANGE" with 2 rules: bolean to number & msg.topic with the full path -> "MQTT-Out" with blank topic ?

Sorry, that conveys nothing to me.

sorry, but I´m having the solution.
Using change node with setting msg.topic to the path and leaving the OUT blank. Thanks.

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