Discover the value of weather data in creating actionable intelligence and how businesses can use weather APIs to access real-time weather information and customize it to meet their specific needs.

Improve Your Business Operations With A Customer Weather App

Weather data has always been somewhat democratized, with many governments investing in the collection of weather data daily and providing it as a free service to the public. While this is itself impressive, it doesn’t solve the problem entirely. After all, although we don’t often think of it this way, our interaction with weather conforms to the “actionable intelligence” model. In other words, we interact with weather data, whether it is on our phone, on television, or hearing our neighbor talk about their swollen knee which means a storm is on the way. However, there is only value created when we get actionable intelligence, when we convert the weather information into instructions for how we need to react. In this way, weather for us can be measured as time-to-action (or more specifically, time-to-correct-action). We want the shortest amount of time possible between having the weather data and knowing what actions to take as a result. Actions could include “bring an umbrella,” “reschedule the picnic,” or even “get into the cellar NOW.”

The great news for businesses with specific weather needs is that not only the data, but the ability to turn it into actionable intelligence, has never been easier. A recent post shows some of the tools available to create real time applications for tracking weather using Node.js. There are many different ways to access weather data and convert it to what your business needs, whether it is identifying safer routes for logistics, creating alerts for a specific area, or simply tracking the weather in a location of interest (i.e., a loading dock, field site).

That said, it’s also important to know that gaining this information and customizing it for your business is not only possible, it’s grown incredibly simple. Let’s look at an example using a weather API from Tomorrow.io forecast extraction. In this case, the platform has simplified the process so much that you can build your own weather app with a single call. 

One Call Weather App

For this example, you can create a climatic forecast with Node.js that can look ahead up to 15 days, and even back up to 6 hours (not offered on many weather apps, but has a number of use cases for businesses), and can select over 80 data points to create the forecast.

Setup

This call will use the “Timelines” endpoint. While there is a premium version, the free version will still allow you to pull a significant amount of data for your app.

const fetch = require('node-fetch');
const querystring = require('query-string');
const moment = require('moment');

// set the timelines get endpoint as the target URL
const getTimelineURL = "https://api.tomorrow.io/v4/timelines";

Get Your Key

Users must input their API key, which can be obtained by signing up to the platform and then accessing the provided key.

// get your key from app.tomorrow.io/development/keys
const apiKey = "YOUR_API_KEY";

Select Location

For the location, you can select either a “latlong” pair, which is separated by a comma, or you can access the list of predefined locations in the system. There are countless GPS coordinate converters available; we used this one in order to get the location of interest via an address, and were able to convert it to latlong (it can also convert for degrees, minutes, seconds). We will leave it to you to uncover for what location this example is getting a weather forecast.

// pick the location as a lat/lon pair
let location = [40.758, -73.9855];

List Fields

Now we come to the fun part. For this example, we will use some of the typical data points that would be of interest in a weather app. However, the full list is here along with the proper data formats. There are also additional data samples you can pull that are normally part of the premium data layers, such as air quality and pollen. If you need specialized data points like solar irradiance, soil moisture, or even wave height, the premium version includes them. For this example, it is more than enough to track precipitation (intensity and type), wind (speed, gust, direction), temperature (also apparent temp), clouds (cover, base, ceiling), and the weather code.

// list the fields
const fields = [
    'precipitationIntensity',
    'precipitationType',
    'windSpeed',
    'windGust',
    'windDirection',
    'temperature',
    'temperatureApparent',
    'cloudCover',
    'cloudBase',
    'cloudCeiling',
    'weatherCode'
]

Choose the Unit System

The unit system is straightforward, allowing for either metric or imperial data.

// choose the unit system, either "metric" or "imperial"
const units = 'imperial';

Set Timesteps

For the timesteps, you can select from a variety of intervals but can also pull multiple intervals. Choices include 1 minute, 5 minutes, 15 minutes, 30 minutes, 1 hour, or 1 day. It can also include “current”, which pulls real-time data. This step also allows for additional tuning: you can include Min, Max, or Avg suffixes to each field. If you don’t include these the call will default to the Max value for that timestep. One other feature is that you can include a MinTime or MaxTime that will show the earliest these values will be met for a day-long interval.

const timesteps = ["current", "1h", "1d"];

Configure Time Frame and Time Zone

For the time frame, you can select up to 6 hours previous and up to 15 days into the future. For this example, we set the time frame from the current time up to a single day ahead. Notice that for this step, the UTC timezone is used. In order to set your target timezone, you can specify it through the “timezone” variable, which uses the standard IANA Time Zone database format.

// configure the time frame up to 6 hours back and 15 days out

const now = moment.utc();
const startTime = moment.utc(now).add(0, "minutes").toISOString();
const endTime = moment.utc(now).add(1, "days").toISOString();

// specify the timezone using standard IANA format
const timeZone = "America/New_York";

Request Timelines

Finally, using the “result” JSON response you can compile all the requested data and output it accordingly.

const getTimelineParameters = queryString.stringify({
    apikey,
    location,
    fields,
    units,
    timesteps,
    startTime,
    endTime,
    timezone,
}, { arrayFormat: 'comma' });

fetch(getTimelineURL + "?" + getTimelineParameters, { method: 'GET', compress: true })
    .then(response => response.json())
    .then((json) => console.log(json))
    .catch((error) => console.error("error: " + error));

Final Thoughts

Now you have everything you need to build a weather app with the key metrics needed by your business. There is an interactive version of this call that can be run through Postman if you want to experiment with the variables and have instant feedback on the results. Good luck!


Sponsors