https://github.com/invokable/laravel-switchbot
https://github.com/invokable/laravel-switchbot
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/invokable/laravel-switchbot
- Owner: invokable
- License: mit
- Created: 2022-10-09T07:41:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-18T11:55:09.000Z (3 months ago)
- Last Synced: 2026-03-30T02:44:47.490Z (2 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/revolution/laravel-switchbot
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwitchBot API for Laravel
This package provides a simple integration with the SwitchBot API using Laravel's HTTP client macros.
For specific API details, please refer to the official SwitchBot API repository: https://github.com/OpenWonderLabs/SwitchBotAPI
[](https://deepwiki.com/invokable/laravel-switchbot)
## Requirements
- PHP >= 8.3
- Laravel >= 12.0
## Installation
```shell
composer require revolution/laravel-switchbot
```
## Configuration
Get tokens from the SwitchBot app.
### .env
```
SWITCHBOT_TOKEN=
SWITCHBOT_SECRET=
```
## Usage
Built as a Laravel HTTP client macro.
```php
use Illuminate\Support\Facades\Http;
$response = Http::switchbot()->get('devices');
dump($response->json());
$deviceId = $response->json('body.deviceList.0.deviceId');
if (filled($deviceId)) {
$response = Http::switchbot()->get("devices/$deviceId/status");
dump($response->json());
}
```
```php
use Illuminate\Support\Facades\Http;
$response = Http::switchbot()->get('scenes');
dump($response->json());
```
## Testing
```php
use Illuminate\Support\Facades\Http;
Http::fake([
'*' => Http::response([
"statusCode" => 100,
"body" => [
"deviceList" => [],
"infraredRemoteList" => [],
],
"message" => "success",
]),
]);
$response = Http::switchbot()->get('devices');
$this->assertSame(100, $response->json('statusCode'));
```
## LICENSE
MIT