# Need Help with IF Then

**URL:** <https://discourse.nodered.org/t/need-help-with-if-then/29263>\
**Category:** General\
**Created:** [30 June 2020 20:28 UTC](https://discourse.nodered.org/t/need-help-with-if-then/29263 "2020-06-30T20:28:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hi8smx](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@hi8smx](https://discourse.nodered.org/u/hi8smx)\
**Post date:** [30 June 2020 20:28 UTC](https://discourse.nodered.org/t/need-help-with-if-then/29263/1 "2020-06-30T20:28:25Z")

</div>

Hi, I am not a programmer by any means and I just started using Node Red for simple projects regarding amateur radio. I´m using an OWM to get local weather to my location and it is working fine but I want to take it a step further.

I want to create a function that IF the description of the weather contains certain words (thunderstorms, lighting, heavy rain) it triggers a text message and it turns off a webswitch I control with a separate flow, plus turns red a led in the dashboard (whic otherwise is green) for visual help.

This is the flow I am using: OpenWeatherMap Weather Dashboard with Icons - Portrait

[https://flows.nodered.org/flow/e8176d72ac8af8fbb9fde4adb4008317](https://flows.nodered.org/flow/e8176d72ac8af8fbb9fde4adb4008317)

Anyone up to the task?

---

<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:** [30 June 2020 21:58 UTC](https://discourse.nodered.org/t/need-help-with-if-then/29263/2 "2020-06-30T21:58:43Z")

</div>

How about you have a look at this flow.

It is not exactly what you want with **how** it is done, but it does **do** what you want.

Rather than using an `IF` command, I used a `switch` node.

Have a look.

```auto
[{"id":"245e5db1.d0feea","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"thunderstorms","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":260,"wires":[["cefa1eeb.51646"]]},{"id":"8f471843.fe865","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"lighting","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":[["cefa1eeb.51646"]]},{"id":"dce8eaf3.4573d","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"heavy rain","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":340,"wires":[["cefa1eeb.51646"]]},{"id":"61a76b87.b6e94c","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"anything else","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":380,"wires":[["cefa1eeb.51646"]]},{"id":"cefa1eeb.51646","type":"switch","z":"b9924a74.4d98f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"thunderstorms","vt":"str"},{"t":"cont","v":"lighting","vt":"str"},{"t":"cont","v":"heavy rain","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":370,"y":300,"wires":[["a91b5133.f8ace8"],["a91b5133.f8ace8"],["a91b5133.f8ace8"],["7909e18.4ab142"]]},{"id":"a91b5133.f8ace8","type":"debug","z":"b9924a74.4d98f8","name":"Bad weather","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":560,"y":270,"wires":[]},{"id":"7909e18.4ab142","type":"debug","z":"b9924a74.4d98f8","name":"Good weather","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":570,"y":330,"wires":[]}]

```

The two `output` nodes are for **good weather** and **bad weather**.  
So depending on what you send in to the _node_ depends on which `debug` node get the message.

You can then use those outputs to start the next stage of things happening.  
Also, you could put a `change` node on each output that simply changes the `msg.payload` to either `bad` or `good` for easier processing at the next stage. But really it isn't needed unless you really want to use the _Original_ messages.

---

<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:** [1 July 2020 01:43 UTC](https://discourse.nodered.org/t/need-help-with-if-then/29263/3 "2020-07-01T01:43:22Z")

</div>

Did that solve the problem?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 August 2020 01:43 UTC](https://discourse.nodered.org/t/need-help-with-if-then/29263/4 "2020-08-30T01:43:23Z")

</div>

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