A Node-RED flow to Monitor the Weather

In this guide you will learn how to create a Node-RED to monitor the weather and send a tweet when the skies are clear.

What is Node RED?

Node-RED is a visual tool for wiring the Internet of Things developed by IBM Emerging Technology and the open source community. Using Node-RED, developers wire up input, output and processing nodes to create flows to process data, control things, or send alerts. It works by allowing you to wire up web services or custom “nodes” to each other, or to things, to do things like:

  • Send an email on a rainy weather forecast.
  • Push sensor data to services like Twitter.
  • Perform complex analysis on data with ease.

showcase-flow

What is FRED

Front End for Node-RED (FRED) manages instances of Node-RED for multiple users in the cloud. We manage and optimize your instance of Node RED so you worry about accomplishing your project, not setting up and maintaining your Node-RED instance.

Create a FRED Account

To begin our tutorial create your own Node-RED instance in the cloud. Register for a free account at http://fred.sensetecnic.com.

After registering make sure to activate your account via your email. You will not be able to login until you validate your account.


About Sense Tecnic: Sense Tecnic Systems Inc have been building IoT applications and services since 2010. We provide FRED, cloud hosted Node-RED as a service to the community. We also offer a commercial version to our customers, as well as professional services. Learn more.


 Creating a flow to monitor the weather

If you are new to Node-RED, we recommend you read the How to create a Node-RED flow guide prior to this.

We will first drag and drop from the left pane onto the canvas a weather node.

Double click on the node and fill out the modal form with your location. Type your city and country in the fields. You will also need to obtain your API key from openweathermap.org in order to get response from the server. Once you have all the information, click on “Ok”.

If we drag and drop a “debug” node and click on “Deploy” we can see that the payload object from the Weather node is:

[javascript]
{
“weather”: “Clear”,
“detail”: “sky is clear”,
“tempk”: 295.104,
“tempc”: 21.903999999999996,
“humidity”: 53,
“maxtemp”: 295.104,
“mintemp”: 295.104,
“windspeed”: 2.22,
“winddirection”: 273.007,
“location”: “Vancouver”,
“sunrise”: 1432038196,
“sunset”: 1432094081,
“clouds”: 8,
“description”: “The weather in Vancouver at coordinates: 49.25, -123.12 is Clear (sky is clear).”
}
[/javascript]

We are interested in the ‘”weather”: “Clear”‘ bit. Drag and drop a function node:

Now double click on the Function node and type/copy this:

[javascript]
if (msg.payload.weather === “Clear”) {
msg.payload = “Clear skies ahead today!”
return msg;
}
return null;
[/javascript]

This will parse the payload for the weather key and compare it to the string “Clear”, if it is equal it will re-write the message payload with our own string “Clear skies ahead today!”. Otherwise it will return a null message. This last bit is important, in Node-RED nodes ignore null messages.

We can do all sorts of things now, we can wire this message to an email node, or pushbullet node. For this tutorial we will use the Twitter output node. Insert a Twitter out node and fill out your credentials:

Click on “Deploy”:

You are done! Now whenever there is a message sent from the openweathermap node, the message will be post to your Tweeter account!

4 thoughts on “A Node-RED flow to Monitor the Weather”

    1. Hello Archana, this could be due to many factors. Can you provide more detail in what you have set up in the flow? any output or error messages in the console?

  1. Has something changed with FRED? I can’t find the openweathermap node, or indeed a lot of nodes that are shown on the various tutorials.

Leave a Reply