# Help with simple flow.. I guess

**URL:** <https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286>\
**Category:** General\
**Created:** [29 October 2019 16:59 UTC](https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286 "2019-10-29T16:59:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![htilly](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@htilly](https://discourse.nodered.org/u/htilly)\
**Post date:** [29 October 2019 16:59 UTC](https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286/1 "2019-10-29T16:59:38Z")

</div>

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 😕

Any help would be appreciated.

This is what I see when debugging.

 ![45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/72a3dd163c9ac57f07fcd0b26959c9cf108d742f.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 October 2019 17:15 UTC](https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286/2 "2019-10-29T17:15:51Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![htilly](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@htilly](https://discourse.nodered.org/u/htilly)\
**Post date:** [29 October 2019 17:54 UTC](https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286/3 "2019-10-29T17:54:33Z")

</div>

Thanks!

That got me on the right track. Works!

 ![42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/92be07f7c29d21ddebf9f7afaf11f2994aee9e6c.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 October 2019 18:24 UTC](https://discourse.nodered.org/t/help-with-simple-flow-i-guess/17286/4 "2019-10-29T18:24:09Z")

</div>

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.
