ESPHome and INA219 current sensor seems off by factor of 100

I have connected an INA219 breakout board to a D1 Mini so that the INA219 is measuring only the 5v current into the D1 Mini. I loaded a minimal ESPHome configuration, using the example in the ESPHome doc for the INA219.

When running, I measure across the shunt with a DVM and get 7mV. And the device also reports the same:

'INA219 Shunt Voltage': Sending state 0.00710 V with 3 decimals of accuracy

I believe that the board’s shunt resistor is 0.1 ohm, because a) it has marking ‘R100’, which matches the marking on the board from Adafruit they say theirs is 0.1 ohm, and b) an ‘R10’ chip is supposed to 0.1 ohms so I think R100 is also.

With those numbers, I calculate the current at 0.007v / 0.1 ohm = 0.070 A or 70 mA, which I can accept since I’ve heard that the D1 Mini draws less than 120 mA.

Ok, but, ESPHome reports the current is 0.0007A:

'INA219 Current': Sending state 0.00069 A with 3 decimals of accuracy

So I changed the value of the shunt_resistance: 0.001 ohm

And now it reports the expected current:

'INA219 Current': Sending state 0.07174 A with 3 decimals of accuracy

What is up?

Here is the relevant part of my config:

sensor:
  # the INA219 current sensor
  - platform: ina219
    address: 0x40
    # the board's shunt is 0.1 ohms but I set to 0.001 ohms so the current comes out right
    shunt_resistance: 0.001 ohm
    current:
      name: "INA219 Current"
      accuracy_decimals: 3
    power:
      name: "INA219 Power"
    bus_voltage:
      name: "INA219 Bus Voltage"
    shunt_voltage:
      name: "INA219 Shunt Voltage"
      accuracy_decimals: 3
    max_voltage: 32.0V
    max_current: 3.2A
    update_interval: 10s  

Thanks in advance,
Kent

Your calculations look right to me, as well as the interpretaion of R100.

The only thing I note is you have this set to 32V

max_voltage ( Optional , float): The maximum bus voltage you are expecting. ESPHome will use this to configure the sensor optimally. Defaults to 32V (the max)

Try setting it closer to your expected values, I am not sure what “ESPHome will use this to configure the sensor optimally” means, but worth a try? Same with max_current

I found an ESPHome issue which matches my symptoms:

The issue was CLOSED because it has a workaround: add a filter that multiplies the answer by 100. I may not agree that a workaround can close an issue, but this isn’t my rodeo. I’ve suggested a change to the documentation.

On to the next challenge!

2 Likes

Hy …please can you help me. i have a D1mini and INA219 with esphome config;

esphome:
name: ina219
platform: ESP8266
board: d1_mini

i2c:
sda: D2
scl: D1
scan: True

sensor:

the INA219 current sensor

  • platform: ina219
    address: 0x40

    the board’s shunt is 0.1 ohms but I set to 0.001 ohms so the current comes out right

    shunt_resistance: 0.001 ohm
    current:
    name: “INA219 Current”
    accuracy_decimals: 3
    filters:
    - multiply: 100
    power:
    name: “INA219 Power”
    accuracy_decimals: 3
    filters:
    - multiply: 100
    bus_voltage:
    name: “INA219 Bus Voltage”
    accuracy_decimals: 3
    shunt_voltage:
    name: “INA219 Shunt Voltage”
    accuracy_decimals: 3
    max_voltage: 32.0V
    max_current: 3.2A
    update_interval: 10s

but i HAVE THIS error:

[14:01:34][C][i2c:028]: I2C Bus:
[14:01:34][C][i2c:029]: SDA Pin: GPIO4
[14:01:34][C][i2c:030]: SCL Pin: GPIO5
[14:01:34][C][i2c:031]: Frequency: 50000 Hz
[14:01:34][I][i2c:033]: Scanning i2c bus for active devices…
[14:01:34][I][i2c:049]: Found no i2c devices!
[14:01:34][C][logger:185]: Logger:
[14:01:34][C][logger:186]: Level: DEBUG
[14:01:34][C][logger:187]: Log Baud Rate: 115200
[14:01:34][C][logger:188]: Hardware UART: UART0
[14:01:34][C][ina219:132]: INA219:
[14:01:34][C][ina219:133]: Address: 0x40
[14:01:34][E][ina219:136]: Communication with INA219 failed!
[14:01:34][C][ota:029]: Over-The-Air Updates:

You definitely have a hardware problem because i2c scanning works reliably and you should even be able to raise bus frequency to 400kHz imo. Maybe try attaching any other i2c device you have to the bus.
BR, Tom

Hello. I went through problems similar to this one. When we have weird readings like these, it’s because of the lack of reference GND between the ESP and the negative of the load to be measured.

Would you please share your diagram? Thanks,