Device Resource Management (Trait)
For Aqara devices, endpoint, function, and trait are the three core hierarchical levels used to describe and operate smart device features.
- Endpoint: Represents a physical or logical port of the device. Each endpoint identifies a sub-unit of the device (such as an individual socket hole in an outlet) and is uniquely marked by
endpointId. - Function: Each endpoint can contain one or more functions, such as "switch control", "status information," etc. Each function is distinguished by the
functionCode. - Trait: Each function is further composed of multiple traits. A trait is the smallest operable unit that can be read, written, or subscribed to and corresponds to a specific property or operation (for example: "switch status", "current power value," etc.). Each trait is identified by the
traitCode.
The following is an example using a double rocker switch "A" to illustrate these relationships:
Double Rocker Switch A
├─ Root (endpointId: 0)
│ └─ Basic Information (functionCode: BasicInformation)
│ │ └─ Firmware Version (traitCode: FirmwareRevision)
│ │ └─ ...
│ └─ ...
├─ Public (endpointId: 1)
│ └─ Energy Control (functionCode: EnergyManagement)
│ │ └─ Voltage Value (traitCode: CurrentVoltage)
│ │ └─ ...
│ └─ ...
├─ Switch (endpointId: 2)
│ └─ Switch Function (functionCode: Output)
│ │ └─ Switch State (traitCode: OnOff)
└─ Switch (endpointId: 3)
└─ Switch Function (functionCode: Output)
│ └─ Switch State (traitCode: OnOff)
In actual development, you will frequently encounter fields such as type and trait in interface parameters and responses. For device types and trait codes corresponding to these fields, refer to the following documentation:
Query Trait Values Of Matter Device By ID
- API intent: spec.query.specdevice.config
- Description: This API queries trait values of a matter device by its ID. A Matter device here refers to a device whose model prefix is
aqara.matter.
Request Parameter Description
| Name | Type | Required | Description |
|---|---|---|---|
| dids | Array<String> | Yes | The list of Matter device IDs to query. Maximum array length: 10. |
Request Example
{
"intent" : "spec.query.specdevice.config",
"data":{
"dids": ["matt.2990fb3413ed87c9b7370000", "matt.2990fb3413ed884726370000"]
}
}
Response Data Description
result.data is an array of objects. The table below details the data structure of each object in result.data, with all fields being subfields of result.data:
| Field | Type | Description |
|---|---|---|
| deviceId | String | Device ID. |
| types | Array<String> | List of supported device types. For the meanings of each string, see Supported Device Types. |
| endpoints | Array<Object> | List of endpoints. |
| endpoints[].endpointId | Number | Endpoint ID. |
| endpoints[].endpointTypes | Array<String> | List of endpoint types. |
| endpoints[].functions | Array<Object> | List of functions. |
| endpoints[].functions[].functionId | Number | Function ID. |
| endpoints[].functions[].functionCode | String | Function code. |
| endpoints[].functions[].traits | Array<Object> | List of traits. |
| endpoints[].functions[].traits[].traitId | Number | Trait ID. |
| endpoints[].functions[].traits[].traitCode | String | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
| endpoints[].functions[].traits[].attribute | Object | Trait attribute. |
| endpoints[].functions[].traits[].attribute.readable | Boolean | Whether readable. |
| endpoints[].functions[].traits[].attribute.writable | Boolean | Whether writable. |
| endpoints[].functions[].traits[].attribute.subscribable | Boolean | Whether subscribable. |
| endpoints[].functions[].traits[].attribute.type | String | Type of trait attribute (BOOLEAN, STRING, ENUM, NUMBER, OTHER, etc.). |
| endpoints[].functions[].traits[].attribute.format | String | Detailed type of trait attribute. |
| endpoints[].functions[].traits[].attribute.unit | String | Unit. This field is only meaningful when attribute.type is NUMBER. |
| endpoints[].functions[].traits[].attribute.defaultValue | String | Default value. |
| endpoints[].functions[].traits[].attribute.min/max/step | Numeric | Minimum/maximum/step value for number types. |
| endpoints[].functions[].traits[].attribute.enums | Array<Object> | List of enum values. Only available when attribute.type is ENUM or BOOLEAN. |
| endpoints[].functions[].traits[].attribute.enums.key | string | Enum key. |
| endpoints[].functions[].traits[].attribute.enums.value | string | Enum value. |
| endpoints[].functions[].traits[].value | Any | Current value of the trait. The type depends on the format. |
| endpoints[].functions[].traits[].time | Number | UTC timestamp (in milliseconds) of the latest value update. This field may be absent. |
| model | String | Device model name. |
Response Example
{
"code": 0,
"message": "Success",
"msgDetails": null,
"requestId": "",
"result": {
"data": [
{
"types": [
"ContactSensor"
],
"endpoints": [
{
"functions": [
{
"functionId": 128,
"traits": [
{
"traitId": 32901,
"attribute": {
"readable": true,
"format": "Bool",
"type": "BOOLEAN",
"subscribable": true,
"writable": false
},
"time": 1762399511357,
"value": "1",
"traitCode": "Reachable"
}
],
"functionCode": "BasicInformation"
},
{
...
}
],
"endpointId": 0,
"endpointTypes": [
"Root"
]
},
{
...
},
],
"model": "aqara.matter.4447_8194",
"deviceId": "matt.2990fb3413ed87c9b7370000"
}
]
}
}
Query Trait Values Of Non-Matter Devices By Models
- API intent: spec.query.qlinkmodel.config
- Description: This API queries the trait value by the model of a non-Matter device.
Request Parameter Description
| Name | Type | Required | Description |
|---|---|---|---|
| models | Array<String> | Yes | The list of model names to query. Maximum array length: 5. |
Request Example
{
"intent" : "spec.query.qlinkmodel.config",
"data":{
"models": ["lumi.motion.agl001","lumi.switch.aus002"]
}
}
Response Data Description
result.data is a Map<String, Object>, where the device model is used as the key, and the value is the configuration object for that device. The table below details the data structure of result.data, with all fields being subfields under result.data:
| Field | Type | Description |
|---|---|---|
| {model} | Object | {model} is a dynamic field name, i.e. the specific device model as the key. Different models have different configuration objects. |
| {model}.model | String | Device model name. |
| {model}.types | Array<String> | List of device types. See Supported Device Types for meanings. |
| {model}.endpoints | Array<Object> | Endpoint list. |
| {model}.endpoints[].endpointId | Number | Endpoint ID. |
| {model}.endpoints[].endpointTypes | Array<String> | Endpoint type list. |
| {model}.endpoints[].functions | Array<Object> | Function list. |
| {model}.endpoints[].functions[].functionId | Number | Function ID. |
| {model}.endpoints[].functions[].functionCode | String | Function code. |
| {model}.endpoints[].functions[].traits | Array<Object> | Trait list. |
| {model}.endpoints[].functions[].traits[].traitId | Number | Trait ID. |
| {model}.endpoints[].functions[].traits[].traitCode | String | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
| {model}.endpoints[].functions[].traits[].attribute | Object | Trait attribute. |
| {model}.endpoints[].functions[].traits[].attribute.readable | Boolean | Whether readable. |
| {model}.endpoints[].functions[].traits[].attribute.writable | Boolean | Whether writable. |
| {model}.endpoints[].functions[].traits[].attribute.subscribable | Boolean | Whether subscribable. |
| {model}.endpoints[].functions[].traits[].attribute.type | String | Type of trait attribute (BOOLEAN, STRING, ENUM, NUMBER, OTHER, etc.). |
| {model}.endpoints[].functions[].traits[].attribute.format | String | Detailed type of trait attribute. |
| {model}.endpoints[].functions[].traits[].attribute.unit | String | Unit. Only meaningful when attribute.type is NUMBER. |
| {model}.endpoints[].functions[].traits[].attribute.defaultValue | String | Default value. |
| {model}.endpoints[].functions[].traits[].attribute.min/max/step | Numeric | Minimum/maximum/step value for number types. |
| {model}.endpoints[].functions[].traits[].attribute.enums | Array<Object> | Enum value list. Only available when attribute.type is ENUM or BOOLEAN. |
| {model}.endpoints[].functions[].traits[].attribute.enums.key | string | Enum key. |
| {model}.endpoints[].functions[].traits[].attribute.enums.value | string | Enum value. |
Response Example
{
"code": 0,
"message": "Success",
"msgDetails": null,
"requestId": "",
"result": {
"data": {
"lumi.switch.aus002": {
"types": [
"Switch",
"Button",
"OccupancySensor"
],
"endpoints": [
{
"functions": [
{
"functionId": 128,
"traits": [
{
"traitId": 32901,
"attribute": {
"readable": true,
"enums": [
{
"value": "0",
"key": "Offline"
}
],
"format": "Bool",
"type": "BOOLEAN",
"subscribable": true,
"writable": false
},
"traitCode": "Reachable"
}
],
"functionCode": "BasicInformation"
},
{
...
}
],
"endpointId": 0,
"endpointTypes": [
"Root"
]
},
{
...
}
],
"model": "lumi.switch.aus002"
}
}
}
}
Get Device Trait Values
- API intent: spec.query.trait
- Description: This API supports querying the current values of multiple traits in batch. A maximum of 50 traits can be queried per request; if more than 50 traits are provided, only the latest values of the first 50 traits will be returned.
Request Parameter Description
| Name | Type | Required | Description |
|---|---|---|---|
| traits | Array<Object> | Yes | Array of trait objects to query, up to 50 supported. |
| traits.deviceId | String | Yes | Unique identifier of the device. |
| traits.endpointId | Number | Yes | Endpoint ID. |
| traits.functionCode | String | Yes | Function code. |
| traits.traitCode | String | Yes | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
Request Example
{
"intent": "spec.query.trait",
"data": {
"traits": [
{
"deviceId": "lumi1.54ef448a0b73",
"endpointId": 0,
"functionCode": "BasicInformation",
"traitCode": "Reachable"
},
{
"deviceId": "lumi1.54ef448a0b73",
"endpointId": 0,
"functionCode": "Descriptor",
"traitCode": "EndpointArrayDynamic"
},
{
...
}
]
}
}
Response Data Description
result.data is an array of Objects. The following table details the data structure of each object in result.data, with all fields being subfields of result.data:
| Field | Type | Description |
|---|---|---|
| functionCode | String | Function code, indicating the type of function to which the trait belongs, such as BasicInformation, etc. |
| endpointId | Number | Endpoint ID. |
| time | Number/Null | UTC timestamp (in milliseconds) when the trait value was last updated. If the value is null, you do not need to pay attention to the update time of this trait. |
| deviceId | String | Device ID. |
| value | String | Current value of the trait. The value type depends on the trait specified by traitCode. |
| traitCode | String | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
Response Example
{
"code": 0,
"message": "Success",
"msgDetails": null,
"requestId": "",
"result": {
"data": [
{
"functionCode": "BasicInformation",
"endpointId": 0,
"time": null,
"deviceId": "lumi1.54ef448a0b73",
"value": "1",
"traitCode": "Reachable"
},
{
"functionCode": "Descriptor",
"endpointId": 0,
"time": 1762417659743,
"deviceId": "lumi1.54ef448a0b73",
"value": "[0,1,2,3]",
"traitCode": "EndpointArrayDynamic"
},
{
...
}
]
}
}
Control Devices
- API intent: spec.write.trait
- Description: This API is used to batch control devices by specifying a list of traits. A maximum of 10 devices can be controlled in a single request, and any number of traits can be issued to each device simultaneously. If the device count exceeds 10, only the first 50 trait control requests will be processed, and the excess will be ignored.
Request Parameter Description
| Name | Type | Required | Description |
|---|---|---|---|
| traits | Array<Object> | Yes | Array of traits to write. Array length note:
|
| traits.deviceId | String | Yes | Unique device ID. |
| traits.endpointId | Number | Yes | Endpoint ID. |
| traits.functionCode | String | Yes | Function code. |
| traits.traitCode | String | Yes | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
| traits.value | Any | Yes | Target value for the trait. |
Request Example
{
"intent": "spec.write.trait",
"data": {
"traits": [
{
"deviceId": "lumi1.54ef448a0b73",
"endpointId": 3,
"functionCode": "Output",
"traitCode": "OnOff",
"value": "0"
}
]
}
}
Response Data Description
| Field | Type | Description |
|---|---|---|
| functionCode | String | Function code, corresponding to the controlled function, e.g., "Output". |
| endpointId | Number | Endpoint ID. It identifies which endpoint the function resides on. |
| deviceId | String | Device ID, the unique identifier of the controlled device. |
| value | Any | The updated trait value. Its type depends on the trait. |
| traitCode | String | Trait code, corresponding to the specific function supported by the device. See Supported Traits for details about each trait, including its meaning, type (such as numeric, boolean, enum, etc.), and whether it is readable, writable, or reportable. |
| code | Number | Return code. 0 indicates a successful API call, while non-zero indicates a failed API call (this only reflects the API request itself, not whether the device was actually controlled). |
Response Example
result.data is an array of objects. The table below details the data structure of each object in result.data, with all fields being subfields of result.data:
{
"code": 0,
"message": "Success",
"msgDetails": null,
"requestId": "",
"result": {
"data": [
{
"functionCode": "Output",
"endpointId": 3,
"deviceId": "lumi1.54ef448a0b73",
"value": "0",
"traitCode": "OnOff",
// 0 indicates a successful API call, while non-zero indicates a failed API call (this only reflects the API request itself, not whether the device was actually controlled)
"code": 0
}
]
}
}
Subscribe and Unsubscribe to Trait Value Push
To subscribe or unsubscribe to device trait value updates, please refer to the relevant sections in the Message Push Interface (Trait) documentation: