# Newbie help - If/Then

**URL:** <https://discourse.nodered.org/t/newbie-help-if-then/19913>\
**Category:** General\
**Created:** [4 January 2020 21:43 UTC](https://discourse.nodered.org/t/newbie-help-if-then/19913 "2020-01-04T21:43:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikewoodld](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikewoodld/32/26822_2.png) [@mikewoodld](https://discourse.nodered.org/u/mikewoodld)\
**Post date:** [4 January 2020 21:43 UTC](https://discourse.nodered.org/t/newbie-help-if-then/19913/1 "2020-01-04T21:43:25Z")

</div>

Wondering if I can simplify my project just a bit. Right now, I have two different flows that take HTTP IN and then execute a shell script on the server:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a65a78451d7585bed3445b3cee8cdf115df286f1.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f635cee0451ca06790fb5e1d878c1a898d6ff24c.png)

I'm wondering if it would instead be possible to have a single HTTP in, then something that does an if/then evaluation of the payload, then depending on the contents of the payload, execute different shell scripts.

For example, I send HTTP POST to my HTTP IN with either Driveway, Porch, or Garage.

A middle step parses the message and then passes it along to the final step, the appropriate exec step:  
If Driveway, exec driveway.sh  
Else If Porch, exec porch.sh  
Else If Garage, exec garage.sh.

Does that make sense? Currently I'm able to accomplish what I want with multiple flows, but I'd love to be able to just have it on one.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 21:56 UTC](https://discourse.nodered.org/t/newbie-help-if-then/19913/2 "2020-01-04T21:56:28Z")

</div>

There are two ways I can see.

I've posted an example of both.

You use the `switch` node.

To help keep things separate I used the `msg.topic` for identifying from where the message comes.  
That way the `payload` can be used for things like pictures.

```auto
[{"id":"1c6296dd.e816d1","type":"inject","z":"8ca77c0a.a59f98","name":"Garage","topic":"Garage","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":1650,"wires":[["372f17e.e70cd68"]]},{"id":"af33861a.38d88","type":"inject","z":"8ca77c0a.a59f98","name":"Driveway","topic":"Driveway","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":1690,"wires":[["372f17e.e70cd68"]]},{"id":"295831cb.18de26","type":"inject","z":"8ca77c0a.a59f98","name":"Porch","topic":"Porch","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":1730,"wires":[["372f17e.e70cd68"]]},{"id":"372f17e.e70cd68","type":"switch","z":"8ca77c0a.a59f98","name":"Garage?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Garage","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":1650,"wires":[["89e29418.88e7c8"],["4773d6f6.2604b8"]]},{"id":"4773d6f6.2604b8","type":"switch","z":"8ca77c0a.a59f98","name":"Driveway?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Driveway","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":1650,"wires":[["269dc0c4.414e2"],["bd098880.5fb478"]]},{"id":"89e29418.88e7c8","type":"function","z":"8ca77c0a.a59f98","name":"Garage stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":1570,"wires":[[]]},{"id":"269dc0c4.414e2","type":"function","z":"8ca77c0a.a59f98","name":"Driveway stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":1570,"wires":[[]]},{"id":"bd098880.5fb478","type":"function","z":"8ca77c0a.a59f98","name":"Porch stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":1710,"wires":[[]]},{"id":"a82bdecf.74f0f","type":"inject","z":"8ca77c0a.a59f98","name":"Garage","topic":"Garage","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":1820,"wires":[["faa38409.885988"]]},{"id":"a8c82b.7bb3a7d8","type":"inject","z":"8ca77c0a.a59f98","name":"Driveway","topic":"Driveway","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":1860,"wires":[["faa38409.885988"]]},{"id":"f08bd293.a43538","type":"inject","z":"8ca77c0a.a59f98","name":"Porch","topic":"Porch","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":1900,"wires":[["faa38409.885988"]]},{"id":"faa38409.885988","type":"switch","z":"8ca77c0a.a59f98","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Driveway","vt":"str"},{"t":"eq","v":"Garage","vt":"str"},{"t":"eq","v":"Porch","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":460,"y":1860,"wires":[["7b129912.03926"],["5ed848ad.2d684"],["8d58275c.ddae98"]]},{"id":"7b129912.03926","type":"function","z":"8ca77c0a.a59f98","name":"Garage stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":1810,"wires":[[]]},{"id":"5ed848ad.2d684","type":"function","z":"8ca77c0a.a59f98","name":"Driveway stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":1860,"wires":[[]]},{"id":"8d58275c.ddae98","type":"function","z":"8ca77c0a.a59f98","name":"Porch stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":1920,"wires":[[]]}]

```

That is a basic idea.  
Option 1 you only look for one match in the `switch` node.  
Option 2 you split/search for all three and route the message as needed.

Hope that helps.

 ![Screenshot from 2020-01-05 08-54-41](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/dc735dc660917f6eede39c49f07f378fbf98b21c.png)
