跳转到内容

Belling BL0940 电能监控器

bl0940 组件允许您在 ESPHome 中使用 BL0940 电能监控传感器。这些传感器用于一些 Tuya 设备(例如功率计 BW-SHP10)和 Vaiotech Rowi2 智能插座。

与该组件的通信通过 UART 进行。因此,您必须在配置中添加一个 uart: 条目,并将 TX 和 RX 引脚设置到板子上的某些引脚,波特率设置为 4800,停止位设置为 1。

# 示例配置
sensor:
- platform: bl0940
voltage:
name: 'BL0940 Voltage'
current:
name: 'BL0940 Current'
power:
name: 'BL0940 Power'
energy:
name: 'BL0940 Energy'
internal_temperature:
name: 'BL0940 Internal temperature'
external_temperature:
name: 'BL0940 External temperature'
  • uart_id (可选): 如果要使用多个 UART 总线,请手动指定 UART 组件的 ID。
  • legacy_mode (可选, 布尔值): 是否使用初始实现的旧版配置。 默认值为 true 以防止破坏性更改。
  • read_command (可选): 与 BL0940 通信时用于读取命令的字节。 默认设置为 0x58,或在 legacy_mode 中为 0x50
  • write_command (可选): 与 BL0940 通信时用于写入命令的字节。 默认设置为 0xA8,或在 legacy_mode 中为 0xA0
  • voltage (可选): 传感器的电压值,单位为伏特。所有选项来自 传感器
  • current (可选): 传感器的电流值,单位为安培。所有选项来自 传感器
  • power (可选): 传感器的(有功)功率值,单位为瓦特。所有选项来自 传感器
  • energy (可选): 使用传感器的电压值,单位为 kWh。所有选项来自 传感器
  • internal_temperature (可选): 传感器的内部温度值,单位为 °C。 所有选项来自 传感器
  • external_temperature (可选): 传感器的外部温度值,单位为 °C。通常未连接,会产生垃圾数据。所有选项来自 传感器
  • update_interval (可选): 检查传感器的时间间隔。默认值为 60s
  • reference_voltage (可选, 浮点数): Vref 的校准参数。默认值为 1.218

  • resistor_shunt (可选, 浮点数): RL 的校准参数。默认值为 1

  • resistor_one (可选, 浮点数): R1 的校准参数。默认值为 0.51

  • resistor_two (可选, 浮点数): R2 的校准参数。默认值为 1950

  • voltage_reference (可选, 浮点数): 电压读数的校准参数。 默认值为 266013.136288998,使用架构默认值计算。

  • current_reference (可选, 浮点数): 电流读数的校准参数。 默认值为 17158.9201389365,使用架构默认值计算。

  • power_reference (可选, 浮点数): 功率读数的校准参数。 默认值为 713.104696500825,使用架构默认值计算。

  • energy_reference (可选, 浮点数): 累计电能读数的校准参数。 默认值为 6120.6267056536,使用架构默认值计算。

有两个基本校准参数取决于硬件设计:voltage_referencecurrent_reference

这些可以通过检查实际硬件设计或使用准确的电压和电流表配合简单的电阻性负载来确定。

# 原理图选项默认值
reference_voltage: 1.218 # Vref = 1.218
resistor_shunt: 1 # RL = 1 mΩ
resistor_one: 0.51 # R1 = 0.51 kΩ
resistor_two: 1950 # R2 = 5 x 390 kΩ -> 1950 kΩ

默认值基于 BL0940_APPNote_TSSOP14_V1.04_EN.pdf

默认情况下,所有参考值将使用上述值按以下确切顺序计算。

this->voltage_reference_ = 79931 / this->vref_ * (this->r_one_ * 1000) / (this->r_one_ + this->r_two_);
this->current_reference_ = 324004 * this->r_shunt_ / this->vref_;
// 如果已配置 voltage_reference 和 current_reference
this->power_reference_ = this->voltage_reference_ * this->current_reference_ * 4046 / 324004 / 79931;
// 如果没有,我们使用规格中提供的公式
this->power_reference_ = 4046 * this->r_shunt_ * this->r_one_ * 1000 / this->vref_ / this->vref_ / (this->r_one_ + this->r_two_);
this->energy_reference_ = this->power_reference_ * 3600000 / (1638.4 * 256);

如果启用了 legacy_mode,参考值将根据初始实现设置。

this->voltage_reference_ = 33000;
this->current_reference_ = 275000;
this->power_reference_ = 1430;
this->energy_reference_ = 3.6e6 / 297;

任何参考值都可以手动配置;用户指定的值将优先于计算/预定义的值。

理论上,配置 voltage_referencecurrent_reference 应该足以校准传感器,但为了完整性,power_referenceenergy_reference 也是可配置的。

# 自定义参考值
voltage_reference: 17158.9201389365
current_reference: 266013.136288998
power_reference: 713.104696500825
energy_reference: 6120.6267056536

bl0940 数值平台允许在线校准传感器读数。

number:
- platform: bl0940
current_calibration:
name: Current Calibration
voltage_calibration:
name: Voltage Calibration
power_calibration:
name: Power Calibration
energy_calibration:
name: Energy Calibration
  • current_calibration (可选): 启用电流校准配置。
  • voltage_calibration (可选): 启用电压校准配置。
  • power_calibration (可选): 启用功率校准配置。
  • energy_calibration (可选): 启用电能校准配置。
  • min_value (可选, 浮点数): 此数值可设置的最小值。允许的最小值为 -50,默认值为 -10
  • max_value (可选, 浮点数): 此数值可设置的最大值。允许的最大值为 50,默认值为 10
  • step (可选, 浮点数): 设置数值的粒度。默认值为 0.1
  • restore_value (可选, 布尔值): 将状态保存并加载到 RTC/闪存。默认值为 true
  • 所有其他选项来自 数值

校准因子根据配置的 calibration 组件提交的值以 % 计算。

float BL0940::calculate_calibration_value_(float state) { return (100 + state) / 100; }

在 UI 上更改校准值时,所有校准的参考值将被重新计算。

如果未手动指定,voltage_calibrationcurrent_calibration 将影响 power_referenceenergy_reference

bl0940 按钮平台允许将所有外部校准值重置为初始状态。

button:
- platform: bl0940
name: Reset Calibration
  • 所有选项来自 按钮