Properties

$appId

$appId : 

App-Id 在开放平台申请: https://open.home.mi.com.

Type

$accessToken

$accessToken : 

Access-Token 小米账号登录后的Oauth Token 需要使用者自己实现小米oauth并获取到用户的access token oauth使用的应用id一定要与 App-Id一致.

Type

$specNS

$specNS : string

名字空间 必须是 miot-spec-v2.

Type

string

$httpClient

$httpClient : 

Type

$host

$host : 

Type

$port

$port : 

Type

$timeout

$timeout : 

Type

Methods

__construct()

__construct(null  $appId = null, null  $accessToken = null, string  $specNS = 'miot-spec-v2') 

Api constructor.

Parameters

null $appId
null $accessToken
string $specNS

setHost()

setHost(  $host) 

设置 请求的 host 默认为大陆host,如果要获取其他地区设备的时候,可以使用此方法设置host.

Parameters

$host

devices()

devices(boolean  $compact = false) : array|mixed

读取抽象设备列表.

Parameters

boolean $compact

如果希望读取设备列表时,只想读取最简单的信息,compact设置为true

Returns

array|mixed

get()

get(  $uri, array  $params = array()) : array|boolean|mixed

GET.

Parameters

$uri
array $params

Returns

array|boolean|mixed

deviceInformation()

deviceInformation(  $dids) : array|mixed

读取设备信息 读取一个设备 : GET /api/v1/device-information?dids=xxxx 读取多个设备: GET /api/v1/device-information?dids=xxxx,yyy,zzzzz.

Parameters

$dids

Returns

array|mixed

properties()

properties(  $pid, string  $voice = '') : array|mixed

读取属性 读取一个属性 : GET /api/v1/properties?pid=AAAD.1.1 读取多个属性:GET /api/v1/properties?pid=AAAD.1.1,AAAD.2.3 语音控制需要增加voice字段:GET /api/v1/properties?pid=AAAD.1.1,AAAD.2.3&voice={"recognition":"灯开了吗","semantics":"xxx"}.

Parameters

$pid
string $voice

Returns

array|mixed

setProperties()

setProperties(  $data) : array|boolean|mixed

设置属性.

Parameters

$data

Throws

\MiotApi\Exception\JsonException

Returns

array|boolean|mixed

put()

put(  $uri,   $data) : array|boolean|mixed

PUT.

Parameters

$uri
$data

Returns

array|boolean|mixed

invokeActions()

invokeActions(  $data) : array|boolean|mixed

调用方法 一次请求只能调用一个设备的一个方法 PUT /api/v1/action.

Parameters

$data

Throws

\MiotApi\Exception\JsonException

Returns

array|boolean|mixed

scenes()

scenes() : array|mixed

读取用户在米家设置好的场景列表.

Returns

array|mixed

triggerScene()

triggerScene(  $sceneId) : array|boolean|mixed

主动触发某个场景.

Parameters

$sceneId

Returns

array|boolean|mixed

post()

post(  $uri,   $data) : array|boolean|mixed

POST.

Parameters

$uri
$data

Returns

array|boolean|mixed

homes()

homes() : array|mixed

读取家庭列表.

Returns

array|mixed

subscript()

subscript(  $properties,   $receiverUrl) : array|boolean|mixed

订阅属性变化 开始订阅: POST /api/v1/subscriptions Content-Type: application/json Content-Length: 134 ​ * { "topic": "properties-changed", "properties": [ "AAAB.1.1", "AAAC.1.1", "AAAD.1.1", "AAAD.1.2" ], "receiver-url": "xxx" }.

订阅成功,应答如下: HTTP/1.1 207 Multi-Status Content-Type: application/json Content-Length: 156 { "expired": 36000, // 超时时间,单位为秒。 "properties": [ { "pid": "AAAB.1.1", "status": 0 }, { "pid": "AAAC.1.1", "status": -704002023 }, { "pid": "AAAD.1.1", "status": 0 } { "pid": "AAAD.1.2", "status": 705202023 } ] }

Parameters

$properties
$receiverUrl

Returns

array|boolean|mixed

unSubscript()

unSubscript(  $properties) : array|boolean|mixed

退订属性变化 POST /api/v1/subscriptions Content-Type: application/json Content-Length: 134 ​ * { "topic": "properties-changed", "properties": [ "AAAB.1.1", "AAAC.1.1", "AAAD.1.1", "AAAD.1.2" ], "receiver-url": "xxx" }.

退订成功,应答如下: HTTP/1.1 207 Multi-Status Content-Type: application/json Content-Length: 156 { "expired": 36000, // 超时时间,单位为秒。 "properties": [ { "pid": "AAAB.1.1", "status": 0 }, { "pid": "AAAC.1.1", "status": -704002023 }, { "pid": "AAAD.1.1", "status": 0 } { "pid": "AAAD.1.2", "status": 705202023 } ] }

Parameters

$properties

Returns

array|boolean|mixed

delete()

delete(  $uri,   $data) : array|boolean|mixed

DELETE.

Parameters

$uri
$data

Returns

array|boolean|mixed