As part of a larger effort to get a better understanding of our energy consumption and production, I wanted to predict the production of our solar arrays on a day to day basis. This requires information on the Global Horizontal Irradiance, which is calculated in the weather models by the Royal Netherlands Meteorological Institute KNMI. Because the KNMI is a publicly funded organisation and is part of the Ministry of Infrastructure and Water Management, the data generated by the KNMI is made publicly available. The output from the weather models is published on the KNMI Data Platform. You can download this data using the access points that the KNMI prescribed and then process the data yourself. It is, however, much simpler to download the pre-processed data from Meteoserver. This company downloads the data from the KNMI, pre-processes it into useful information and published it to their customers. For home use and hobby purposes, they have a free alternative available as well in the weerlive.nl website, which has its own API [1]. In this article, I will briefly explain how to access the data through the latter API [2].

The API access is limited to 300 requests per day. This should be more than enough to get the weather forecast on an hourly basis or just once per day as I do. You need an API key to access for locations other than Amsterdam, and you can request one from weerlive.nl here. Because the API is pretty well documented on the weerlive website, I will not copy that information here. Below you will find a Python 3.x example with verbose comments that access the data for the location of the KNMI in De Bilt and extracts the hourly forecase for the local temperature and global horizontal irradiance.

import requests  # python library for HTTP requests

def get_weerlive_forecast(lat_deg, lon_deg, api_key):
  #  Retrieve the weather forecast from weerlive.nl
  url = f"https://weerlive.nl/api/weerlive_api_v2.php"
  payload = {'key': api_key, 'locatie': f"{lat_deg},{lon_deg}"}

  # For debugging purposes you can override the payload, 
  # so that we can use a dummy api key, that does not have
  # a cap on the number of requests/day. 
  # payload = {'key': 'demo', 'locatie': "Amsterdam"}

  response = requests.get(url, params=payload)

  # Store JSON data
  response_json = response.json() 
  
  # We are only interested in the hourly forecast
  # so we will unpack that separately.
  hourly_forecast_24h = response_json["uur_verw"]
  
  # Loop over every entry in the hourly forecasts
  for hourly_forecast in hourly_forecast_24h:
    # Timestamp in format: 15-06-2024 11:00 = DD-MM-YYYY HH:MM
    timestamp= hourly_forecast["uur"] 
    # Temperature in degrees Celcius
    temperature = hourly_forecast["temp"]
    # Global Horizontal Irradiance (GHI) or Global Radiation (GR)
    # in W/m2
    ghi = hourly_forecast["gr"]
    
    # Print the results to the console
    print(f"Timestamp: {timestamp}; GHI: {ghi:0.1f} W/m2")

if __name__=="__main__":
  get_weerlive_forecast(lat_deg = 52.1015474, # Latitude of your location
                        lon_deg = 5.1754243,  # Longitude of your location
                        api_key = 'demo')     # Get the API key from weerlive.
                        

Bibliography

[1] Royal Netherlands Meteorological Institute KNMI, KNMI Data Platform – Weather Forecasts, URL: https://dataplatform.knmi.nl/group/weather-forecast. Accessed: 28 june 2024

[2] Weerlive / Meteoserver, KNMI Weer API, URL: https://weerlive.nl/delen.php, Accessed: 28 june 2024

Back to Top