- Home
- Plugins
- Dev & Plugin Tools
- dsh-smart-home-simulator
dsh-smart-home-simulator
cube-ai/dsh-smart-home-simulator
A draggable, resizable floating panel that simulates an air conditioner, light, curtain, and air purifier, with an agent-callable control tool. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.
Install
dsh plugin --profile web add github:cube-ai/dsh-smart-home-simulatorREADME
智慧家庭模拟器(Smart Home Simulator)
一个 DSH Web 插件:侧边栏入口打开一个可拖动、可缩放的悬浮面板,演示空调、灯光、窗帘和空气净化器;同时注册一个 smart_home_control 工具,让大模型可以实时调节面板里的状态。
本插件仅供演示。所有状态都是插件内存里的模拟数据,不连接任何真实家电。
安装
方式 A:界面安装(推荐)
在 DSH 的「插件 → 添加插件」中输入:
@cubeai/dsh-smart-home-simulator
或从源码仓库安装:
https://openi.pcl.ac.cn/dsh/dsh-smart-home-simulator.git
安装后刷新 DSH,左侧栏下方会出现 智慧家庭模拟器。
方式 B:命令行安装
dsh plugin --profile web add @cubeai/dsh-smart-home-simulator
或:
dsh plugin --profile web add https://openi.pcl.ac.cn/dsh/dsh-smart-home-simulator.git
安装后如果页面没有自动加载新模块,刷新一次 Web GUI。插件是 profile 级安装,对该 profile 的所有会话生效。
功能
- 侧边栏入口:Settings 上方的整行菜单项,右侧显示“N 台运行 / 全关”;侧边栏收起时变成 36×36 图标。
- 悬浮面板:拖动标题栏移动,拖动任意边缘或四角缩放,X 或 Esc 关闭;位置和尺寸保存在浏览器
localStorage。 - 四件设备
- 空调:开关、制冷/制热/送风、16–30 °C、风速、摆风;出风动画。
- 灯光:开关、亮度 1–100、暖光/自然/冷光;光晕随亮度和色温变化。
- 窗帘:0–100% 开合滑杆、全开/全关;帘布开合动画。
- 空气净化器:开关、风速、PM2.5 圆环和旋转风扇。
- 场景:回家、离家、睡眠、影院。
- AI 联动:工具修改状态后,面板若未打开会自动弹出,对应卡片高亮并显示“AI 已调节…”提示。
- 亮/暗主题都使用 DSH 的
--dsw-alias-*token;设备图形使用独立配色。
工具
工具名:smart_home_control。一个 dispatcher,通过 device + action 区分操作。
| 参数 | 类型 | 说明 |
|---|---|---|
device | ac / light / curtain / purifier / all | 目标设备;all 用于场景、状态、重置、整屋开关 |
action | status / on / off / set / scene / reset | status 只读;on/off 开关(窗帘为开/关);set 改设置并自动开机;scene 应用场景;reset 恢复默认 |
temperature | 16–30 | 仅 ac + set |
brightness | 1–100 | 仅 light + set |
color_temp | warm / neutral / cool | 仅 light + set |
position | 0–100 | 仅 curtain + set |
mode | cool / heat / fan | 仅 ac + set |
fan_speed | auto / low / medium / high | 空调或净化器 |
swing | boolean | 仅空调 |
scene | home / away / sleep / movie | action=scene 时必填 |
每次调用都返回 { ok, message, state },模型不需要二次查询。参数错误返回可读的 message,不会中断会话。
远程状态命令
给「智慧家庭客户端」的图形页签使用,插件额外注册了一个只读扩展命令:
/smarthome status
→ SH_STATE:{"homeId":"...","revision":12,"room":{...},"devices":{...}}
- 该命令走 DSH 的命令注册表,由飞书频道的
ChatCommands直接执行,不经过大模型。 - 返回的是精简后的状态(不含
lastChange),用于 Web 客户端首次打开和操作后对账。 - 控制操作仍然由 Web 客户端以用户身份发送自然语言提示词,远端 Agent 调用
smart_home_control。 - 飞书频道需要在私聊中允许命令;如果回复“上一条消息正在合并”,等 5 秒再发。
- 该命令不是工具,不会出现在模型的工具列表里;工具的
status动作仍然保留。
演示脚本
可以直接对模型说:
- “把空调调到 24 度,风速自动。”
- “打开窗帘到 100%,灯光调到 40% 暖光。”
- “我回家了。” → 回家场景
- “现在家里各设备什么状态?” →
status - “睡眠模式。” → 睡眠场景
- “全部关掉。” → 整屋 off
状态与同步
- Host 侧
index.js持有唯一状态,2 秒一个 tick 让室温和 PM2.5 缓慢趋近设备设置。 - Client 通过
/api/smart-home/state、/api/smart-home/action、/api/smart-home/wait三个受 DSH/api鉴权保护的精确 fetch 路由同步;wait是 15–20 秒长轮询,状态一变更立刻返回,断线自动重试。 - 面板操作和工具调用走同一个
applyActionreducer,避免两套逻辑。 - 状态只在内存中,DSH 重启后恢复默认;多个标签页/会话共享同一个“家”。
开发
dsh-smart-home-simulator/
├─ package.json
├─ cordis.patch.yml
├─ index.js # Host:状态、仿真、fetch 路由、工具
├─ client.js # Client:侧边栏入口、悬浮窗、四件设备、同步
├─ locale/zh.json
├─ locale/en.json
├─ icon.svg
├─ README.md
└─ test/state.test.mjs # reducer / 场景 / tick / wait 单测
本地校验:
node --check index.js
node --check client.js
node --test test/state.test.mjs
已知边界
- 不接真实设备、MQTT 或 Home Assistant;没有持久化。
- 状态是 profile 全局单例,不是每个会话一份。
- 侧边栏入口位于
sidebar.footer.action。DSH 现有的 Cordis 面板入口占满该区域一行,因此插件给这个 slot 的父容器加了一条flex-wrap,让两个整行入口上下排列;这是唯一一处宿主布局适配,作用域仅限该 slot。 - 悬浮面板的像素级效果需要在浏览器里实际查看;安装脚本只能验证注册、状态逻辑和工具 schema。
Related plugins
deepseek-harness
deepseek-ai/deepseek-harness
dsh-market
dsh-market/dsh-market
dsh-web (dsh-plugin-manager)
zhu1090093659/dsh-web
dsh-web
zhu1090093659/dsh-web