26 Star 86 Fork 19

Yeelight / miot-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

StyleCI Build Status Build Status Build Status Total Downloads Latest Stable Version License 996.icu

小米IOT控制端API及小米IOT设备规范 SDK

安装

composer require yeelight/miot-api

使用

$appId = 'Your App-Id';
// 用户oauth取得的accessToken
$accessToken = 'user access token';
$api = new Api($appId, $accessToken);

// 默认为大陆host,如果要获取其他地区设备的时候,可以setHost设置host
$api->setHost('api.home.mi.com');

// 一次性获取到包含了 serialNumber (原did)的设备列表
$devices = $api->devicesList();

// 根据 piid 获取 属性值 
$properties = $api->properties([
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk4OTg3NRVoAA.2.1',
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk4OTg3NRVoAA.2.2',
]);
        
$properties = [
    'properties' => [
        [
            "pid" => "M1GAxtaW9A0LXNwZWMtdjIVgoAFGA15ZWVsaW5rLW1vbm8xFRQYCDEzMTgwNzc2FWYA.2.2",
            "value" => 75
        ]
    ]
];

// 设置属性
$api->setProperties($properties);


// 读取用户在米家设置好的场景列表
$secenes = $api->scenes();

// 主动触发场景
$scene_id = '1031976223';

$api->triggerScene($scene_id);

// 读取家庭列表
$homes = $api->homes();

// 订阅属性变化
$properties = [
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA15ZWVsaW5rLW1vbm8xFRQYCDEzMTgwNzc2FWYA.2.2',
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk4OTg3NRVoAA.2.1',
];
$customData = [
    'test' => 'test'
];
$receiverUrl = 'https://www.xxx.com/receiver';
$api->subscript($properties, $customData, $receiverUrl);

// 退订属性变化
$api->unSubscript($properties);

// 优雅的设置单个设备属性
$did = 'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk2NTYwNRVoAA';
$type = "urn:miot-spec-v2:device:light:0000A001:yeelink-color1:1";
$data = [
    'on' => true,
    'brightness' => 99,
    'color-temperature' => 2100,
    'color' => 5777215
];
$requestInfo = $api->setPropertyGraceful($did, $type, $data);

// 优雅的设置多个设备属性
$data = [
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk2NTYwNRVoAA' => [
        'type' => 'urn:miot-spec-v2:device:light:0000A001:yeelink-color1:1',
        'data' => [
            'on' => true,
            'brightness' => 99,
            'color-temperature' => 2100,
            'color' => 2777215
        ]
    ],
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGAt5ZWVsaW5rLWN0MhUUGAg4NzEzMDQyMhWcCAA' => [
        'type' => 'urn:miot-spec-v2:device:light:0000A001:yeelink-ct2:1',
        'data' => [
            'on' => true,
            'brightness' => 50,
            'color-temperature' => 3500
        ]
    ]
];
$requestInfo = $api->setPropertiesGraceful($data);

// 优雅的获取单个设备属性
$did = 'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk2NTYwNRVoAA';
$type = "urn:miot-spec-v2:device:light:0000A001:yeelink-color1:1";
// data为空数组时,获取所有可读属性
$data = [
    'on',
    'brightness',
    'color-temperature',
    'color'
];
$attibutes = $api->getPropertyGraceful($did, $type, $data);

// 优雅的获取多个设备属性
$data = [
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGA55ZWVsaW5rLWNvbG9AyMRUUGAg0NTk2NTYwNRVoAA' => [
        'type' => 'urn:miot-spec-v2:device:light:0000A001:yeelink-color1:1',
        'data' => [
            'on',
            'brightness',
            'color-temperature',
            'color'
        ]
    ],
    'M1GAxtaW9A0LXNwZWMtdjIVgoAFGAt5ZWVsaW5rLWN0MhUUGAg4NzEzMDQyMhWcCAA' => [
        'type' => 'urn:miot-spec-v2:device:light:0000A001:yeelink-ct2:1',
        'data' => [] // 为空时,获取所有可读属性
    ]
];
$attibutes = $api->getPropertiesGraceful($data);

// 订阅设备的所有可订阅属性
$devices = $api->devicesList();
$customData = [
    'test' => 'test'
];
$receiverUrl = 'https://www.xxx.com/receiver';
$requestInfo = $api->subscriptByDevices($devices, $customData, $receiverUrl);

// 退订设备的所有订阅属性
$devices = $this->api->devicesList();
$requestInfo = $this->api->unSubscriptByDevices($devices);

参考资源

Security Vulnerabilities

If you discover a security vulnerability within this library, please send an e-mail to Sheldon Lee via lixiaodong@yeelight.com. All security vulnerabilities will be promptly addressed.

License

This library is open-sourced software licensed under the MIT license.

MIT License Copyright (c) 2018 Yeelight Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

小米IOT控制端API及小米IOT设备规范 SDK 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/yeelight/miot-api.git
git@gitee.com:yeelight/miot-api.git
yeelight
miot-api
miot-api
master

搜索帮助

14c37bed 8189591 565d56ea 8189591