Looking to hire Laravel developers? Try LaraJobs

laravel-switchbot maintained by revolution

Description
SwitchBot API for Laravel
Author
Last update
2026/06/29 23:17 (dev-main)
License
Links
Downloads
7 621

Comments
comments powered by Disqus

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

Ask DeepWiki

Requirements

  • PHP >= 8.3
  • Laravel >= 12.0

Installation

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.

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());
}
use Illuminate\Support\Facades\Http;

$response = Http::switchbot()->get('scenes');
dump($response->json());

Testing

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