Skills aqara-open-api
Query and control Aqara/Lumi Studio smart home devices and manage spaces via the Aqara Open Platform API (HTTP JSON). Use when the user asks to list Aqara devices, get device status, control lights/switches/sensors, or manage rooms/spaces. Requires AQARA_OPEN_API_TOKEN and AQARA_ENDPOINT_URL.
git clone https://github.com/openclaw/skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/aiot-f2e-team/aqara-open-api" ~/.claude/skills/openclaw-skills-aqara-open-api && rm -rf "$T"
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/skills/aiot-f2e-team/aqara-open-api" ~/.openclaw/skills/openclaw-skills-aqara-open-api && rm -rf "$T"
skills/aiot-f2e-team/aqara-open-api/SKILL.mdAqara Open API Skill
This skill equips the agent to operate Aqara/Lumi Studio smart home devices via HTTPS requests to the Aqara Open Platform API. All operations are performed exclusively through
commands, except curl
GetAllDevicesWithSpaceRequest, which must be executed through bash scripts/fetch_all_devices.sh to refresh the local cache file data/devices.json.
This skill supports only:
- device discovery and device type lookup
- device state queries from cache
- device control
- space listing, creation, update, and device assignment
Configuration
The following environment variables are required:
: The base URLAQARA_ENDPOINT_URL
: Your Long-Lived Access Token.AQARA_OPEN_API_TOKEN
AI Quick Navigation (Read This First)
This section is a navigation and execution summary only. It does not add new rules or change existing constraints.
What This Skill Can Do
- Device discovery: load all devices, space mappings, endpoints, functions, traits, and current values
- Device type catalog: query all device types in the project with code and display name
- Device queries: filter by type, name, room/space, or online status; read current trait values
- Device control: send control requests using real
,deviceId
,endpointId
, andfunctionCode
from cachetraitCode - Space management: list spaces, create spaces, update spaces, and assign devices to spaces
Intent to Fastest Path
- List all devices / devices by type / devices in a room / device state
- Check
data/devices.json - If cache exists: read the file
- If cache is missing: run
bash scripts/fetch_all_devices.sh
- Check
- Control a device
- Ensure
existsdata/devices.json - Read
from cachedeviceId + endpointId + functionCode + traitCode - Then use bash +
forcurlExecuteTraitRequest
- Ensure
- What device types are there?
- Use bash +
forcurlGetDeviceTypeInfosRequest
- Use bash +
- Refresh all device data
- Only run
bash scripts/fetch_all_devices.sh
- Only run
- List spaces
- Use bash +
forcurlGetSpacesRequest
- Use bash +
- Create or update a space
- First get the real
fromspaceIdGetSpacesRequest - Then call
orCreateSpaceRequestUpdateSpaceRequest
- First get the real
- Assign devices to a space
- First get the real
fromspaceIdGetSpacesRequest - Read real
values fromdeviceIddata/devices.json - Then call
AssociateDevicesToSpaceRequest
- First get the real
Six Highest-Priority Rules
- All-device loading only goes through the script:
may only be executed viaGetAllDevicesWithSpaceRequest
.bash scripts/fetch_all_devices.sh - All other requests only go through curl: except for the refresh script above, every other API call must use bash +
.curl - Request bodies may only contain four fields:
,type
,version
, andmsgId
;data
must always beversion
."v1"
is whitelist-only: use only the exact request types listed in this document; never test guessed alternatives such astype
,GetAllSpacesRequest
, orGetSpaceListRequest
.QuerySpaceListRequest- All IDs and codes must come from real API data: never guess
,deviceId
,endpointId
,functionCode
, ortraitCode
.spaceId
Required Preconditions
- Before listing devices, reading state, or filtering by room/type: check whether
existsdata/devices.json - Before controlling a device: obtain the real
,deviceId
,endpointId
, andfunctionCode
from the cache filetraitCode - Before creating or updating a space: if
is needed, callspaceId
firstGetSpacesRequest - Before assigning devices to a space: get
fromspaceId
andGetSpacesRequest
values fromdeviceIddata/devices.json
Terms and Field Reference
- Cache file:
, which stores thedata/devices.json
array fromdataGetAllDevicesWithSpaceRequest - deviceId: device identifier used for control and space assignment
- endpointId: endpoint identifier, only from cached
endpoints[].endpointId - functionCode / traitCode: capability identifiers from cache
- spaceId: space identifier from
or cachedGetSpacesRequestspace.spaceId
Section Index
- Protocol and four-field request body: see
## API Protocol - Script vs curl execution rules: see
### Execution Model - Cache file rules: see
### File Cache Model (Cache-First Data Model) - Device APIs: see
under## API Commands### Device Management - Space APIs: see
### Space Management - Standard workflows: see
## Standard Operating Procedures (SOP) - Decision trees: see
and## Cache Decision Tree## API Call Decision Tree - Forbidden behavior: see
## Forbidden Behavior - Trait code reference: see
references/trait-codes.md
1. Role and Core Philosophy
Role: You are a strict hardware interface controller. Never infer or guess IDs or capability fields.
2. Hard Safety Rules
2.1 Valid Value Rule
Any operation involving live device state, such as power, brightness, or temperature, must follow this rule:
| Power status | Valid interpretation | Response style |
|---|---|---|
| Brightness / color temperature / power should be treated as 0 or "off" | "The device is currently off" |
| Use the actual returned value | "Brightness is X%" |
Never produce logically inconsistent output such as "the light is off but brightness is 100%".
Quick Start (Operator)
- Set environment variables:
: your Aqara Open API Bearer token (JWT)AQARA_OPEN_API_TOKEN
: the API base URLAQARA_ENDPOINT_URL
Real environment value rule:
AQARA_ENDPOINT_URL and AQARA_OPEN_API_TOKEN must be read from the runtime environment (via $AQARA_ENDPOINT_URL and $AQARA_OPEN_API_TOKEN). Do not guess, fabricate, or use example placeholders as real request values. If either variable is missing or empty, tell the user to configure it first.
- Test connectivity:
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"GetAllDevicesWithSpaceRequest","version":"v1","msgId":"test-1"}'
API Protocol
Base URL:
$AQARA_ENDPOINT_URL
All requests use a single unified POST endpoint. Routing is determined by the
type field in the JSON body.
Request Envelope
The request-body JSON may contain exactly these 4 fields. Do not add, remove, or replace fields:
{ "type": "<RequestType>", "version": "v1", "msgId": "<unique-id>", "data": { ... } }
| Field | Required | Meaning | Forbidden behavior |
|---|---|---|---|
| Yes | API method name, such as or | Do not modify, abbreviate, or replace it with a value not listed in this document |
| Yes | Must be the string | Do not omit it; do not use , , or any other value |
| Yes | Unique request identifier, such as | None |
| Yes | Payload for the selected (, object, array, or string depending on the request) | Only use structures defined in this document or |
Strict request-body constraints
- Do not omit
: every curl request body must includeversion
."version":"v1" - Do not add undefined fields: the request body may contain only these 4 keys. Do not add
,senderId
,source
, or any field not defined in this document.timestamp - Do not invent field names or structures: neither the top-level body nor
may contain made-up fields or undocumented shapes.data - Do not invent or trial-run alternate
values: if this document says the request type istype
, thenGetSpacesRequest
must be exactlytype
.GetSpacesRequest - Do not use synonym or variant guessing for
: names such astype
,GetAllSpacesRequest
,GetSpaceListRequest
,QuerySpaceListRequest
, or other self-created variants are forbidden unless they are explicitly documented in this file.ListSpacesRequest
Required Headers
Authorization: Bearer $AQARA_OPEN_API_TOKEN Content-Type: application/json
Response Envelope
{ "type": "<ResponseType>", "version": "v1", "msgId": "<matching-id>", "code": 0, "message": null, "data": { ... } }
code: 0 = success. Non-zero = error. Common error codes:
- 400: invalid parameters
- 1001: token expired
- 2030: device not found
curl Template
The
-d value for every curl request must be a JSON object with only 4 keys: type, version, msgId, and data. Replace <TYPE> with the API method name and <DATA> with the correct payload:
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"<TYPE>","version":"v1","msgId":"msg-'$(date +%s)'","data":<DATA>}'
Always keep
"version":"v1" in -d, and never add senderId or any other field not defined in this document.
How the Agent Should Use This Skill
Execution Model
Execution rules (must follow):
- Only
: execute it viaGetAllDevicesWithSpaceRequest
. The script calls the API and writes the responsebash scripts/fetch_all_devices.sh
todata
. Do not call this request directly with curl.data/devices.json - All other supported API requests (such as
,ExecuteTraitRequest
,GetSpacesRequest
,CreateSpaceRequest
, andUpdateSpaceRequest
): execute them with bash +AssociateDevicesToSpaceRequest
. The JSON body must contain exactly 4 keys:curl
,type
,version
, andmsgId
.data - No exploratory
retries: when a request fails, do not try nearby or similar type names. Verify the documentedtype
, payload shape, token, IDs, cache, and required preconditions, then retry the same documented request only if appropriate.type
File Cache Model (Cache-First Data Model)
Local cache file
— thedata/devices.json
array fromdata
, including complete device information:GetAllDevicesWithSpaceRequest
,deviceId
,name
,deviceTypesList
,state
,space
, and allendpointsfunctions/traits/current values
Refresh cache (create/overwrite cache file)
bash scripts/fetch_all_devices.sh
Usage rules (must follow)
- Read cache first: when the user asks for device lists, device types, room mappings, or basic device information, check whether
exists and is non-empty.data/devices.json - Cache hit: if the cache file exists, read the file directly and continue. Do not call
again.GetAllDevicesWithSpaceRequest - Cache miss / missing file / parse failure: run
to refresh the cache. After refresh, re-read the cache file before continuing.bash scripts/fetch_all_devices.sh - Explicit refresh requested by the user: run
and then re-read the file.bash scripts/fetch_all_devices.sh - Control commands (
) still go directly to the API via curl, but allExecuteTraitRequest
/deviceId
/endpointId
/functionCode
values must come from the cache file.traitCode
Critical Data-Only Rule
NEVER guess, fabricate, or infer
deviceId, endpointId, functionCode, or traitCode. Every value used in control calls MUST come from the cached data/devices.json file.
must be taken from the device'sendpointId
.endpoints[].endpointId
andfunctionCode
must be taken fromtraitCode
.endpoints[].functions[].traits[]
type must match the trait definition.value
Local Filtering (No Extra API Calls)
When the user asks for a subset of devices (for example, all lights, devices in the bedroom, or online switches):
- Filter the cached
locally bydata/devices.json
,deviceTypesList
,name
, orstate
/space.name
.space.spatialMarking - Do not make a new API call to filter.
Device Type vs Device Name
- By Type (preferred): when the user asks for lights or switches, filter cached file by
.deviceTypesList - By Name (secondary): use device name only to select a specific device from the cached list.
Error Handling
- On errors with code 1001 (token expired) or 400 (bad params): re-check token, verify all IDs come from cached device data.
- On 2030: device not found; run
to refresh cache and retry.bash scripts/fetch_all_devices.sh - Timeout/network errors: retry once, then report.
- Cache file parse error: delete
and rundata/devices.json
to regenerate.bash scripts/fetch_all_devices.sh
API Commands (7 total)
Device Management
Get all devices with space info — GetAllDevicesWithSpaceRequest
GetAllDevicesWithSpaceRequestRetrieve all smart home devices in a single call, including full device info, space assignment, endpoints, functions, traits, and current values. No
data field is needed (or data: null).
The agent MUST write this response to the local cache file (
data/devices.json) and use the cache for all subsequent device queries, status checks, and as the basis for control commands. Use the provided script to fetch and cache:
bash scripts/fetch_all_devices.sh
Manual curl (for reference only — prefer the script):
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"GetAllDevicesWithSpaceRequest","version":"v1","msgId":"msg-'$(date +%s)'"}'
Get all device types — GetDeviceTypeInfosRequest
GetDeviceTypeInfosRequestRetrieve every device type available in the current project. Each entry contains a
deviceType code and its localized display name.
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"GetDeviceTypeInfosRequest","version":"v1","msgId":"msg-'$(date +%s)'"}'
Control device — ExecuteTraitRequest
ExecuteTraitRequestControl one or more device functions, such as turning on/off or adjusting level.
endpointId, functionCode, and traitCode must be read from the cache.
# Turn on curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"ExecuteTraitRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":[{"deviceId":"<deviceId>","endpointId":<endpointId>,"functionCode":"<functionCode>","traitCode":"OnOff","value":true}]}' # Turn off curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"ExecuteTraitRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":[{"deviceId":"<deviceId>","endpointId":<endpointId>,"functionCode":"<functionCode>","traitCode":"OnOff","value":false}]}'
Space Management
List space hierarchy — GetSpacesRequest
GetSpacesRequestRetrieve all spaces as a hierarchical tree. Each space includes its ID, name, parent space ID, spatial marking label, and nested children.
Space request type hard rule: the request
type for space listing is only GetSpacesRequest. Do not try GetAllSpacesRequest, GetSpaceListRequest, QuerySpaceListRequest, or any other guessed variant.
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"GetSpacesRequest","version":"v1","msgId":"msg-'$(date +%s)'"}'
Create a new space — CreateSpaceRequest
CreateSpaceRequestCreate a room, zone, or building. Omit
parentSpaceId to create a top-level space. Run GetSpacesRequest first if the parent space ID is not known.
# Top-level space curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"CreateSpaceRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":{"name":"Living Room","spatialMarking":"living_room"}}' # Sub-space curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"CreateSpaceRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":{"name":"Bedroom","parentSpaceId":"<parentSpaceId>","spatialMarking":"bedroom"}}'
Update space properties — UpdateSpaceRequest
UpdateSpaceRequestUpdate the name or spatial marking of an existing space. Only provided fields are updated.
spaceId is required.
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"UpdateSpaceRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":{"spaceId":"<spaceId>","name":"New Room Name"}}'
Assign devices to a space — AssociateDevicesToSpaceRequest
AssociateDevicesToSpaceRequestAssign one or more devices to an existing space. Response
data only contains failed items; empty means all succeeded.
curl -s -X POST "$AQARA_ENDPOINT_URL" \ -H "Authorization: Bearer $AQARA_OPEN_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"type":"AssociateDevicesToSpaceRequest","version":"v1","msgId":"msg-'$(date +%s)'","data":{"spaceId":"<spaceId>","deviceIds":["<deviceId1>","<deviceId2>"]}}'
Standard Operating Procedures (SOP)
SOP A: List or discover devices
- Check whether
exists and is non-empty.data/devices.json - If it exists: read device data directly from the file.
- If it is missing or empty: run
to generate the cache, then read the file.bash scripts/fetch_all_devices.sh - Answer the user's request by filtering the cache file.
SOP B: Query device state
- Device state and trait values are already included in the cache file.
- If
is missing, rundata/devices.json
first.bash scripts/fetch_all_devices.sh - Find the device in the cache file and read the corresponding trait
.value - No separate API call is needed to read device state.
SOP C: Control device
- If
is missing, rundata/devices.json
first.bash scripts/fetch_all_devices.sh - Read the exact
,deviceId
,endpointId
, andfunctionCode
from the cache file.traitCode - Use the
curl command with only cached values.ExecuteTraitRequest - Response
only contains failed items; an empty array means all commands succeeded.data
SOP D: Space management
- Device-to-space associations are already included in
.data/devices.json - Use the
curl command to retrieve the full space hierarchy tree.GetSpacesRequest - Use
,CreateSpaceRequest
, orUpdateSpaceRequest
as needed.AssociateDevicesToSpaceRequest
Cache Decision Tree
Does the user request involve devices, spaces, or types? ├── Yes → Check the local cache file `data/devices.json` │ ├── Cache hit (file exists and is non-empty) │ │ └── Read from the file directly and filter/aggregate locally │ └── Cache miss / missing file │ ├── Run `bash scripts/fetch_all_devices.sh` │ ├── Re-read the cache file │ └── Continue with the refreshed data └── No → Continue with the normal flow Does the task require device control? ├── Yes → Ensure `data/devices.json` exists (refresh first if missing) │ ├── Read `deviceId + endpointId + functionCode + traitCode` from cache │ └── Call `ExecuteTraitRequest` via curl └── No → Return the cached data result Did the user explicitly ask to refresh device data? └── Run `bash scripts/fetch_all_devices.sh` to overwrite the cache, then re-read it
API Call Decision Tree
User wants devices by type? → data/devices.json exists? → Yes: filter file by deviceTypesList → No: bash scripts/fetch_all_devices.sh, then filter User wants to list/discover all devices? → data/devices.json exists? → Yes: return full list from file → No: bash scripts/fetch_all_devices.sh, then read User wants state of a device? → data/devices.json exists? → No: bash scripts/fetch_all_devices.sh → Read value from file: endpoints[].functions[].traits[].value User wants to control a device? → data/devices.json exists? → No: bash scripts/fetch_all_devices.sh → Get deviceId + endpointId + functionCode + traitCode from file → curl ExecuteTraitRequest with correct value type User wants devices by space/room? → data/devices.json exists? → Yes: filter file by space.name / spatialMarking → No: bash scripts/fetch_all_devices.sh, then filter User wants to refresh device data? → bash scripts/fetch_all_devices.sh User wants to see spaces? → curl GetSpacesRequest User wants to create, update, or assign spaces? → curl GetSpacesRequest if a real spaceId is needed → then curl CreateSpaceRequest / UpdateSpaceRequest / AssociateDevicesToSpaceRequest
Forbidden Behavior
| Forbidden | Correct behavior |
|---|---|
Guessing or fabricating | Always use IDs from cache file. |
Guessing or creating | Always take from in cache file. |
Guessing or | Always take from in cache file. |
Running without first resolving device/endpoint info | Ensure exists and use the cached structure. |
Using curl to call | Only this request goes through the script: use . |
| Calling the script or API for devices when cache file already exists and user did not ask to refresh | Read instead. |
| Making a separate API call to read device status/values | Device status and trait values are already in . |
| Inferring device type from device name | Filter cached devices by . |
Guessing | Always use IDs from response or cached device . |
Guessing or testing undocumented request values | Use only the exact request names listed in . |
| Trying alternate request names after a failure | Keep the documented unchanged; inspect payload, token, IDs, cache, and preconditions. |
Trying guessed space-list request names such as , , or | Use only to list spaces. |
Guessing or fabricating or | These must be read from the runtime environment. |
Files
— cache refresh script; callsscripts/fetch_all_devices.sh
and writesGetAllDevicesWithSpaceRequestdata/devices.json
— cache file generated by the script; contains complete device datadata/devices.json
— example curl invocationsreferences/examples.md
— full list of trait codes with type, unit, read/write, subscribe flagsreferences/trait-codes.md
Keep this
SKILL.md lean; consult references for details.