烟雾模块阈值告警
本例展示 ADC 原始读数、蜂鸣器、指示灯和 MQTT 设备事件的联动,不把 MQ-2 原始 ADC 计数称为已标定烟雾浓度。传感器预热、基准、气体交叉敏感性及浓度换算按实际模块说明和标定处理,不能仅用 2000 判定“中等烟雾”。
保存 smoke_sensor 原始 ADC 输入、buzzer_01 有源蜂鸣器和 led_alarm 数字输出。GPIO34 仅是经典 ESP32 的示例 ADC1 输入,不适用于全部芯片。5V 模块 AO 可能超出 GPIO 电压范围,先测量并配置分压或合适前端;ADC 衰减并不使 GPIO 变成 5V 容忍,也不保证 0~4095 与 0~3.3V 线性对应。
采集与告警规则
示例假设 ADC 已配置为原始计数,读数随目标环境变化增大,蜂鸣器/LED 均 HIGH 有效。实际方向和极性不同须调整。三条规则先停用:
json
{
"rules": [
{
"id": "exec_smoke_read",
"name": "exec_smoke_read",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 1,
"timerMode": 0,
"intervalSec": 5
}
],
"actions": [
{
"actionType": 19,
"targetPeriphId": "smoke_sensor",
"actionValue": "{\"periphId\":\"smoke_sensor\",\"sensorCategory\":\"analog\",\"channelField\":\"analog\",\"dataField\":\"analog\",\"unit\":\"count\"}"
}
],
"reportAfterExec": true
},
{
"id": "exec_smoke_alarm",
"name": "exec_smoke_alarm",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 4,
"eventId": "ds:smoke_sensor_analog",
"operatorType": 2,
"compareValue": "2000"
}
],
"actions": [
{
"actionType": 2,
"targetPeriphId": "buzzer_01",
"actionValue": "300"
},
{
"actionType": 2,
"targetPeriphId": "led_alarm",
"actionValue": "500"
},
{
"actionType": 21,
"targetPeriphId": "device_alarm",
"actionValue": "smoke_threshold"
}
],
"reportAfterExec": true
},
{
"id": "exec_smoke_recover",
"name": "exec_smoke_recover",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 4,
"eventId": "ds:smoke_sensor_analog",
"operatorType": 3,
"compareValue": "1000"
}
],
"actions": [
{
"actionType": 1,
"targetPeriphId": "buzzer_01"
},
{
"actionType": 1,
"targetPeriphId": "led_alarm"
}
],
"reportAfterExec": true
}
]
}device_alarm 是内置可发送设备事件。若用自定义 smoke_alarm,必须先创建并保存 DEVICE_EVENT(类型 60)再引用,不能只手写不存在的事件 ID。
2000/1000 与 5 秒都是演示参数,应按实际标定、响应需求和资源预算选择。中间区保持最近输出;读失败和过期不会生成虚假恢复值,也没有自动关闭报警的承诺。此通用阈值示例不能替代有认证要求的独立火灾报警设备。
先验证采集、原始缓存 smoke_sensor_analog、输出极性、实际声音/灯光与平台收到的事件,再启用。每个超限有效样本可能重复产生告警,MQTT 请求入队不等于送达。详见读取动作、事件动作。

