Reallocating messages to different outputs

#1

Hello,

I have several temperature sensors and I would like to have the different temperatures displayed on several gauges and graphs.
I would like to seperate the values by using their topics.
How can I seperate the different temperatures values using their topics and allocate them to different outputs?

For example, following messages arrives at one node:
{"topic":"Haus/Temperatur/T01Aussen","payload":16.6,"_msgid":"db91425d.2c2ee"}
{"topic":"Haus/Temperatur/T31HWRRauchmelder","payload":20.9,"_msgid":"a8c46095.77b11"}
{"topic":"Haus/Temperatur/T30FlurKellerRauchmelder","payload":20.3,"_msgid":"4e75d350.e96a2c"}
{"topic":"Haus/Temperatur/T23AbluftKeller","payload":21.5,"_msgid":"9c6719e7.4accb8"}
{"topic":"Haus/Temperatur/T22AbluftHaus","payload":22.3,"_msgid":"3ee42820.e4c3a8"}
{"topic":"Haus/Temperatur/T21ZuluftHaus","payload":21.6,"_msgid":"11efed1c.146b03"}
{"topic":"Haus/Heizung/T03Warmwasserspeicher","payload":47.6,"_msgid":"26a4b9a1.3e8436"}
{"topic":"Haus/Temperatur/T29HobbyRauchmelder","payload":20.1,"_msgid":"7e3483ad.84c07c"}
{"topic":"Haus/Temperatur/T11TemperaturServerBreadboard","payload":21.3,"_msgid":"2d9b17a2.aac8b8"}
{"topic":"Haus/Heizung/T20KellerRücklauf","payload":20.8,"_msgid":"65f3592a.ae4e78"}
{"topic":"Haus/Temperatur/T02Fortluft","payload":15.9,"_msgid":"38ecfc04.db4064"}
{"topic":"Haus/Temperatur/T05Bad","payload":22.5,"_msgid":"8bfd29b1.2dd988"}
{"topic":"Haus/Temperatur/T28BüroRauchmelder","payload":20.1,"_msgid":"d985aafb.81f258"}
{"topic":"Haus/Heizung/T19KellerVorlauf","payload":21.4,"_msgid":"b5aa70c7.aef17"}
{"topic":"Haus/Heizung/T04WarmwasserVorlauf","payload":40.6,"_msgid":"620130ef.926b4"}
{"topic":"Haus/Heizung/T15ZirkulationKüche","payload":31.8,"_msgid":"68e3e00c.753c9"}
{"topic":"Haus/Heizung/T16ZirkulationBad","payload":31.6,"_msgid":"3b97a801.79b598"}
{"topic":"Haus/Heizung/T17HausVorlauf","payload":22,"_msgid":"a7e9a05d.48326"}
{"topic":"Haus/Heizung/T18HausRücklauf","payload":23.7,"_msgid":"9a3258d6.3fc998"}

And now I looking for a methodology to reallocate the messages to different node outputs to link the different topics to different gauges and graph.

For example:
On node output 1 should only arrive:
{"topic":"Haus/Temperatur/T01Aussen","payload":16.6,"_msgid":"db91425d.2c2ee"}

On node output 2 should only arrive:
{"topic":"Haus/Temperatur/T31HWRRauchmelder","payload":20.9,"_msgid":"a8c46095.77b11"}
{"topic":"Haus/Temperatur/T30FlurKellerRauchmelder","payload":20.3,"_msgid":"4e75d350.e96a2c"}
{"topic":"Haus/Temperatur/T23AbluftKeller","payload":21.5,"_msgid":"9c6719e7.4accb8"}
{"topic":"Haus/Temperatur/T22AbluftHaus","payload":22.3,"_msgid":"3ee42820.e4c3a8"}
{"topic":"Haus/Temperatur/T21ZuluftHaus","payload":21.6,"_msgid":"11efed1c.146b03"}
{"topic":"Haus/Temperatur/T29HobbyRauchmelder","payload":20.1,"_msgid":"7e3483ad.84c07c"}
{"topic":"Haus/Temperatur/T11TemperaturServerBreadboard","payload":21.3,"_msgid":"2d9b17a2.aac8b8"}
{"topic":"Haus/Temperatur/T02Fortluft","payload":15.9,"_msgid":"38ecfc04.db4064"}
{"topic":"Haus/Temperatur/T05Bad","payload":22.5,"_msgid":"8bfd29b1.2dd988"}
{"topic":"Haus/Temperatur/T28BüroRauchmelder","payload":20.1,"_msgid":"d985aafb.81f258"}

