跳转到内容

LD2412 传感器

ld2412 传感器平台允许您在 ESPHome 中使用 HI-LINK LD2412 运动和存在传感器。

此传感器需要在您的配置中设置 UART 才能工作;parity 和 stop_bits 必须分别为 NONE 和 1。

强烈建议使用硬件 UART,因为它能最好地支持传感器模块默认的 115200 波特率。

LD2412 运动和存在传感器
# Example configuration entry
ld2412:
  • uart_id (可选,ID): 手动指定 UART 组件 的 ID, 如果您的配置中定义了多个 UART,则此项为必需。

  • id (可选,ID): 手动为此组件指定 ID。

ld2412 二值传感器可帮助您快速确定传感器报告的多种状态。

binary_sensor:
- platform: ld2412
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
dynamic_background_correction_status:
name: Dynamic Background Correction Status
  • has_target (可选): 如果为 true,表示检测到静止或运动的目标。 来自 Binary Sensor 的所有选项。

  • has_moving_target (可选): 如果检测到运动目标则为 true。 来自 Binary Sensor 的所有选项。

  • has_still_target (可选): 如果检测到静止目标则为 true。 来自 Binary Sensor 的所有选项。

  • dynamic_background_correction_status (可选): 传感器执行动态背景 校正期间为 true。来自 Binary Sensor 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

NOTE

默认情况下,上述每个目标 Binary Sensor 组件都包含 以下过滤器,以防止向 Home Assistant 大量推送状态更新:

- settle: 1000ms

如果您已定义其他过滤器,此默认值将被覆盖;当然,如果您愿意,可以按照上述方式将其添加到自定义 过滤器中。

要移除任意给定二值传感器实例的默认过滤器,请在其配置中添加 filters: []。

ld2412 传感器可报告传感器采集的各种测量值。

sensor:
- platform: ld2412
moving_distance:
name : Moving Distance
still_distance:
name: Still Distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
light:
name: light
gate_0:
move_energy:
name: Gate 0 move energy
still_energy:
name: Gate 0 still energy
gate_1:
move_energy:
name: Gate 1 move energy
still_energy:
name: Gate 1 still energy
gate_2:
move_energy:
name: Gate 2 move energy
still_energy:
name: Gate 2 still energy
gate_3:
move_energy:
name: Gate 3 move energy
still_energy:
name: Gate 3 still energy
gate_4:
move_energy:
name: Gate 4 move energy
still_energy:
name: Gate 4 still energy
gate_5:
move_energy:
name: Gate 5 move energy
still_energy:
name: Gate 5 still energy
gate_6:
move_energy:
name: Gate 6 move energy
still_energy:
name: Gate 6 still energy
gate_7:
move_energy:
name: Gate 7 move energy
still_energy:
name: Gate 7 still energy
gate_8:
move_energy:
name: Gate 8 move energy
still_energy:
name: Gate 8 still energy
gate_9:
move_energy:
name: Gate 9 move energy
still_energy:
name: Gate 9 still energy
gate_10:
move_energy:
name: Gate 10 move energy
still_energy:
name: Gate 10 still energy
gate_11:
move_energy:
name: Gate 11 move energy
still_energy:
name: Gate 11 still energy
gate_12:
move_energy:
name: Gate 12 move energy
still_energy:
name: Gate 12 still energy
gate_13:
move_energy:
name: Gate 13 move energy
still_energy:
name: Gate 13 still energy
  • light (可选,int): 在工程模式下,指示灯光 灵敏度,否则指示 unknown。值介于 0 到 255 之间(含)。注意,这是任意单位,不对应于任何特定的强度测量单位。来自 Sensor 的所有选项。

  • moving_distance (可选,int): 检测到的运动目标的距离,单位为厘米。来自 Sensor 的所有选项。

  • still_distance (可选,int): 检测到的静止目标的距离,单位为厘米。来自 Sensor 的所有选项。

  • moving_energy (可选,int): 运动目标的能量。值介于 0 到 100 之间(含)。来自 Sensor 的所有选项。

  • still_energy (可选,int): 静止目标的能量。值介于 0 到 100 之间(含)。来自 Sensor 的所有选项。

  • detection_distance (可选,int): 目标的距离,单位为厘米。来自 Sensor 的所有选项。

  • gate_X (可选): 门 X 的能量值,其中 X 在 0 到 13 范围内。

    • move_energy (可选,int): 在工程模式下,指示 门的运动能量,否则指示 unknown。值介于 0 到 100 之间(含)。来自 Sensor 的所有选项。

    • still_energy (可选,int): 在工程模式下,指示 门的静止能量,否则指示 unknown。值介于 0 到 100 之间(含)。来自 Sensor 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

NOTE

默认情况下,上述每个 Sensor 组件都包含以下 过滤器,以防止向 Home Assistant 大量推送状态更新:

- throttle_with_priority: 1000ms

如果您已定义其他过滤器,此默认值将被覆盖;当然,如果您愿意,可以按照上述方式将其添加到自定义 过滤器中。

要移除任意给定传感器实例的默认过滤器,请在其配置中添加 filters: []。

ld2412 开关允许您在前端启用或禁用传感器功能。

switch:
- platform: ld2412
engineering_mode:
name: Engineering Mode
bluetooth:
name: Bluetooth
  • bluetooth (可选): 打开/关闭蓝牙适配器。默认为 true。来自 Switch 的所有选项。

  • engineering_mode 打开/关闭工程模式。来自 Switch 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

ld2412 数值允许您控制模块的配置。

