Help with simple flow.. I guess

Hi!

New to MQTT and Node Red.
What I want to achieve is a simple flow that takes an input and based on a simple value (ON/OFF) push a new message to another queue.

Basically something like:

IN:
camera/motion/Entre : msg.payload : string[2]
"ON"

if string = "ON"

then

OUT
domoticz/in : msg.payload : Object
command: "switchlight"
idx: 273
switchcmd: "On"

And then the other way around.. if OFF then send switchcmd: "Off".

oho.. and I'm really not good at coding :confused:

Any help would be appreciated.

This is what I see when debugging.

So after your MQTT In node you want to change the msg.payload to be something else depending what the value is.

So you could do this in a function node where you can write Javascript
Or you can do it with a selection of the nodes that come with Node-RED

step 1: Use a switch node to have two different paths for if msg.payload is "ON" or "OFF"
step 2 : Then use a change node on each of the two outputs from your switch node to change msg.payload to what you want your output to be
step 3 : wire the outputs from both the change nodes to a MQTT out node

A message comes in via your MQTT node, gets sent down one of the two paths by the switch node, gets the msg.payload bit of the message changed and then gets sent out as a MQTT message.

Here's an example of the change node to get you started which you can import

[{"id":"b55db76c.81b51","type":"change","z":"8abddfa4.b6ea98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"command\":\"switchlight\",\"idx\":273,\"switchcmd\":\"On\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":240,"wires":[["bb3d99c3.4d66c8"]]}]

Thanks!

That got me on the right track. Works!

1 Like

Great! One tip is to use more than one debug node.

You can give them all different names and it makes it easier to track messages through your flow when they get more complex.

1 Like