Reuse node-red change node for multiple entities

In Node-red, is it possibly to create one change node and use it for multiple entities? Or is the result send to all the entities?

See the “Open” node in the image below. It is called (via a switch) by all change elements which check for the status of my car’s doors and the outcome is send to all mqtt nodes. I assumed flow’s are isolated, but I wonder if the outcome of the switch (e.g coming from ‘doors-front-left’) is send to all mqtt nodes connected to it.

First you should use debug nodes and configure them to show the whole message object to be able to see what each node sends and understand what’s happening. You should also have a look at understanding JSON

For your understanding:
All nodes connected together are called a flow. The way the nodes communicate with each other are JSON messages like {"Payload":true}. In your case, the Open node has no idea where this message comes from, as every node could have send it. To solve this you could add another Key to each message like Topic: {"Payload":true, "Topic":"doors-front-left"}.
Now get a switch node and configure it like:

if msg.Topic = doors-front-left   -> forward message to output one
if msg.Topic = doors-front-right  -> forward message to output two
...
1 Like

UPDATE: excellent solution!

@Syntox Thanks. I have used debug nodes and I know JSON, so that’s fine.

In your case, the Open node has no idea where this message comes from, as every node could have send it.

So the flows are not isolated, that’s where I got it wrong. Interesting solution to add keys to the payload and use that to send the message to the correct node. I’ll give it a try.

In fact, the standard HA nodes do this by default (entity-id as topic).

1 Like