Aqara Smart Home AI Agent Skill
Basics
- - Website: https://www.aqara.com/cn/
- Skill root:
skills/aqara-home-skills/ (in-repo skill) - Python wrapper for the Aqara Open API:
scripts/aqara_open_api.py — calls the API surface directly.
Core workflow
High-level order: deps → sign-in → pick home → intent → follow references/*.md and summarize.
Ground truth: no fabricated smart-home data
Large models may hallucinate plausible homes, rooms, devices, states, or counts. For this skill, that is explicitly forbidden:
- - Sources of truth only: Homes, rooms, device names/IDs (for internal use), capabilities, live attributes (temperature, brightness, switch state, online/offline, etc.), lists, counts, logs, and control outcomes must come only from executed skill scripts and real Aqara API responses—or from user-supplied input the skill is designed to accept (e.g. pasted
aqara_api_key). If the corresponding inquiry or control flow has not been run successfully, do not present any of that information as factual. - Never invent or “plausible-fill”: Example or demo-style device/home lists; guessed room layouts; assumed device counts; synthetic attribute values; fabricated success after errors, timeouts, skipped steps, or missing auth; JSON or prose that mimics API output without a real response.
- When data is missing: State clearly that it could not be retrieved (and why, e.g. not signed in, API error), then follow auth/retry/
references/—never substitute imagined content to make the answer feel complete.
Align with usage and core workflow above; implement in order:
- 1. Environment
- - Install dependencies before use:
CODEBLOCK0
- 2. Auth — Before any feature, verify Aqara account auth and ensure
user_account.json is readable/writable.
- - Follow
references/aqara-account-manage.md. - Login UI strings (heading, instruction paragraph, link label, token-saved line) live in
assets/login_prompt_i18n.json; pick the locale to match the user’s language as described there—do not hardcode one language in replies. Fallback: use English (en) when language is unknown or unsupported (fallback_locale / default_locale in that file).
INLINECODE11 shape:
CODEBLOCK1
- 3. Home management
- - After
aqara_api_key is saved, automatically follow references/home-space-manage.md to fetch the home list and finalize selection: run that doc’s step 0 immediately; if there is a single home, write it; if multiple, ask the user to pick by index/name. Do not end with only “please reply with a home name” without running the fetch. - When the agent/terminal runs scripts:
save_user_account.py (write token) and aqara_open_api.py homes (fetch homes) must be two separate runs — do not chain with && in one shell line; see references/aqara-account-manage.md step 2 and references/home-space-manage.md step 0. - Switching homes: by default only re-fetch the home list and let the user choose (see
references/home-space-manage.md); do not default to re-login. Only if the user clearly asks to re-login/rotate the token, or the API indicates an expired/unauthorized token, follow references/aqara-account-manage.md for login.
- 4. Intent
- - Space / device query / device control; for multiple intents query first, then control, following clause order in the utterance.
| Intent | Capability | Reference |
|---|
| Space | List all homes; list rooms in a home | INLINECODE21 |
| Device query |
Filter by home/room; device details (incl. current attributes) |
references/devices-inquiry.md |
| Device control | Control hardware in the home |
references/devices-control.md |
- 5. Route to the matching
references/ doc, execute, and summarize.
- - Summarize from real outcomes only; never fabricate success or any homes, rooms, devices, attributes, counts, or states that are not grounded in actual script/API output (see Ground truth: no fabricated smart-home data above).
Wrapper shape (illustrative) — CLI scripts may print JSON with call_tool output under result for troubleshooting (fields as actually returned):
CODEBLOCK2
On bad params or JSON parse errors (illustrative):
CODEBLOCK3
Error handling
| Situation | Action |
|---|
| Device not found | Say no match for “X”; optionally list a few candidate names |
| Capability not supported |
State the unsupported action/attribute; do not pretend success |
| Home/room not found | Say no hit; suggest checking the home or re-fetching space/device lists per
references/ |
| Multiple devices match | List matches; ask the user to pick room or full name (one question at a time) |
| Not signed in / no
aqara_api_key | Guide login and saving
aqara_api_key, then continue with home fetch |
| No home selected | Clarify proactively; point to space-management flow |
| Invalid
aqara_api_key or auth failure | Ask to re-login or refresh the token (no sensitive leakage). On
home switch, only treat as auth failure if the home list call fails with an auth-class error—do not require login just because the user said “switch home”.
If the platform returns unauthorized or insufficient permissions (or equivalent), always follow references/aqara-account-manage.md to re-login and save the token; never fake query/control success |
| Control path unavailable | Say the device was located but the command could not be sent |
| Other | Short, understandable summary + retry or check
references/; do not expose internal URLs or full request headers |
| Indeterminate | Use
references/ and script output; if it’s a skill bug, file an issue in the skill repo |
| Risk of empty/missing API output |
Do not invent homes, rooms, devices, or readings to fill the gap; re-run the correct flow or explain the failure—see
Ground truth: no fabricated smart-home data |
Notes
- 1. Do not expose raw IDs in user-facing replies (device id, position id, homeid, …).
- Default query before control for multiple intents in one utterance.
- After adding/moving devices or rooms, if matching fails, re-fetch space and device lists via
references/home-space-manage.md and devices-inquiry.md, then retry. - User-visible replies: conclusion first, then detail; one key clarification question at a time.
- Session gate first: if not signed in, the “conclusion” should guide setup—not pretend devices were controlled.
- When
scripts/*.py must run, execute automatically; details follow mandatory script execution policy (if defined elsewhere). - After switching account or home, update
user_account.json and re-run the relevant steps in aqara-account-manage.md. - Do not echo tokens or full headers; treat
user_account.json and caches as sensitive. - Device name matching is often fuzzy; ask the user to confirm when multiple hits exist.
- In user-visible replies, do not print shell commands, script paths, raw stdout (incl. debug JSON), or
references/ filenames; the agent runs scripts; summarize in plain language. - When control APIs return success, keep the closing brief (result + essentials only); do not add hedging like “if some lights didn’t turn on, tell me”—troubleshoot only when the user reports an issue.
- Anti-hallucination: Treat Ground truth: no fabricated smart-home data as binding for every turn; any user-visible home/room/device/state detail must trace to a real run of this skill’s tooling, not to model imagination or general knowledge of “typical” smart homes.
Out of scope
The skill does not support:
- - Video / cameras — live view, playback
- Door locks — unlock, lock/unlock smart locks (security-sensitive)
- Scenes — run or list scenes
- Automations — list or create automations
- Energy — power usage / billing
- Weather — forecasts
If asked, say clearly that the skill cannot do it and suggest the Aqara Home app.
Aqara 智能家居 AI 技能
基础信息
- - 网站: https://www.aqara.com/cn/
- 技能根目录: skills/aqara-home-skills/(仓库内技能)
- Aqara 开放 API 的 Python 封装: scripts/aqaraopenapi.py — 直接调用 API 接口
核心工作流程
高级顺序:依赖安装 → 登录 → 选择家庭 → 意图识别 → 遵循 references/*.md 并总结
事实依据:禁止编造智能家居数据
大模型可能会幻觉出看似合理的家庭、房间、设备、状态或数量。对于本技能,这是明确禁止的:
- - 仅限真实数据源:家庭、房间、设备名称/ID(内部使用)、功能、实时属性(温度、亮度、开关状态、在线/离线等)、列表、数量、日志和控制结果必须仅来自已执行的技能脚本和真实的 Aqara API 响应——或来自用户提供的、技能设计可接受的输入(例如粘贴的 aqaraapikey)。如果相应的查询或控制流程尚未成功运行,不得将任何此类信息作为事实呈现。
- 绝不编造或“合理填充”:示例或演示风格的设备/家庭列表;猜测的房间布局;假定的设备数量;合成的属性值;在错误、超时、跳过步骤或缺少认证后编造的成功;模仿 API 输出但没有真实响应的 JSON 或文本。
- 数据缺失时:明确说明无法获取数据(以及原因,例如未登录、API 错误),然后遵循认证/重试/references/ 流程——绝不用想象的内容替代以使答案显得完整。
与上述用法和核心工作流程保持一致;按顺序执行:
- 1. 环境准备
bash
cd skills/aqara-home-skills
pip install -r scripts/requirements.txt
- 2. 认证 — 在使用任何功能前,验证 Aqara 账户认证并确保 user_account.json 可读/可写。
- - 遵循 references/aqara-account-manage.md。
- 登录界面字符串(标题、说明段落、链接标签、令牌保存行)位于 assets/loginprompti18n.json;根据该文件描述选择与用户语言匹配的区域设置——不要在回复中硬编码一种语言。回退方案:当语言未知或不支持时使用英语(en)(该文件中的 fallbacklocale / defaultlocale)。
user_account.json 格式:
json
{
aqaraapikey: ,
updated_at: ,
home_id: ,
home_name:
}
- 3. 家庭管理
- - 保存 aqaraapikey 后,自动遵循 references/home-space-manage.md 获取家庭列表并完成选择:立即运行该文档的步骤 0;如果只有一个家庭,则写入;如果有多个,让用户通过索引/名称选择。不要在未运行获取操作的情况下仅以“请回复家庭名称”结束。
- 当代理/终端运行脚本时:saveuseraccount.py(写入令牌)和 aqaraopenapi.py homes(获取家庭)必须分两次独立运行——不要在单行 shell 命令中用 && 连接;参见 references/aqara-account-manage.md 的步骤 2 和 references/home-space-manage.md 的步骤 0。
- 切换家庭:默认仅重新获取家庭列表并让用户选择(参见 references/home-space-manage.md);不要默认重新登录。仅当用户明确要求重新登录/更换令牌,或 API 指示令牌过期/未授权时,才遵循 references/aqara-account-manage.md 进行登录。
- 4. 意图识别
- - 空间/设备查询/设备控制;对于多个意图,按照话语中的子句顺序先查询后控制。
| 意图 | 功能 | 参考文档 |
|---|
| 空间 | 列出所有家庭;列出家庭中的房间 | references/home-space-manage.md |
| 设备查询 |
按家庭/房间筛选;设备详情(包括当前属性) | references/devices-inquiry.md |
| 设备控制 | 控制家中的硬件设备 | references/devices-control.md |
- 5. 路由到匹配的 references/ 文档,执行并总结。
- - 仅从真实结果中总结;绝不编造成功或任何未基于实际脚本/API 输出的家庭、房间、设备、属性、数量或状态(参见上文事实依据:禁止编造智能家居数据)。
封装格式(示例) — CLI 脚本可能打印包含 call_tool 输出的 JSON,其中 result 用于故障排查(字段按实际返回):
json
{
toolname: devicestatus_inquiry,
headers: { position_id: ... },
params: { device_ids: [...] },
result: {}
}
参数错误或 JSON 解析错误时(示例):
json
{
ok: false,
error: ...
}
错误处理
| 情况 | 操作 |
|---|
| 设备未找到 | 说明未匹配到“X”;可选地列出几个候选名称 |
| 不支持的功能 |
说明不支持的操作/属性;不要假装成功 |
| 家庭/房间未找到 | 说明未找到;建议检查家庭或根据 references/ 重新获取空间/设备列表 |
| 多个设备匹配 | 列出匹配项;让用户选择房间或完整名称(一次一个问题) |
| 未登录/无 aqara
apikey | 引导登录并保存 aqara
apikey,然后继续获取家庭 |
| 未选择家庭 | 主动澄清;指向空间管理流程 |
| 无效的 aqara
apikey 或认证失败 | 要求重新登录或刷新令牌(不泄露敏感信息)。
切换家庭时,仅当获取家庭列表调用返回认证类错误时才视为认证失败——不要仅仅因为用户说“切换家庭”就要求登录。
如果平台返回 unauthorized or insufficient permissions(或等效信息),始终遵循 references/aqara-account-manage.md 重新登录并保存令牌;绝不伪造查询/控制成功 |
| 控制路径不可用 | 说明已定位到设备但无法发送命令 |
| 其他 | 简短易懂的摘要 + 重试或检查 references/;不要暴露内部 URL 或完整请求头 |
| 不确定情况 | 使用 references/ 和脚本输出;如果是技能 bug,在技能仓库中提交 issue |
| API 输出为空/缺失的风险 |
不要编造家庭、房间、设备或读数来填补空白;重新运行正确的流程或解释失败原因——参见
事实依据:禁止编造智能家居数据 |
注意事项
- 1. 在面向用户的回复中不要暴露原始 ID(设备 ID、位置 ID、homeid 等)。
- 对于单条话语中的多个意图,默认先查询后控制。
- 添加/移动设备或房间后,如果匹配失败,通过 references/home-space-manage.md 和 devices-inquiry.md 重新获取空间和设备列表,然后重试。
- 用户可见的回复:先结论后细节;每次只提一个关键澄清问题。
- 会话门控优先:如果未登录,“结论”应引导设置——不要假装设备已被控制。
- 当必须运行 scripts/*.py 时,自动执行;详情遵循强制脚本执行策略(如果其他地方有定义)。
- 切换账户或家庭后,更新 useraccount.json 并重新运行 aqara-account-manage.md 中的相关步骤。
- 不要回显令牌或完整请求头;将 useraccount.json 和缓存视为敏感信息。
- 设备名称匹配通常是模糊的;当存在多个匹配时,请用户确认。
- 在面向用户的回复中,不要打印 shell 命令、脚本路径、原始标准输出(包括调试 JSON)或 references/ 文件名;代理运行脚本;用通俗语言总结。
- 当控制 API 返回成功时,保持结尾简洁(仅结果和要点);不要添加类似“如果有些灯没亮,请告诉我”的保留语句——仅在用户报告问题时进行故障排查。
- 反幻觉:将事实依据:禁止编造智能家居数据视为每次交互的约束;任何用户可见的家庭/房间/设备/状态细节必须追溯到本技能工具的实际运行,而非模型的想象或对“典型”智能家居的一般知识。
不适用范围
本技能不支持: