Track messages across nodes

I'm having some problems on a complex flow: I don't know which node turns on some lights! :see_no_evil:
Is there a way to track the messages across nodes so that I can understand which function triggers the lights?
Thanks!

I don't know the answer to the question, but if you add debug nodes to the output of each node that can turn the lights on then you should be able to find it.

I scatter a few of these to see what and where a message is being routed (requires node-red-contrib-simpletime)

[{"id":"42652991.2d0e78","type":"subflow","name":"+ hh:mm:ss","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"68633fa6.25f2e"}]}],"out":[{"x":380,"y":60,"wires":[{"id":"68633fa6.25f2e","port":0}]}],"env":[],"meta":{},"color":"#C7E9C0","icon":"node-red-contrib-sun-position/clock-white.png","status":{"x":380,"y":120,"wires":[{"id":"421b10be.1db69","port":0},{"id":"68633fa6.25f2e","port":0}]}},{"id":"68633fa6.25f2e","type":"simpletime","z":"42652991.2d0e78","name":"","mydate":false,"myymd":true,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":115,"y":60,"wires":[["a8b5a4ba.c0c178"]],"l":false},{"id":"421b10be.1db69","type":"change","z":"42652991.2d0e78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mytimes","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":180,"wires":[[]]},{"id":"a8b5a4ba.c0c178","type":"delay","z":"42652991.2d0e78","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":120,"y":180,"wires":[["421b10be.1db69"]]},{"id":"96c1978419f64b6f","type":"subflow:42652991.2d0e78","z":"d760e2801b9ca31b","name":"","env":[],"x":305,"y":610,"wires":[["b57d7d0afc2c0bd1","af93327c733ce7b1"]],"l":false}]

If I'm using MQTT, I often add sub-topics that indicate the origin flow and last update.

For a pure message flow, maybe consider adding a "standard" bit of metadata to the msg. Maybe:

msg = {
   .....
   _meta: {
       track: [
          // .. each section of flow your msg traverses, push another entry to this array
      ]
   }
1 Like

Mmm...I've imported your flow, but I didn't get it. Could you elaborate a bit?
Thanks!

I know, but I have thousands of nodes around about 15 pages and it's quite impossible to add a debug node everywhere.

Surely there are not thousands of nodes that output to the lights?

This seems a very nice idea!
For now it would mean that I'll have to redo all the function node and it wouldn't work on the change nodes.
Also sometimes I discard the old msg and create a new one to lose unnecessary msg.*.
I'll keep your idea in mind for the next developments.
Thanks!

1 Like

That outputs to the lights no, but those that does have tens of connections each, so I don't know where the command starts.

Work back through the flow.

As I told you, each node that output a command to the light, has tens of node connected to it.
It it was so easy, I would have already done it!
Your replies aren't really helping.

How many mqtt-out nodes do you have?
Are they multi-purpose with the topic set by msg.topic or is the topic generally hard coded in the mqtt node?

I have just a few (4 or 5) MQTT out nodes that are generic, the topics are generated in other nodes.

Wow, you have tens of different ways that a light can be switched on/off. I am surprised by that.

There is also a design principle in there about "loose coupling". Trying to make sure that you are not tightly coupling different sections of your logic and data. I use MQTT a fair bit for that because it gives you an event driven loose coupling that is generally still highly performant.

But yes, unfortunately, that does likely mean some rework. Most of my home automation stuff has been completely rewritten at least 4 or 5 times. :slight_smile:

1 Like

Do you mean that you link different section of your Node Red project with MQTT instead of link IN/OUT?

:smile:
I'm not there...yet! I think that I'm only at the third version!!!

Yes. here is an example. I take the inputs from my 433MHz devices all in one place, standardise the data and push to MQTT.

And here, I listen to some of them and output - again to MQTT

Those outputs are listened to in another flow that outputs to Telegram. Of course, I could have many other outputs if I needed them.

So each section of "code" is kept relatively simple and if, for example, I needed to rip out Telegram and replace with something else, that would be easy. Just as easy would be ripping out the 433MHz stuff and replacing with something else without having to replace the other logic.

1 Like

I was wondering if a flow to generate a list of dashboard tabs and the nodes which link to mqtt would help, something like this
image

{"tabs":{"tab1":{"name":"tab1","id":"c7777","nodes":{"aaa":{"nodename":"aaa","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}},"bbb":{"nodename":"bbb","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}}}},"tab2":{"name":"tab2","id":"c7777","nodes":{"aaa":{"nodename":"aaa","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}},"bbb":{"nodename":"bbb","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}}}}}}

but I'm having difficulty generating that format from the flows file.

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