自动化规则
规则引擎让 NeoMind 在无人值守时自动响应:设备数据越过阈值 → 自动通知、下发指令、触发 AI Agent。规则以 JSON 格式定义,通过 Web UI、CLI、REST API 或 AI Chat 创建。
NeoMind 的自动化页面包含两个页签:Rules(规则) 和 Transforms(数据转换)。本文档介绍 Rules,数据转换见 数据转换。
前置条件
界面概览
点击左侧导航的 Automation(分支图标)进入自动化页面,默认显示 Rules 页签:
页面以表格形式展示所有规则,每行包含:
| 列 | 说明 |
|---|---|
| 规则名称 | 你设置的名称 |
| 触发器 | Data Change / Schedule / Manual |
| 条件摘要 | 规则条件的文本预览(如 temperature > 30) |
| 动作 | 该规则包含的动作列表(Notify / Execute / Trigger Agent) |
| 状态开关 | 启用 / 禁用切换 |
| 操作菜单 | 编辑、删除、立即执行 |
右上角的 Import / Export 按钮可批量导入导出规则 JSON。
规则结构
一条规则由四部分组成——名称、触发器、条件、动作(可选持续时间与冷却):
{
"name": "高温告警",
"trigger": { "trigger_type": "data_change" },
"condition": {
"condition_type": "comparison",
"source": "device:sensor-01:temperature",
"operator": "greater_than",
"threshold": 30
},
"actions": [
{ "type": "notify", "message": "温度过高:{value}°C", "severity": "critical" }
]
}
通过 Web UI 创建规则
步骤 1:打开规则构建器
在 Rules 页签点击 Create 按钮,打开全 屏规则构建器:
构建器顶部填写:
| 字段 | 说明 |
|---|---|
| Name(名称) | 规则的显示名称 |
| Description(描述) | 可选,说明规则用途 |
| Trigger(触发器) | 选择触发方式(见下文) |
步骤 2:配置触发器
| 触发类型 | 说明 | 适用场景 |
|---|---|---|
| Data Change | 条件引用的指标有新数据时自动评估 | 实时告警、阈值监控 |
| Schedule | 按 cron 表达式定时触发 | 定时播报、周期性检查 |
| Manual | 仅手动触发(API / CLI / UI 按钮) | 调试、按需执行 |
Cron 表达式为 6 段:
秒 分 时 日 月 周。"0 */5 * * * *"= 每 5 分钟。
data_change 触发器会自动从 condition 中提取引用的数据源,无需手动指定 sources。
步骤 3:配置条件
条件决定规则何时触发。支持三种类型:
比较条件(comparison)——值与阈值比较:
| 运算符 | 含义 | 阈值字段 |
|---|---|---|
greater_than | 大于 | threshold(数字) |
less_than | 小于 | threshold(数字) |
greater_equal | 大于等于 | threshold(数字) |
less_equal | 小于等于 | threshold(数字) |
equal | 等于 | threshold(数字/布尔) |
not_equal | 不等于 | threshold |
contains | 包含(字符串) | threshold_value(字符串) |
starts_with | 前缀匹配 | threshold_value |
ends_with | 后缀匹配 | threshold_value |
regex | 正则匹配 | threshold_value |
source 使用 DataSourceId 格式 {type}:{id}:{field},如 device:sensor-01:temperature。
范围条件(range)——值在某区间内时触发:
{ "condition_type": "range", "source": "device:sensor-01:temperature", "min": 20, "max": 25 }
逻辑组合(logical)——AND / OR / NOT 嵌套多个子条件:
{
"condition_type": "logical",
"operator": "and",
"conditions": [
{ "condition_type": "comparison", "source": "device:sensor-01:temperature", "operator": "greater_than", "threshold": 30 },
{ "condition_type": "comparison", "source": "device:sensor-01:humidity", "operator": "less_than", "threshold": 20 }
]
}
步骤 4:配置动作
条件满足后执行的操作。一条规则可以有多个动作,按顺序执行。
| 动作 | type 值 | 说明 |
|---|---|---|
| 发送通知 | notify | 消息模板支持 {value}、{source_id} 插值 |
| 执行指令 | execute | 下发控制指令到设备或扩展 |
| 触发 Agent | trigger_agent | 调用 AI Agent 做深度分析 |
notify 动作——severity 取值:info、warning、critical、emergency
{ "type": "notify", "message": "温度过高:{value}°C", "severity": "critical" }
execute 动作——下发设备控制指令:
{ "type": "execute", "target": "humidifier-01", "target_type": "device", "command": "power_on", "params": { "level": 3 } }
trigger_agent 动作——调用 AI Agent:
{ "type": "trigger_agent", "agent_id": "diagnostic", "input": "sensor-03 离线,请诊断原因" }