Using 'if' statement for Weather Data on NodeRed

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

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

Thanks and Regards

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

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

It works like you suggested,

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

msg = msg.payload
return msg;

Thanks a lot :slight_smile:

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