Aqara Smart Home AI Agent Skill
Basics
- - Aqara Open Host (default):
agent.aqara.com (override via AQARA_OPEN_HOST) - Skill root:
skills/aqara-agent/ (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
- - Set environment host first (single-switch for test/prod):
CODEBLOCK0
- - Install dependencies before use:
CODEBLOCK1
- 2. Auth — Before any feature, verify Aqara account auth and ensure
user_account.json is readable/writable (project rules may require reading it first). Follow references/aqara-account-manage.md for switch-home vs re-login, token save, and §1 login layout. Locale strings and default_login_url live in assets/login_reply_prompt.json—match the user’s language; fallback to en when unknown (fallback_locale / default_locale in that file). Login URL / QR / “stop after qr_fallback_line” rules: see Canonical login above.
INLINECODE15 shape:
CODEBLOCK2 S
- 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 | INLINECODE25 |
| 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 |
| Scene | List and execute scenes |
references/scene-manage.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):
CODEBLOCK3
On bad params or JSON parse errors (illustrative):
CODEBLOCK4
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.
- Never invent homes, rooms, devices, scenes, or states: only report data from executed scripts/API responses."
Out of scope
The skill does not support:
- - Video / cameras — live view, playback
- Door locks — unlock, lock/unlock smart locks (security-sensitive)
- 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-agent
详细描述:
Aqara智能家居AI智能体技能
基础信息
- - Aqara开放主机(默认):agent.aqara.com(可通过AQARAOPENHOST覆盖)
- 技能根目录:skills/aqara-agent/(仓库内技能)
- Aqara开放API的Python封装:scripts/aqaraopenapi.py — 直接调用API接口。
核心工作流程
高级顺序:依赖安装 → 登录 → 选择家庭 → 意图识别 → 遵循references/*.md并总结。
事实依据:禁止编造智能家居数据
大模型可能会幻觉出看似合理的家庭、房间、设备、状态或数量。对于本技能,这是明确禁止的:
- - 仅限事实来源:家庭、房间、设备名称/ID(内部使用)、功能、实时属性(温度、亮度、开关状态、在线/离线等)、列表、数量、日志以及控制结果必须仅来自已执行的技能脚本和真实的Aqara 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. 认证 — 在任何功能之前,验证Aqara账户认证并确保useraccount.json可读/可写(项目规则可能要求先读取它)。遵循references/aqara-account-manage.md进行切换家庭与重新登录、令牌保存以及§1登录布局。本地化字符串和defaultloginurl位于assets/loginreplyprompt.json中——匹配用户的语言;未知时回退到en(该文件中的fallbacklocale / defaultlocale)。登录URL/二维码/“在qrfallback_line后停止”规则:请参见上面的规范登录。
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 |
| 场景 | 列出并执行场景 | references/scene-manage.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/和脚本输出;如果是技能错误,在技能仓库中提交问题 |
| 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返回成功时,保持结尾简洁(仅结果和必要信息);不要添加诸如“如果有些灯没亮,请告诉我”之类的模糊表述——仅在用户报告问题时才进行故障排除。
- 反幻觉:将事实依据:禁止编造智能家居数据视为