Skip to content

光敏自动灯控场景 ​

先保存模拟输入 light_sensor 和数字输出 relay_light。ADC 引脚按实际芯片选择;GPIO32~39 仅是经典 ESP32 的部分 ADC1 引脚,不能套用 C3/C6/S3。输入电压不得超过板卡允许范围,模块 AO 高于 3.3V 时使用合适的分压或电平接口。

采集与控制 ​

本例明确使用已配置 ADC 的原始计数,假设实测为“越暗计数越小”、输出 HIGH 吸合/LOW 释放。模块方向、转换模式或继电器极性不同必须同步调整,500/2000 只是演示值,不是通用照度阈值。

三条规则分别采集、判暗和判亮,先均保持停用:

json
{
  "rules": [
    {
      "id": "exec_light_collect",
      "name": "exec_light_collect",
      "enabled": false,
      "execMode": 0,
      "triggers": [
        {
          "triggerType": 1,
          "timerMode": 0,
          "intervalSec": 5
        }
      ],
      "actions": [
        {
          "actionType": 19,
          "targetPeriphId": "light_sensor",
          "actionValue": "{\"periphId\":\"light_sensor\",\"sensorCategory\":\"analog\",\"channelField\":\"analog\",\"dataField\":\"analog\",\"unit\":\"count\"}"
        }
      ],
      "reportAfterExec": true
    },
    {
      "id": "exec_light_dark",
      "name": "exec_light_dark",
      "enabled": false,
      "execMode": 0,
      "triggers": [
        {
          "triggerType": 4,
          "eventId": "ds:light_sensor_analog",
          "operatorType": 3,
          "compareValue": "500"
        }
      ],
      "actions": [
        {
          "actionType": 0,
          "targetPeriphId": "relay_light"
        }
      ],
      "reportAfterExec": true
    },
    {
      "id": "exec_light_bright",
      "name": "exec_light_bright",
      "enabled": false,
      "execMode": 0,
      "triggers": [
        {
          "triggerType": 4,
          "eventId": "ds:light_sensor_analog",
          "operatorType": 2,
          "compareValue": "2000"
        }
      ],
      "actions": [
        {
          "actionType": 1,
          "targetPeriphId": "relay_light"
        }
      ],
      "reportAfterExec": true
    }
  ]
}

先启用采集并确认缓存 light_sensor_analog,再在授权的现场范围测试输出极性和阈值。告警/控制监听 ds:light_sensor_analog,不是平台触发,也不是填写传感器 ID 就自动采集。

500~2000 的中间区保持最近输出,形成迟滞;启动状态单独配置。本例不是持续温控控制器,数据失鲜或采集失败不会自动合成恢复读数、把灯关掉或提供专用故障锁定。需要此类业务保证时增加对应受支持方案并验收,不能把原始 ADC 数值标为 lux。

上报依赖 MQTT 实例与主题,软件输出结果不证明继电器触点或照明负载。见传感器动作、GPIO 动作和轮询与条件。

蜂信物联 | fastbee.cn