# How to apply if else condition?

**URL:** <https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939>\
**Category:** General\
**Created:** [8 October 2020 13:31 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939 "2020-10-08T13:31:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![UtsavPatel](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@UtsavPatel](https://discourse.nodered.org/u/UtsavPatel)\
**Post date:** [8 October 2020 13:31 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939/1 "2020-10-08T13:31:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6d77fa8be035091ff6a8f7caf4832a2049a5416.png)  
Hi,  
I am trying to design a smart irrigation app in my academic project. In this image, I got the Average value of all sensor input but now I need to add some condition like if average \< 35000 then it will generate an email notification. so I have no idea how to implement the condition. So, please help me out...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 October 2020 13:52 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939/2 "2020-10-08T13:52:46Z")

</div>

A switch allows you to do an "if" operation so instead of using JS in a function, you could add a `switch` node BEFORE and use the `<` less than compare option.

NOTE: By the looks of it, you could benefit from spendin an hour watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about an hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![UtsavPatel](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@UtsavPatel](https://discourse.nodered.org/u/UtsavPatel)\
**Post date:** [9 October 2020 02:25 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939/3 "2020-10-09T02:25:13Z")

</div>

Thank you buddy  
I have tried this and put switch but it is not working so am I doing something wrong in switch..? please check it..

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8c4ad847a526f20de65f7e9ba5fd396ed8e7591c.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 October 2020 07:50 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939/4 "2020-10-09T07:50:21Z")

</div>

Is the value in msg.payload or msg.payload.avg? also are you testing a number or string?

---

<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:** [8 December 2020 07:50 UTC](https://discourse.nodered.org/t/how-to-apply-if-else-condition/33939/5 "2020-12-08T07:50:21Z")

</div>

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