This module adds a block that displays weather forecasts based on a configured region. It requires the Geolocation Field module.
Weather Forecast provides a block that shows the current weather, and optionally a forecast for the coming days, for any place in the world. Data comes from OpenWeatherMap, and the free plan is all you need.
Place the block, type a city name, and you're done. Small towns work too, because place names are looked up with OpenWeatherMap's geocoding service before the weather is fetched.
Features
- Current weather: temperature, conditions and icon, with optional details: feels-like temperature, wind, humidity, sunrise and sunset.
- Forecast for the next 1 to 5 days, with daily highs and lows and an icon for each day.
- Any location:
- a city or town name, optionally with a country code to tell places with the same name apart, for example
Springfield,US; - or exact latitude and longitude.
Saving the block checks that OpenWeatherMap knows the place, and confirms which one was found.
- a city or town name, optionally with a country code to tell places with the same name apart, for example
- Metric or imperial units (°C and m/s, or °F and mph), per block. Place several blocks to show several cities.
- Local time: the observation time, sunrise and sunset are shown in the city's own time zone, not your site's.
- Multilingual: weather descriptions follow the visitor's language, and all labels are translatable.
- Fast and within free-plan limits: weather data is cached, 15 minutes by default, so the API is called at most once per location in that time, not on every page view.
- Safe with your API key: the key is checked when you save it and never written to the logs. You can keep it out of configuration exports by setting it in settings.php.
- Themeable: the output uses the
weather-forecast.html.twigtemplate and a small stylesheet.
Requirements
- Drupal 10.3 or later, or Drupal 11.
- A free OpenWeatherMap API key. The module uses the Current weather, 5 day / 3 hour forecast and Geocoding APIs, which are all included in the free plan. New keys can take a couple of hours to become active.
No other modules are needed. Since 1.0.6, Weather Forecast no longer depends on the Geolocation module, so it can be installed alongside any version of Geolocation, or without it.
Installation
Install as you would normally install a contributed Drupal module. For further information, see Installing Drupal Modules.
composer require drupal/weather_forecast drush pm:enable weather_forecast
Configuration
- Go to Configuration » Web services » Weather API settings (
/admin/config/services/weather-settings) and enter your API key. Optionally, change how often the weather is updated. - Place the Weather forecast block at Structure » Block layout, and choose the location, units, number of forecast days and whether to show the details.
To keep the API key out of configuration exports, set it in settings.php instead:
$config['weather_forecast.weather_settings']['api_key'] = getenv('OPENWEATHERMAP_KEY');Support
Report bugs and request features in the issue queue.
Ask your assistant about Weather Forecast Block
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- block Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.