# Using 'if' statement for Weather Data on NodeRed

**URL:** <https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005>\
**Category:** General\
**Created:** [22 October 2019 10:38 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005 "2019-10-22T10:38:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [22 October 2019 10:38 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005/1 "2019-10-22T10:38:55Z")

</div>

Hello all,

I am using OpenWeatherMap node on Node-Red to fetch weather data for my city. But I am trying to use 'if' statement with a function node. But I am not sure if I am actually doing it right as I am not getting any data on debug node. I attempted to use it for my personal understanding by checking the exact temperature and then forming an 'if' statement. For eg:

if ((msg.payload.tempc === "13.3"))  
{msg.payload = "Wear a Jacket"}

else msg.payload = msg  
return;

But it is wrong. I would actually want for the statement "if the temperature is less than 15, wear a jacket"

Thanks and Regards

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 October 2019 10:43 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005/2 "2019-10-22T10:43:07Z")

</div>

What is the output of the openweathermap node ?

here you are testing against a string

`msg.payload.tempc === "13.3"`

depending on the output of the node, i suspect this should be:

`msg.payload.tempc === 13.3` or for your request: `msg.payload.tempc < 15`

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [22 October 2019 10:49 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005/3 "2019-10-22T10:49:07Z")

</div>

Thanks a lot for your reply. I am going to try what you suggested, my actual output is in the screenshot below

 ![2019-10-22-144446_1280x1024_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f201a14e636ad287a9212f984726c98f7a964e28.png)

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [22 October 2019 10:58 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005/4 "2019-10-22T10:58:09Z")

</div>

It works like you suggested,

if ((msg.payload.tempc \< 15))  
{msg.payload = "Wear a Jacket"}

else  
msg = msg.payload  
return msg;

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 October 2019 11:06 UTC](https://discourse.nodered.org/t/using-if-statement-for-weather-data-on-nodered/17005/5 "2019-10-22T11:06:35Z")

</div>

Nice. Can you click "solution" under my reply above ?
