Aqara Smart Home AI Agent Skill
Basics
- - Host (default):
agent.aqara.com — override with AQARA_OPEN_HOST. Skill root: skills/aqara-agent/. Wrapper: scripts/aqara_open_api.py (AqaraOpenAPI → Open Platform REST, including energy).
aqara_open_api.py CLI
- - Invocation:
python3 scripts/aqara_open_api.py <method_name> [json_body]. - Must: first argument equals the exact public method name on
AqaraOpenAPI (see bash examples in references/*.md). Forbidden: aliases or shortened names unless a reference documents an equivalent. - Dispatch:
get_* → no JSON body; post_* → JSON object (optional, default {}). - Energy:
post_energy_consumption_statistic — route from device_ids only (non-empty → device API; else position). Fields and NL mapping: references/energy-statistic.md. - Optional env:
AQARA_OPEN_HTTP_TIMEOUT (default 60), AQARA_OPEN_API_URL.
Skill Package Layout
Relative to skills/aqara-agent/. Normative: this file + references/*.md. README.md is a human index only.
| Path | Purpose |
|---|
| INLINECODE20 | This document. |
| INLINECODE21 |
Human index;
Forbidden treat as overriding
SKILL.md. |
|
assets/login_reply_prompt.json | Locales,
official_open_login_url,
login_url_policy. |
|
assets/user_account.example.json | Template shape. |
|
assets/user_account.json | Live session (sensitive). |
|
references/*.md | Per-domain procedures (account, home-space, devices, scenes, automations, energy). |
|
scripts/aqara_open_api.py | CLI + HTTP client. |
|
scripts/save_user_account.py | Writes
aqara_api_key. |
|
scripts/runtime_utils.py | Shared helpers. |
|
scripts/requirements.txt | Dependencies. |
Core Workflow
deps → sign-in → pick home → intent → references/*.md → summarize
Ground Truth (Binding)
Forbidden stating or implying as factual: homes, rooms, devices, capabilities, attributes, counts, logs, or control outcomes, except from executed skill scripts + real API responses or skill-accepted user input (e.g. pasted aqara_api_key). If that flow has not succeeded, Forbidden any factual claim about those entities.
Forbidden demo-style lists, guessed layouts, synthetic values, fake success after errors/timeouts/missing auth, or prose/JSON mimicking API output without a real response.
Must state missing data and cause (e.g. not signed in, API error), then auth/retry/references/. Forbidden imagined padding.
Execute in order:
1. Environment
CODEBLOCK0
CODEBLOCK1
2. Auth
- - Must confirm
user_account.json readable/writable before features; host/project rules may require reading it first. - Must follow
references/aqara-account-manage.md (switch-home vs re-login, token save, Step 1 login copy). - Must read
assets/login_reply_prompt.json on every login guidance turn. Must set the user-facing login link to the exact official_open_login_url string (login_url_policy). Forbidden invent Open Platform / sns-auth / client_id / redirect_uri URLs from memory. - Locale from JSON for the user’s language; unknown →
en (fallback_locale / default_locale). Must deliver the single-line login URL per references/aqara-account-manage.md.
INLINECODE49 :
CODEBLOCK2
3. Home Management
- - Must after saving
aqara_api_key run references/home-space-manage.md step 0 immediately (fetch homes; one home → write; many → user picks). Forbidden reply only “send home name” without running fetch. - Must run
save_user_account.py and aqara_open_api.py get_homes as two separate invocations. Forbidden && on one shell line (aqara-account-manage.md step 2, home-space-manage.md step 0). - Switch home: Must re-fetch homes and let the user choose (
home-space-manage.md). Forbidden default to re-login. Must use aqara-account-manage.md login only if the user demands re-login/token rotation or the API signals expired/unauthorized.
4. Intent
Categories: space, device query, control, scene, automation, energy. Multiple intents: Must query before control, in utterance order.
| Intent | INLINECODE59 methods (details in reference) | Reference |
|---|
| Space | INLINECODE60 , INLINECODE61 | INLINECODE62 |
| Device query |
get_home_devices,
post_device_status; optional
post_device_base_info,
post_device_log |
references/devices-inquiry.md |
| Device control |
post_device_control |
references/devices-control.md |
| Scene |
get_home_scenes,
post_execute_scene,
post_scene_detail_query,
post_scene_execution_log |
references/scene-manage.md |
| Automation |
get_home_automations,
post_automation_detail_query,
post_automation_switch,
post_automation_execution_log |
references/automation-manage.md |
| Energy |
post_energy_consumption_statistic |
references/energy-statistic.md |
5. Route and Summarize
Must open the matching references/ doc, run scripts, summarize from actual output only. Forbidden fabricate success or any home/room/device/state not in script/API output (Ground truth).
Illustrative CLI JSON (Agents Only)
Forbidden paste these raw blocks to end users.
REST shape (skeleton):
CODEBLOCK3
Bad params / parse error (skeleton):
CODEBLOCK4
Error Handling
| Situation | Action |
|---|
| Device not found | Must state no match; allowed: short candidate list. |
| Capability unsupported |
Must state unsupported;
Forbidden imply success. |
| Home/room not found |
Must state no hit;
Must direct next step via
references/ (re-fetch or verify home). |
| Multiple device matches |
Must list matches;
Must one disambiguation question (room or full name). |
| Not signed in / empty
aqara_api_key |
Must login + save per
aqara-account-manage.md, then homes.
MissingAqaraApiKeyError → same. |
| No home selected |
Must home-space-manage.md. No
home_id →
homes/query; one home → auto-write; many →
home_selection_required. |
| Bad token / auth |
Must re-login / refresh (no secret leak).
Forbidden treat
home switch as auth failure unless home-list returns auth error.
unauthorized or insufficient permissions (or equivalent) →
Must re-login per
aqara-account-manage.md;
Forbidden fake success. |
| Control path blocked |
Must say device found, command not sent. |
| Other |
Must short summary + retry/
references/;
Forbidden internal URLs or full headers. |
| Indeterminate |
Must use
references/ + script output; confirmed bug →
Must file skill issue. |
| Empty API data |
Forbidden invent entities/readings;
Must re-run or report failure (
Ground truth). |
| HTTP / network |
Forbidden treat as success;
Must retry or brief explanation;
Forbidden raw stacks. |
Notes
- 1. Forbidden raw IDs in user text (device, position,
home_id, …). Exception: automation_id allowed if server desensitized virtual ID. - After layout changes, if match fails: Must re-fetch space + devices (
home-space-manage.md, devices-inquiry.md), retry. - User replies: Must conclusion first, then detail; Must ≤ one clarification question.
- Session gate: unsigned → Must end on setup; Forbidden imply control ran.
- Must run
scripts/*.py automatically when required (stricter host policy wins). - Account/home change: Must update
user_account.json and re-run aqara-account-manage.md. - Forbidden echo tokens/headers; Must treat
user_account.json and caches as sensitive. - Multiple fuzzy name hits: Must user confirm.
- User-visible: Forbidden shell, paths, raw stdout, debug JSON,
references/ filenames; Must plain summary. - Control OK: Must brief close; Forbidden preemptive hedging; fix only after user reports failure.
Out of Scope
Unsupported (no create/edit in this wrapper):
- - Cameras — live / playback.
- Locks — unlock / lock-unlock.
- Scene authoring — only ops in
references/scene-manage.md. - Automation authoring — only ops in
references/automation-manage.md. - Shortcuts (e.g. Siri lists) — Must point to Aqara Home app.
- Weather — outside this API.
- Entertainment — beyond
references/devices-control.md.
When user asks for unsupported: Must say unsupported (or not yet); Must direct to Aqara Home app if the app covers it.
Aqara 智能家居 AI 智能体技能
基础信息
- - 主机(默认): agent.aqara.com — 可通过 AQARAOPENHOST 覆盖。技能根目录: skills/aqara-agent/。封装器: scripts/aqaraopenapi.py(AqaraOpenAPI → 开放平台 REST,包含能源功能)。
aqaraopenapi.py 命令行界面
- - 调用方式: python3 scripts/aqaraopenapi.py <方法名> [jsonbody]。
- 必须: 第一个参数需与 AqaraOpenAPI 上的确切公开方法名一致(参见 references/.md 中的 bash 示例)。禁止: 使用别名或缩写名称,除非参考文档中有等效说明。
- 分发规则: get → 无 JSON 请求体;post* → JSON 对象(可选,默认为 {})。
- 能源功能: postenergyconsumptionstatistic — 路由仅从 deviceids 出发(非空 → 设备 API;否则为位置)。字段和自然语言映射:references/energy-statistic.md。
- 可选环境变量: AQARAOPENHTTPTIMEOUT(默认 60)、AQARAOPENAPI_URL。
技能包结构
相对于 skills/aqara-agent/。规范性文件: 本文件 + references/*.md。README.md 仅为人工索引。
| 路径 | 用途 |
|---|
| SKILL.md | 本文档。 |
| README.md |
人工索引;
禁止将其视为覆盖 SKILL.md。 |
| assets/login
replyprompt.json | 语言区域、official
openlogin
url、loginurl_policy。 |
| assets/user_account.example.json | 模板格式。 |
| assets/user_account.json | 实时会话(敏感信息)。 |
| references/*.md | 各领域流程(账户、家庭空间、设备、场景、自动化、能源)。 |
| scripts/aqara
openapi.py | 命令行界面 + HTTP 客户端。 |
| scripts/save
useraccount.py | 写入 aqara
apikey。 |
| scripts/runtime_utils.py | 共享辅助工具。 |
| scripts/requirements.txt | 依赖项。 |
核心工作流程
依赖安装 → 登录 → 选择家庭 → 意图识别 → references/*.md → 结果汇总
事实依据(绑定规则)
禁止陈述或暗示以下内容为事实:家庭、房间、设备、能力、属性、数量、日志或控制结果,除非来自已执行的技能脚本 + 真实的 API 响应或技能接受的用户输入(例如粘贴的 aqaraapikey)。如果该流程尚未成功,禁止对这些实体做出任何事实性声明。
禁止使用演示风格的列表、猜测的布局、合成值、错误/超时/缺少认证后的虚假成功、或没有真实响应的模仿 API 输出的散文/JSON。
必须说明缺失的数据及其原因(例如未登录、API 错误),然后进行认证/重试/参考 references/。禁止凭空填充。
按顺序执行:
1. 环境准备
bash
export AQARAOPENHOST=agent.aqara.com # 测试环境;根据需要省略或设置生产环境主机
bash
cd skills/aqara-agent
pip install -r scripts/requirements.txt
2. 认证
- - 必须在功能使用前确认 useraccount.json 可读/可写;主机/项目规则可能要求先读取该文件。
- 必须遵循 references/aqara-account-manage.md(切换家庭 vs 重新登录、令牌保存、步骤 1 登录复制)。
- 必须在每次登录引导轮次中读取 assets/loginreplyprompt.json。必须将面向用户的登录链接设置为确切的 officialopenloginurl 字符串(loginurlpolicy)。禁止凭记忆编造开放平台 / sns-auth / clientid / redirecturi URL。
- 根据 JSON 中的语言区域设置用户语言;未知语言 → en(fallbacklocale / defaultlocale)。必须按照 references/aqara-account-manage.md 提供单行登录 URL。
user_account.json:
json
{
aqaraapikey: ,
updated_at: ,
home_id: ,
home_name:
}
3. 家庭管理
- - 必须在保存 aqaraapikey 后立即执行 references/home-space-manage.md 的步骤 0(获取家庭列表;一个家庭 → 写入;多个家庭 → 用户选择)。禁止仅回复“请发送家庭名称”而不执行获取操作。
- 必须将 saveuseraccount.py 和 aqaraopenapi.py get_homes 作为两次独立的调用执行。禁止在同一 shell 行中使用 &&(aqara-account-manage.md 步骤 2、home-space-manage.md 步骤 0)。
- 切换家庭: 必须重新获取家庭列表并让用户选择(home-space-manage.md)。禁止默认重新登录。必须仅在用户要求重新登录/令牌轮换或 API 提示令牌过期/未授权时,才使用 aqara-account-manage.md 的登录流程。
4. 意图识别
类别:空间、设备查询、控制、场景、自动化、能源。多意图: 必须先查询后控制,按用户话语顺序执行。
| 意图 | AqaraOpenAPI 方法(详情见参考文档) | 参考文档 |
|---|
| 空间 | gethomes、getrooms | references/home-space-manage.md |
| 设备查询 |
get
homedevices、post
devicestatus;可选 post
devicebase
info、postdevice_log | references/devices-inquiry.md |
| 设备控制 | post
devicecontrol | references/devices-control.md |
| 场景 | get
homescenes、post
executescene、post
scenedetail
query、postscene
executionlog | references/scene-manage.md |
| 自动化 | get
homeautomations、post
automationdetail
query、postautomation
switch、postautomation
executionlog | references/automation-manage.md |
| 能源 | post
energyconsumption_statistic | references/energy-statistic.md |
5. 路由与结果汇总
必须打开对应的 references/ 文档,执行脚本,仅根据实际输出进行汇总。禁止捏造成功结果或任何不在脚本/API 输出中的家庭/房间/设备/状态(事实依据)。
示例 CLI JSON(仅限智能体使用)
禁止将以下原始代码块粘贴给最终用户。
REST 格式(骨架):
json
{
code: 0,
message: ,
data: {}
}
参数错误/解析错误(骨架):
json
{
ok: false,
error: ...
}
错误处理
| 情况 | 操作 |
|---|
| 设备未找到 | 必须说明无匹配项;允许: 提供简短候选列表。 |
| 能力不支持 |
必须说明不支持;
禁止暗示成功。 |
| 家庭/房间未找到 |
必须说明无匹配项;
必须通过 references/ 指导下一步操作(重新获取或确认家庭)。 |
| 多个设备匹配 |
必须列出匹配项;
必须提出一次澄清问题(房间或全名)。 |
| 未登录 / aqara
apikey 为空 |
必须按照 aqara-account-manage.md 进行登录并保存,然后获取家庭列表。MissingAqaraApiKeyError → 同样处理。 |
| 未选择家庭 |
必须执行 home-space-manage.md。无 home
id → homes/query;一个家庭 → 自动写入;多个家庭 → homeselection_required。 |
| 令牌错误/认证失败 |
必须重新登录/刷新(不泄露密钥)。
禁止将
切换家庭视为认证失败,除非家庭列表返回认证错误。unauthorized or insufficient permissions(或等效信息)→
必须按照 aqara-account-manage.md 重新登录;
禁止伪造成功。