跳转到内容

Belling BL0940 能量监控器

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

与此组件的通信通过 UART 完成。因此,您必须在配置中包含带有 已设置 TX 和 RX 引脚以及波特率为 4800、1 个停止位的 uart: 条目。

# Example configuration entry
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 (可选, boolean): 是否使用初始实现中的旧配置。 默认为 true 以防止破坏性变更。
  • read_command (可选): 与 BL0940 通信时用于读取命令的字节。 默认情况下,设置为 0x58 或在 legacy_mode 下为 0x50。
  • write_command (可选): 与 BL0940 通信时用于写入命令的字节。 默认情况下,设置为 0xA8 或在 legacy_mode 下为 0xA0。
  • voltage (可选): 传感器的电压值,单位为伏特。来自 Sensor 的所有选项。
  • current (可选): 传感器的电流值,单位为安培。来自 Sensor 的所有选项。
  • power (可选): 传感器的(有功)功率值,单位为瓦特。来自 Sensor 的所有选项。
  • energy (可选): 使用传感器的能量值,单位为 kWh。来自 Sensor 的所有选项。
  • internal_temperature (可选): 传感器的内部温度值,单位为 °C。 来自 Sensor 的所有选项。
  • external_temperature (可选): 传感器的外部值,单位为 °C。通常未连接并给出无效 数据。来自 Sensor 的所有选项。
  • update_interval (可选): 检查传感器的时间间隔。默认为 60s。
  • reference_voltage (可选, float): Vref 的校准参数。默认为 1.218。

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

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

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

  • voltage_reference (可选, float): 电压读数的校准参数。 默认为 266013.136288998,使用模式默认值计算得出。

  • current_reference (可选, float): 电流读数的校准参数。 默认为 17158.9201389365,使用模式默认值计算得出。

  • power_reference (可选, float): 功率读数的校准参数。 默认为 713.104696500825,使用模式默认值计算得出。

  • energy_reference (可选, float): 累积能量读数的校准参数。 默认为 6120.6267056536,使用模式默认值计算得出。

有两个基本的校准参数,它们取决于硬件设计:voltage_reference 和 current_reference。

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

# schematic option defaults
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_;
// if voltage reference and current_reference have been configured
this->power_reference_ = this->voltage_reference_ * this->current_reference_ * 4046 / 324004 / 79931;
// if not, we use this formula based on provided formula in the specification
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_reference 和 current_reference 应该足以校准传感器,但 为了完整性,power_reference 和 energy_reference 也是可以配置的。

# custom references
voltage_reference: 17158.9201389365
current_reference: 266013.136288998
power_reference: 713.104696500825
energy_reference: 6120.6267056536

bl0940 number 平台允许对传感器读数进行在线校准。

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 (可选, float): 此数字的最小值。允许的最小值为 -50,默认为 -10。
  • max_value (可选, float): 此数字的最大值。允许的最大值为 50,默认为 10。
  • step (可选, float): 设置数字的粒度。默认为 0.1。
  • restore_value (可选, boolean): 将状态保存到 RTC/闪存并加载。默认为 true。
  • 来自 Number 的所有其他选项。

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

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

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

voltage_calibration 和 current_calibration 将影响 power_reference 和 energy_reference(如果尚未 手动指定)。

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

button:
- platform: bl0940
name: Reset Calibration
  • 来自 Button 的所有选项。