
Unit AMeter はリアルタイムの電流監視用の電流計です。内部には 16 ビット ADC コンバータ ADS1115 を採用しており、I2C (0x48) 経由で通信します。
ESPHome から ADS1115 の最新設定を入手してください
ESPHome の設定で I²C コンポーネントを有効にする必要があります:
# Example configuration entry for ESP32
i2c:
sda: GPIOXX
scl: GPIOXX
scan: trueここで指定する GPIO ピンは使用するホストデバイスによって異なります。例えば Atom Lite をホストとする場合:
# I2C Bus on Grove Port (HY2.0-4P)
i2c:
sda: GPIO26
scl: GPIO32Unit 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 の 2 チャネルのみを使用するため、multiplexer は最大で 3 つ使用できます: "A0_A1"、"A0_GND"、"A1_GND"。電流測定では A0_A1 のみが使用されます。Template センサーと組み合わせてカスタムデータを作成しますi2c_device:
id: eeprom
address: 0x51
sensor:
# Previous ads1115 declarations
...
- 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;EEPROM を読み取る際には、ADS1115 の gain 値に応じて、lambda 内の EEPROM_REG 読み出しアドレスを変更する必要があります:
// In lambda expression
// remember to change the 'EEPROM_REG' if you changed the 'gain'
// for an example, when 'gain' is 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 のいずれか一方のみを測定できます**。両方の入力を同時に接続しないでください。
ダッシュボードに追加すると、Home Assistant でセンサーデータを確認できます
