pjanisio/ewelink-api-php

API connector for Sonoff/eWeLink devices

dev-main 2025-07-08 12:45 UTC

This package is auto-updated.

Last update: 2025-07-08 12:46:17 UTC


README

Packagist PHP >= 7.4 License

ewelink-api-php lets you talk to your eWeLink–enabled devices (Sonoff, KingArt, etc.) directly from PHP. It wraps the official HTTP & WebSocket endpoints, handles OAuth, and gives you a neat object‑oriented façade.

📦 Installation

composer require pjanisio/ewelink-api-php

Composer installs the library, creates vendor/autoload.php, and you’re ready to go.

🚀 Quick‑start

<?php
require __DIR__.'/vendor/autoload.php';

use pjanisio\ewelinkapiphp\HttpClient;

$http = new HttpClient();  // takes creds from constants / env
$token = $http->getToken(); // OAuth flow (auto‑refreshes)

$devices = $http->getDevices(); // Devices façade
$list    = $devices->getDevicesList();

print_r($list);  // see everything at once

$lampId  = '100xxxxxx';
$devices->setDeviceStatus($lampId, ['switch' => 'on']);  // turn it on

Full examples live in the Wiki.

✅ Features

Area What you can do
Discovery • Fetch all devices in one call
• Search by deviceid or human name
• Persist raw data as devices.json
Status • Read any single param live (switch, voltage, power, …)
• Grab all live params at once
• Check if a device is online
Control • Set one or many params (HTTP)
• Multi‑channel helpers (switches[n])
• WebSocket realtime control
Monitoring • Live power metrics (voltage / current / power)
• Device history endpoint (/v2/device/history)
Maintenance • Force wake‑up (handshake + echo params)
• Family/home helper (getCurrentFamilyId)
Dev tools • PSR‑4 autoloading via Composer
DEBUG mode – full request/response log to debug.log

🖥️ Demo Monitoring App

Need an out‑of‑the‑box dashboard? Check the companion project ewelinkapiphp‑device‑monitoring – asynchronous UI, HTTP + WS under the hood.

Monitoring screenshot

🗂 Documentation

  • Getting started / API reference → see the Wiki Pages
  • Developer notes (architecture, contribution guide) → Developers Wiki

⚙️ Requirements

  • PHP 7.4 or newer
  • Extensions: curl, json (both enabled by default on typical PHP installs)

📝 License

MIT – do what you want, just keep the copyright notice.

Happy hacking & enjoy your smart devices!