On node output 3 should only arrive:
{"topic":"Haus/Heizung/T03Warmwasserspeicher","payload":47.6,"_msgid":"26a4b9a1.3e8436"}
{"topic":"Haus/Heizung/T20KellerRücklauf","payload":20.8,"_msgid":"65f3592a.ae4e78"}
{"topic":"Haus/Heizung/T19KellerVorlauf","payload":21.4,"_msgid":"b5aa70c7.aef17"}
{"topic":"Haus/Heizung/T04WarmwasserVorlauf","payload":40.6,"_msgid":"620130ef.926b4"}
{"topic":"Haus/Heizung/T15ZirkulationKüche","payload":31.8,"_msgid":"68e3e00c.753c9"}
{"topic":"Haus/Heizung/T16ZirkulationBad","payload":31.6,"_msgid":"3b97a801.79b598"}
{"topic":"Haus/Heizung/T17HausVorlauf","payload":22,"_msgid":"a7e9a05d.48326"}
{"topic":"Haus/Heizung/T18HausRücklauf","payload":23.7,"_msgid":"9a3258d6.3fc998"}

Anybody who can help me?

Thanks a lot and best regards,
Chris

0 Likes

#2

take a look at the switch node

0 Likes

#3

I tried the switch node, but I don't find how to use it in my case.

Can you help me what I need to enter in the switch node?

0 Likes

#4

It looks like you have a nicely organinzed topic structure for your messages...

I would try to take advantage of that by just having a single output port wired to an mqtt out node. Then, you can use an mqtt in node set to listen for topics matching the wildcard Haus/Heizung/# (so that would be equivalent to your output port #3). Or individual charts/gauges could listen to the exact topic, if they are showing only one value...

The only one that cannot be nicely handled is Haus/Temperatur/T01Aussen (for output port #1), since it would also match the wildcard topic "Haus/Temperatur/#" -- but a switch could check for that case and route it to its own widget.

0 Likes

#5

Assuming those are different messages a switch node set to send different topics to different outputs and then wire the ones you want together to the next node

0 Likes

#6

You both understand exactly what my goal is.
But I have no idea how to configure the switch node.
I found no example how to program the switch node choosing on a topic.

I would like do something like:
If Topic = "Haus/Temperatur/T01Aussen" then use Output 1.

But how to do this in a node RED switch node?

0 Likes

#7

the yellow switch node not the dashboard switch node

property msg.topic
==

then add additional rules

0 Likes

#8

Here is one way:

The regex symbol ^ when used as the first character of the expression represents "beginning of string" -- likewise, $ represents "end of string". So by checking for ^xyz it will match all inputs that start with "xyz".

Just make sure you select the option "stopping after the first match" at the bottom, or the same message could match rule #1 and #2.

0 Likes

#9

Okay, thanks a lot, this works!
Nice!
And how to allocate more than one Topic to one Output?

0 Likes

#10

Well, that's effectively what the regex matching does -- multiple topics go out one port. So I guess that's not quite what you are asking... can you give an example of the two topics you would want to go to the same output?

0 Likes

#11

I unterstand the regex like a "wildcard thing"

But the topics are not sorted like this way that I can use it with a kind of wildcard.

For example:
Following topics should be routed to output 1:
"Haus/Temperatur/T31HWRRauchmelder"
"Haus/Temperatur/T30FlurKellerRauchmelder"
"Haus/Temperatur/T23AbluftKeller"

Following topics should be routed to output 2:
"Haus/Temperatur/T22AbluftHaus"
"Haus/Temperatur/T21ZuluftHaus"
"Haus/Heizung/T03Warmwasserspeicher"

Following topics should be routed to output 3:
"Haus/Temperatur/T29HobbyRauchmelder"
"Haus/Temperatur/T11TemperaturServerBreadboard"

0 Likes

#12

Add another condition to the switch and have the output go to the same place as the other

0 Likes

#13

In that case, you will have to "group" them using some other means. It would be best if you could add another level to the topic hierarchy (e.g. room, location, floor) that would be the same for all readings in each output group -- for instance:

Following topics should be routed to output 1:
"Haus/Downstairs/Temperatur/T31HWRRauchmelder"
"Haus/Downstairs/Temperatur/T30FlurKellerRauchmelder"
"Haus/Downstairs/Temperatur/T23AbluftKeller"

Following topics should be routed to output 2:
"Haus/Upstairs/Temperatur/T22AbluftHaus"
"Haus/Upstairs/Temperatur/T21ZuluftHaus"
"Haus/Upstairs/Heizung/T03Warmwasserspeicher"

If that is not practical, then you may have to use some brute-force matching logic. You can use a regex for this as well, but it's not very practical for large lists of strings -- just separate the strings with vertical bars like so:

^Haus/Temperatur/( T31HWRRauchmelder | T30FlurKellerRauchmelder | T23AbluftKeller )$

meaning match any Haus Temperatur topic the ends with a "/" followed by one of these 3 strings

0 Likes

#14

I wish this was possible... but the way it's implemented now, each rule gets its own output port -- which is determined by its order. Unless I've missed some new feature...

0 Likes

#15

Each rule gets its own output port, but nothing stops you wiring multiple output ports to the same next node if they all represent rules in the same logical group.

0 Likes

#16

True, true... and probably more visually recognizable, too.
*Sigh, sometimes I skip right past the simplest solutions :blush:

0 Likes

#17

It works very fine.

Thanks a lot for your help :slight_smile: ->happy

0 Likes