A Laravel package for integrating Netatmo Weather Station API with your Laravel application
ekstremedia/laravel-netatmo-weather is a Laravel package for a laravel package for integrating netatmo weather station api with your laravel application.
It currently has 1 GitHub stars and 1.243 downloads on Packagist (latest version v1.4.0).
Install it with composer require ekstremedia/laravel-netatmo-weather.
Discover more Laravel packages by ekstremedia
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for integrating Netatmo Weather Station API with your Laravel application. This package provides an easy-to-use interface for authenticating with Netatmo, fetching weather data, and storing it in your database.
composer require ekstremedia/laravel-netatmo-weather
php artisan vendor:publish --tag=config --provider="Ekstremedia\NetatmoWeather\NetatmoWeatherServiceProvider"
php artisan vendor:publish --tag=public --provider="Ekstremedia\NetatmoWeather\NetatmoWeatherServiceProvider"
This publishes the images and the self-hosted CSS/JS the views load
(compiled Tailwind, Chart.js, Font Awesome) to public/netatmo-weather. The
views reference no CDNs, so they work behind a strict Content-Security-Policy
(script-src 'self', no 'unsafe-eval') — but only if these assets are
published. After upgrading the package, re-run the command with --force to
refresh them.
If you change any Blade view, rebuild the compiled stylesheet from the package root (requires Node 18+):
npm install
npm run build:css
php artisan migrate
Add the following to your .env file:
NETATMO_AUTH_URL=https://api.netatmo.com/oauth2/authorize
NETATMO_TOKEN_URL=https://api.netatmo.com/oauth2/token
NETATMO_API_URL=https://api.netatmo.com/api
# Optional: Customize the User model
# NETATMO_USER_MODEL=App\Models\User
The configuration file config/netatmo-weather.php contains:
return [
'name' => 'Laravel Netatmo Weather',
// The User model that will be used to associate with Netatmo stations
'user_model' => env('NETATMO_USER_MODEL', 'App\Models\User'),
// Netatmo API URLs
'netatmo_auth_url' => env('NETATMO_AUTH_URL', 'https://api.netatmo.com/oauth2/authorize'),
'netatmo_token_url' => env('NETATMO_TOKEN_URL', 'https://api.netatmo.com/oauth2/token'),
'netatmo_api_url' => env('NETATMO_API_URL', 'https://api.netatmo.com/api'),
];
use Ekstremedia\NetatmoWeather\Services\NetatmoService;
use Ekstremedia\NetatmoWeather\Models\NetatmoStation;
// Get the service instance
$netatmoService = app(NetatmoService::class);
// Find a weather station
$weatherStation = NetatmoStation::first();
// Fetch data from Netatmo API
// This will automatically cache data for 10 minutes
$data = $netatmoService->getStationData($weatherStation);
use Ekstremedia\NetatmoWeather\Models\NetatmoStation;
use Ekstremedia\NetatmoWeather\Models\NetatmoModule;
use Ekstremedia\NetatmoWeather\Models\NetatmoToken;
// Get all weather stations
$stations = NetatmoStation::all();
// Get a station with its modules
$station = NetatmoStation::with('modules')->first();
// Check if token is valid
if ($station->token->hasValidToken()) {
echo "Token is valid!";
}
// Manually refresh token
$station->token->refreshToken();
// Access module data
foreach ($station->modules as $module) {
echo "Module: {$module->module_name}\n";
echo "Type: {$module->type}\n";
echo "Battery: {$module->battery_percent}%\n";
}
If you want to use the included UI scaffolding, the package provides routes and controllers:
// In your routes/web.php or through the package routes
// The following routes are automatically registered:
Route::get('/netatmo', [NetatmoStationController::class, 'index'])->name('netatmo.index');
Route::get('/netatmo/create', [NetatmoStationController::class, 'create'])->name('netatmo.create');
Route::post('/netatmo', [NetatmoStationController::class, 'store'])->name('netatmo.store');
Route::get('/netatmo/{weatherstation}', [NetatmoStationController::class, 'show'])->name('netatmo.show');
Route::get('/netatmo/{weatherstation}/edit', [NetatmoStationController::class, 'edit'])->name('netatmo.edit');
Route::put('/netatmo/{weatherstation}', [NetatmoStationController::class, 'update'])->name('netatmo.update');
Route::delete('/netatmo/{weatherstation}', [NetatmoStationController::class, 'destroy'])->name('netatmo.destroy');
Visit /netatmo in your browser to manage your weather stations.
The package supports public sharing of weather station data. Each station can be individually configured for public access:
Via the UI:
Or in the edit form:
Programmatically:
$station = NetatmoStation::find($id);
$station->update(['is_public' => true]);
Once enabled, your weather station data will be accessible at:
/netatmo/public/{station-uuid}
This route:
is_public = true are accessibleIf your Netatmo account has access to multiple weather stations, the package will prompt you to select which physical device each configuration should display data from.
Option 1: Shared Access (Recommended)
Option 2: Separate Credentials (Fully Independent)
To display weather stations owned by others (family, friends, other locations):
Have the station owner share access:
Your account now sees multiple devices:
Example Setup:
To use completely independent Netatmo accounts for different stations:
Get API credentials for each Netatmo account:
Create station configurations with different credentials:
Authenticate each station independently:
/netatmo/authenticate/{station-1} → Login with Account A/netatmo/authenticate/{station-2} → Login with Account BEach station operates independently:
Visual Indicators:
66c3d88a••••)You can change which device a configuration uses at any time by visiting:
/netatmo/{station}/select-device
This is useful if you want to:
70:ee:50:5e:db:30)device_id columnThe package automatically tracks which modules are active and archives modules that are no longer detected by the Netatmo API.
Lost Module:
Removed Module:
Different Station Configurations:
/netatmo/{station}/authenticateid - Primary keyuuid - UUID for public routinguser_id - Associated userstation_name - Name of the stationdevice_id - Netatmo device MAC address (selected during setup if multiple devices exist, or auto-populated if only one device)is_public - Boolean flag for public access (default: false)client_id - Encrypted Netatmo Client IDclient_secret - Encrypted Netatmo Client Secretredirect_uri - OAuth redirect URIwebhook_uri - Webhook URI (optional)Stores data for each module (base station and add-on modules):
is_active - Boolean flag indicating if module is currently detected (default: true)access_token - Current access tokenrefresh_token - Refresh tokenexpires_at - Token expiration timestampNAMain - Main indoor moduleNAModule1 - Outdoor moduleNAModule2 - Wind gaugeNAModule3 - Rain gaugeNAModule4 - Additional indoor moduleThe package automatically caches weather data for 10 minutes to reduce API calls. You can modify this behavior in the NetatmoService class.
The package includes comprehensive test coverage using Pest PHP:
# Run all tests
composer test
# Run tests with coverage report
composer test-coverage
# Run specific test suite
vendor/bin/pest --testsuite Unit
vendor/bin/pest --testsuite Feature
# Run tests in parallel
vendor/bin/pest --parallel
# Check code style
composer format
vendor/bin/pint --test
Unit Tests (14 tests):
Feature Tests (13 tests):
Pest provides a more elegant and expressive testing syntax:
it('can create a netatmo station', function () {
$station = NetatmoStation::create([...]);
expect($station->uuid)->not->toBeNull();
});
The package uses GitHub Actions for continuous integration:
Contributions are welcome! Please feel free to submit a Pull Request.
This package is open-sourced software licensed under the MIT license.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.