baspa / buienradar-php-api
PHP package to provide a fluent syntax for the Buienradar API.
Fund package maintenance!
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.15.2 || ^8.0.1
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^3.8 || ^4.0 || ^5.3
- phpstan/phpstan: ^2.3.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This framework-agnostic PHP package provides a fluent syntax to interact with the Buienradar API.
Installation
You can install the package via composer:
composer require baspa/buienradar-php-api
Terms of use
This package is not affiliated with Buienradar. The weather data comes from Buienradar, which makes it available for free for use on your own website or intranet. In short, Buienradar's terms are:
- Use is only allowed for non-commercial purposes.
- Attribution is required: credit Buienradar.nl with a link to https://www.buienradar.nl.
- Use in mobile apps or for commercial purposes requires Buienradar's permission, which you can request through the same page.
These are Buienradar's terms, not this package's, and they can change; the linked page is what counts.
Usage
Initialization
Create an instance of the Buienradar class:
use Baspa\Buienradar\Buienradar; $buienradar = new Buienradar();
Caching
The JSON feed is downloaded once and reused by the same instance for 60 seconds, so calling forecast(), actualForecastForStation(), stations(), nearestStation(), sunrise() or sunset() one after another makes a single request. A failed download is not reused (the next call tries again), and rainForecast() is never cached. Call refresh() to make the next call download the feed again, or pass the cache time in seconds as the second constructor argument (0 turns it off):
$buienradar = new Buienradar(cacheSeconds: 300); $buienradar->refresh()->forecast();
Get the actual forecast report
$forecast = $buienradar->forecast()->report();
Get the short-term forecast
$forecast = $buienradar->forecast()->shortTerm();
Get the long-term forecast
$forecast = $buienradar->forecast()->longTerm();
Get the forecast for the upcoming 5 days
$forecast = $buienradar->forecast()->forFiveDays();
Get the forecast for one specific day
If you want to get the forecast for a specific day, you can use the forDay method. The parameter is the day you want to get the forecast for, where 0 is today, 1 is tomorrow, and so on. The maximum value is 4. Values outside 0–4 throw an InvalidArgumentException.
$forecast = $buienradar->forecast()->forDay(1);
Get the actual forecast for a specific measurement station
Choose either one of the following measuring stations:
- Meetstation Arnhem
- Meetstation Berkhout
- Meetstation De Bilt
- Meetstation Den Helder
- Meetstation Eindhoven
- Meetstation Ell
- Meetstation Gilze Rijen
- Meetstation Goes
- Meetstation Groenlo-Hupsel
- Meetstation Groningen
- Meetstation Heino
- Meetstation Herwijnen
- Meetstation Hoek van Holland
- Meetstation Hoogeveen
- Meetstation Hoorn Terschelling
- Meetstation Horst
- Meetstation Houtribdijk
- Meetstation IJmuiden
- Meetstation Lauwersoog
- Meetstation Leeuwarden
- Meetstation Lelystad
- Meetstation Lopik-Cabauw
- Meetstation Maastricht
- Meetstation Marknesse
- Meetstation Nieuw Beerta
- Meetstation Rotterdam
- Meetstation Rotterdam Geulhaven
- Meetstation Schiphol
- Meetstation Stavoren
- Meetstation Texelhors
- Meetstation Twente
- Meetstation Vlieland
- Meetstation Vlissingen
- Meetstation Volkel
- Meetstation Voorschoten
- Meetstation Westdorpe
- Meetstation Wijdenes
- Meetstation Wijk aan Zee
- Meetstation Woensdrecht
- Meetstation Zeeplatform F-3
MeasuringStation::ARCEN is deprecated: Buienradar no longer publishes Meetstation Arcen, so it always returns null. The cases for Gilze Rijen and Houtribdijk are now MeasuringStation::GILZE_RIJEN and MeasuringStation::HOUTRIBDIJK; the old misspelled names GILZE_RIJEEN and HOULTRIBDIJK still work as deprecated aliases.
For example, to get the forecast for the Volkel station, use:
use Baspa\Buienradar\Enum\MeasuringStation; $forecast = $buienradar->actualForecastForStation(MeasuringStation::VOLKEL);
Sun, all stations and nearest station
Sunrise and sunset come back as DateTimeImmutable in the Europe/Amsterdam timezone, or null when the feed has none. stations() returns the current measurement of every station; nearestStation() returns the one closest to a coordinate, skipping stations without coordinates.
$sunrise = $buienradar->sunrise(); // DateTimeImmutable, e.g. 2026-11-13 07:55:00 Europe/Amsterdam $sunset = $buienradar->sunset(); $stations = $buienradar->stations(); // array<int, ActualForecast> $station = $buienradar->nearestStation(52.1, 5.18); echo $station?->stationname; // 'Meetstation De Bilt' echo $station?->temperature;
Rain forecast (short-term precipitation)
Fetch the short-term precipitation forecast (next ~2 hours, per 5 minutes) for a coordinate:
use Baspa\Buienradar\Buienradar; $rain = (new Buienradar)->rainForecast(52.1, 5.18); foreach ($rain as $moment) { echo $moment->time; // '14:25' echo $moment->value; // 0–255 (raw Buienradar value) echo $moment->mm; // mm per hour echo $moment->isDry(); // true when value === 0 }
Error handling
Failed requests (network errors, timeouts, non-2xx responses or unexpected response bodies) do not throw: they return an empty result, or null for actualForecastForStation(), nearestStation(), sunrise() and sunset().
The default HTTP client times out after 10 seconds (5 seconds to connect). Pass your own Guzzle client to the constructor to change this: new Buienradar(new \GuzzleHttp\Client(['timeout' => 3])).
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Bug reports and pull requests are welcome; questions and ideas go to Discussions. Before you open a pull request, run the tests, static analysis and code style fixer:
composer test
vendor/bin/phpstan analyse
composer format
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.