pjanisio / ewelink-api-php
API connector for Sonoff/eWeLink devices
Fund package maintenance!
Buy Me A Coffee
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
- ext-openssl: *
Requires (Dev)
- phpstan/phpstan: ^1
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3
README
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‑example (after authorization)
$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 or multi params 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) |
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.
🗂 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
,openssl
( enabled by default on typical PHP installs)
📝 License
MIT – do what you want, just keep the copyright notice.
🔗 Integrations & Use Cases
- Drupal eWeLink module – integrate Sonoff devices into your Drupal site via drupal.org/project/ewelink
- Bee Hotel Reservation Access – powers the Bee Hotel, see Bee Hotel docs