gared/shelly-php-client
Composer 安装命令:
composer require gared/shelly-php-client
包简介
Client to access HTTP API of shelly devices
README 文档
README
You can use this library to access the HTTP API of a Shelly device. You can find the official API documentation here.
Installation
Use composer
composer require gared/shelly-php-client
Getting started
Configure client
$client = new \ShellyClient\HTTP\Client('http://192.168.1.10');
If you have configured login credentials you have to create the client like this:
$client = new \ShellyClient\HTTP\Client('http://shellyuser:secret@192.168.1.10');
Get current power usage
$meter = $client->getMeter(new \ShellyClient\Model\Request\MeterRequest()); $power = $meter->getPower(); echo "Current power usage: " . $power;
Power shelly plug "on"
$client->getRelay(0, \ShellyClient\Model\Request\RelayRequest::TURN_ON);
Full example
// Create new client for one device $clientLightA = new \ShellyClient\HTTP\Client('http://192.168.1.10', 'ShellyDeviceLightA'); $clientLightB = new \ShellyClient\HTTP\Client('http://192.168.1.20', 'ShellyDeviceLightB'); // Switch device on and get relay data $relayRequest = new \ShellyClient\Model\Request\RelayRequest(); $relayRequest->setRelayIndex(0); $relayRequest->setTurn(\ShellyClient\Model\Request\RelayRequest::TURN_ON); $relay = $clientLightA->getRelay($relayRequest); // check if timer has been set if ($relay->hasTimer()) { // do something } $meter = $clientLightA->getMeter(new \ShellyClient\Model\Request\MeterRequest()); // Get total power consumption in kW/h $kilowattHours = $meter->getTotalInKilowattHours(); // Get last three watt per minute power consumption values $counters = $meter->getCounters(); // Parallel call informations from device B $power = $clientLightB->getMeter(new \ShellyClient\Model\Request\MeterRequest())->getPower(); // Get device name set above in construct $deviceNameDeviceB = $clientLightB->getDeviceName(); // or use device name set in shelly device $deviceNameShelly = $clientLightB->getSettings(new \ShellyClient\Model\Request\SettingsRequest())->getName();
Supported Platforms
- You need at least PHP 8.1
Supported APIs
| API | Code |
|---|---|
| /light | $client->getLight(); |
| /meter | $client->getMeter(); |
| /relay | $client->getRelay(); |
| /settings | $client->getSettings(); |
| /settings/actions | $client->getActions(); |
| /settings/light | $client->getSettingsLight(); |
| /status | $client->getStatus(); |
gared/shelly-php-client 适用场景与选型建议
gared/shelly-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 448 次下载、GitHub Stars 达 10, 最近一次更新时间为 2021 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gared/shelly-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gared/shelly-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 448
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-24