chipneedham/laravel-govee
Laravel package to control Govee smart lights via the Govee Smart Home API. Includes a Govee facade to list devices and control power, brightness, RGB/hex color, and white temperature. Configure with your GOVEE_API_KEY.
This package, Laravel Govee, provides seamless integration with Govee smart home devices (e.g., Bluetooth-enabled sensors, lights, and environmental monitors). To get started:
Installation
Run composer require chipneedham/laravel-govee and publish the config file with php artisan vendor:publish --provider="ChipNeedham\LaravelGovee\GoveeServiceProvider".
Configuration
Set your Govee API key and device credentials in .env:
GOVEE_API_KEY=your_api_key_here
GOVEE_DEVICE_ID=your_device_id
First Use Case Fetch device data in a controller or command:
use ChipNeedham\LaravelGovee\Facades\Govee;
$deviceData = Govee::getDeviceData('your_device_id');
return response()->json($deviceData);
Check the Govee API docs for supported endpoints.
Device Management
$devices = Govee::listDevices();
Data Retrieval
$metrics = Govee::getMetrics('device_id', ['temperature', 'humidity']);
Govee::fetchAndQueueMetrics('device_id', $metrics);
Event-Driven Updates Subscribe to device events (e.g., threshold alerts) using Laravel’s event system:
Govee::listenForAlerts('device_id', function ($data) {
event(new DeviceAlertReceived($data));
});
$data = Cache::remember("govee_{$deviceId}_metrics", now()->addMinutes(5), function () use ($deviceId) {
return Govee::getMetrics($deviceId);
});
config/govee.php for troubleshooting:
'log' => env('GOVEE_LOG_ENABLED', false),
API Rate Limits
try {
$data = Govee::getDeviceData($id);
} catch (\ChipNeedham\LaravelGovee\Exceptions\RateLimitExceeded $e) {
sleep(2); // Retry after delay
}
Device Pairing
Timezone Mismatches
$localTime = $data['timestamp']->setTimezone('America/New_York');
GOVEE_LOG_LEVEL=debug in .env to log raw API responses.E07A1B2C3D4). Use:
if (!Govee::isValidDeviceId($deviceId)) {
throw new \InvalidArgumentException("Invalid device ID format.");
}
Custom Endpoints
Extend the package by adding new methods to ChipNeedham\LaravelGovee\GoveeManager:
// app/Providers/GoveeServiceProvider.php
public function boot()
{
$this->app->make('ChipNeedham\LaravelGovee\GoveeManager')->extend('custom', function () {
return new CustomGoveeClient();
});
}
Webhook Support For real-time updates, integrate with Govee’s webhook system (if available) and forward events to Laravel’s queue:
// routes/web.php
Route::post('/govee-webhook', [GoveeWebhookController::class, 'handle']);
Testing
Use the GoveeFake facade for unit tests:
Govee::shouldReceive('getDeviceData')->once()->andReturn($mockData);
How can I help you explore Laravel packages today?