Unit AMeter 组件通过 I2C 读取电流测量数据。
| 项目 | 信息 |
|---|---|
| 产品名称 | Unit AMeter |
| SKU | U086 |
| 主要功能 | 直流电流测量 |
| 通信接口 | I2C |
| 默认 I2C 地址 | ADS1115:0x48;EEPROM:0x51 |
| ESPHome 组件 | ads1115、template |
| ESPHome 版本要求 | / |
Unit AMeter 使用 ESPHome 官方 ADS1115 传感器读取差分电压,并结合 I2C Device 读取 EEPROM 校准参数,最后通过 Template 传感器换算电流。
Unit AMeter 配置范例:
ads1115:
- address: 0x48
sensor:
- platform: ads1115
multiplexer: "A0_A1"
gain: 0.256
sample_rate: 128
name: "Unit AMeter A0_A1 Ref"
id: diff
update_interval: 10sAIN0 和 AIN1 两个通道,所以最多可以使用 3 个 multiplexer: "A0_A1"、"A0_GND"、"A1_GND";而此处测量电流,仅用到了 A0_A1 参与电流计算。Template Sensor 创建电流实体。以下 sensor 条目应与前面的 ADS1115 条目合并到同一个列表中:i2c_device:
id: eeprom
address: 0x51
sensor:
- platform: template
name: "Input Current"
id: input_cur
unit_of_measurement: "A"
icon: "mdi:current-dc"
accuracy_decimals: 2
update_interval: 10s
lambda: |-
float d = id(diff).state;
if (isnan(d)) return NAN;
const float PRESSURE_COEFF = 0.05f;
const uint8_t EEPROM_REG = 0xF8;
uint8_t calib[8];
uint16_t hope, actual;
if ( id(eeprom).read_register(EEPROM_REG, calib, 8) != i2c::ERROR_OK ) {
ESP_LOGD("ameter.sensor", "Failed to read from EEPROM..");
return NAN;
}
uint8_t xor_result = 0x00;
for (uint8_t i = 0; i < 5; i++) {
xor_result ^= calib[i];
}
if (xor_result != calib[5]) {
return NAN;
}
hope = (calib[1] << 8) | calib[2];
actual = (calib[3] << 8) | calib[4];
float calibration_ratio = (float)hope / actual;
ESP_LOGD("ameter.sensor", "Factory calibration factor: %f", calibration_ratio);
float ain = - d / PRESSURE_COEFF;
ain = ain * calibration_ratio;
return ain;gain 值,修改 lambda 表达式中 EEPROM_REG 读取地址:// 在 lambda 表达式中
// 修改 gain 后,请同步修改 EEPROM_REG
// 例如 gain 为 0.256 时
const uint8_t EEPROM_REG = 0xF8;| ADS1115 Gain | EEPROM Data Register | Max Input Current (theory) |
|---|---|---|
| 6.144 | 0xD0 | - |
| 4.096 | 0xD8 | - |
| 2.048 | 0xE0 | - |
| 1.024 | 0xE8 | - |
| 0.512 | 0xF0 | 10 A |
| 0.256 | 0xF8 | 5 A |
推荐的 gain 值为 0.256,分辨率 0.3mA,仅能测量 AIN0 或 AIN1 其中一路,请勿将两路都接上输入。
当添加至 Dashboard 之后,您可以在 Home Assistant 中查看传感器数据。