number:
- platform: ld2412
timeout:
name: Presence Timeout
min_distance_gate:
name: Minimum Distance Gate
max_distance_gate:
name: Maximum Distance Gate
light_threshold:
name: Light Threshold
gate_0:
move_threshold:
name: Gate 0 Move Threshold
still_threshold:
name: Gate 0 Still Threshold
gate_1:
move_threshold:
name: Gate 1 Move Threshold
still_threshold:
name: Gate 1 Still Threshold
gate_2:
move_threshold:
name: Gate 2 Move Threshold
still_threshold:
name: Gate 2 Still Threshold
gate_3:
move_threshold:
name: Gate 3 Move Threshold
still_threshold:
name: Gate 3 Still Threshold
gate_4:
move_threshold:
name: Gate 4 Move Threshold
still_threshold:
name: Gate 4 Still Threshold
gate_5:
move_threshold:
name: Gate 5 Move Threshold
still_threshold:
name: Gate 5 Still Threshold
gate_6:
move_threshold:
name: Gate 6 Move Threshold
still_threshold:
name: Gate 6 Still Threshold
gate_7:
move_threshold:
name: Gate 7 Move Threshold
still_threshold:
name: Gate 7 Still Threshold
gate_8:
move_threshold:
name: Gate 8 Move Threshold
still_threshold:
name: Gate 8 Still Threshold
gate_9:
move_threshold:
name: Gate 9 Move Threshold
still_threshold:
name: Gate 9 Still Threshold
gate_10:
move_threshold:
name: Gate 10 Move Threshold
still_threshold:
name: Gate 10 Still Threshold
gate_11:
move_threshold:
name: Gate 11 Move Threshold
still_threshold:
name: Gate 11 Still Threshold
gate_12:
move_threshold:
name: Gate 12 Move Threshold
still_threshold:
name: Gate 12 Still Threshold
gate_13:
move_threshold:
name: Gate 13 Move Threshold
still_threshold:
name: Gate 13 Still Threshold
  • timeout (可选,int): 不再检测到存在后存在状态保持的秒数。默认为 5s。来自 Number 的所有选项。

  • min_distance_gate (可选,int): 运动检测的最大距离门。值介于 1 到 12 之间(含)。默认为 1。来自 Number 的所有选项。

  • max_distance_gate (可选,int): 静止检测的最大距离门。值介于 2 到 13 之间(含)。默认为 13。来自 Number 的所有选项。

  • light_threshold (可选,int): 灯光激活传感器 OUT 引脚的阈值。来自 Number 的所有选项。

  • gate_X (可选): 门 X 的阈值,其中 X 在 0 到 13 范围内。

    • move_threshold(必选,int): 运动检测的门阈值。对于相应门, 超过此水平的值将导致检测到运动。值介于 0 到 100 之间(含)。 参见下方默认值。来自 Number 的所有选项。

    • still_threshold(必选,int): 静止检测的门阈值。对于相应门, 低于此水平的值将导致检测到静止。值介于 0 到 100 之间(含)。 参见下方默认值。来自 Number 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

ld2412 按钮允许您对传感器执行操作。

button:
- platform: ld2412
factory_reset:
name: Factory Reset
restart:
name: Restart
query_params:
name: Query Params
start_dynamic_background_correction:
name: Start Dynamic Background Correction
  • factory_reset (可选): 此命令用于将所有配置值恢复为原始值。 来自 Button 的所有选项。

  • restart (可选): 重启设备。来自 Button 的所有选项。

  • query_params (可选): 刷新设备的所有传感器值。来自 Button 的所有选项。

  • start_dynamic_background_correction (可选): 启动动态背景校正。来自 Button 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

ld2412 文本传感器可报告传感器元数据。

text_sensor:
- platform: ld2412
version:
name: Firmware Version
mac_address:
name: Mac Address
  • version (可选): 固件版本。来自 Text Sensor 的所有选项。

  • mac_address (可选): 蓝牙 MAC 地址。蓝牙关闭时将设为 unknown。来自 Text Sensor 的所有选项。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

ld2412 选择器允许您配置传感器硬件。

select:
- platform: ld2412
out_pin_level:
name: Hardware Output Pin Level
distance_resolution:
name: Distance Resolution
light_function:
name: Light Function
baud_rate:
name: Baud Rate
  • distance_resolution (可选): 控制门的距离分辨率。可为 0.75m、0.5m 或 0.2m。 默认为 0.75m。来自 Select 的所有选项。

  • baud_rate (可选): 允许更改 LD2412 串口的波特率。默认为 115200。更改后, 传感器将停止工作,直到在设备的配置中更新 UART 组件 的波特率。来自 Select 的所有选项。

  • out_pin_level (可选): 允许选择传感器检测到存在时 LD2412 的 OUT 引脚行为。 可为 low 或 high。默认为 low。来自 Select 的所有选项。

  • light_function (可选): 允许选择 LD2412 的 OUT 引脚对光水平的响应方式。可为 off、below 或 above。注意,此功能与存在检测配合使用。详见参考 手册。

  • ld2412_id (可选,ID): 手动为组件指定 ID。使用多个 组件时为必需。

LD2412 的 OUT 引脚提供了一种简单的硬件机制,报告传感器是否检测到存在(和 灯光)。如果需要,可以设置一个 GPIO 二值传感器:

binary_sensor:
- platform: gpio
pin: GPIOXX
name: LD2412 Out Pin Status
device_class: presence

要校准传感器,请执行以下操作:

  1. 启用工程模式。
  2. 监控 gate_X_move_energy 和 gate_X_still_energy 传感器。
  3. 更改阈值并重复第 2 步,直到满意为止。
  4. 禁用工程模式。

或者,您也可以离开房间,打开”动态背景校正”,让它自行校准。