Node-RED OpenWeatherMap Node
This package provides two Node-RED nodes, 'OpenWeatherMap' (input) and 'OpenWeatherMap Query' (query), for integrating weather data from the OpenWeatherMap API into Node-RED flows. The 'input' node periodically fetches current weather or a 5-day forecast based on configured location (city/country or lat/lon) and outputs a message if data changes. The 'query' node allows on-demand fetching of current weather, triggered by input messages containing location details. It returns detailed weather information including temperature, humidity, wind, and precipitation, as well as an object with full API data. Currently at version 1.0.1, it is part of the broader Node-RED ecosystem and follows its release cadence for updates and compatibility. A key differentiator is its seamless integration into Node-RED's visual programming environment, abstracting direct API calls and simplifying complex API interactions into configurable nodes. This makes it accessible for users who prefer visual programming over writing code for data fetching and processing.
Common errors
-
Error: API key not provided or invalid
cause The OpenWeatherMap API key field in the node configuration is empty, malformed, or has been revoked/expired.fixObtain a valid API key from openweathermap.org/appid and enter it correctly into the API Key field in the Node-RED node's configuration settings. -
Error: No data received from OpenWeatherMap API
cause This typically indicates an issue with network connectivity from the Node-RED instance, incorrect location parameters in the input message/node configuration, or an issue with the OpenWeatherMap API itself.fixVerify that your Node-RED instance has internet access. Check the `city`, `country`, `lat`, and `lon` parameters for accuracy. Also, confirm that your OpenWeatherMap API key is active and not exceeding rate limits.
Warnings
- gotcha An OpenWeatherMap API key is mandatory for the nodes to function correctly. Without a valid API key configured in the node properties, the nodes will fail to retrieve any weather data.
- gotcha The 'OpenWeatherMap' (Input Node) is designed to output a message only when the fetched weather data changes. If the weather conditions remain stable, you might not see frequent outputs from this node.
- gotcha The 5-day forecast data is returned as a 5-part array, where each element represents aggregated daily weather information, not granular hourly forecasts. The structure includes various temperatures (day, min, max, night, eve, morn) and other conditions.
Install
-
npm install node-red-node-openweathermap -
yarn add node-red-node-openweathermap -
pnpm add node-red-node-openweathermap
Quickstart
/*
Step 1: Install the node in your Node-RED environment.
Open your Node-RED user directory (typically ~/.node-red) in your terminal and run:
*/
// npm install node-red-node-openweathermap
/*
Step 2: Restart Node-RED to load the new nodes (if it was running).
*/
// node-red
/*
Step 3: In the Node-RED editor (usually accessible at http://localhost:1880),
drag an "OpenWeatherMap Query" node from the palette onto the canvas.
Double-click the node to configure it, providing your OpenWeatherMap API Key
(obtained from openweathermap.org/appid).
Step 4: To trigger the 'OpenWeatherMap Query' node and fetch current weather
for a specific location, inject a message (e.g., using an 'Inject' node)
with the following structure:
*/
const msg_by_city = {
payload: {},
location: {
city: "London",
country: "UK"
}
};
// Alternatively, you can specify location using latitude and longitude:
const msg_by_coords = {
payload: {},
location: {
lat: 51.5074,
lon: 0.1278
}
};
/*
The 'OpenWeatherMap Query' node will then output a message (msg.payload)
containing detailed weather data, similar to the following:
{
"description": "light rain",
"weather": "Rain",
"icon": "10d",
"id": 500,
"tempc": 15.2,
"tempk": 288.35,
"humidity": 87,
"windspeed": 2.1,
"winddirection": 240,
"location": "London",
"rain": 0.5,
"lat": 51.5074,
"lon": 0.1278,
"city": "London",
"country": "UK",
"time": 1678886400, // example epoch timestamp
"data": { /* full JSON from OpenWeatherMap API */ } // full JSON from OpenWeatherMap API
}
*/