Sonoff/Tasmota with INA219 Voltage sensor

Hi there,
I am quite a newbie, and I was trying to figure out how to build a low DC voltage sensor using a Sonoff device and an INA219, that should be supported by Tasmota firmware, as I see in the wiki.
Unfortunately it’s not written how to do that, or at least I wasn’t able to find it in the documentation.
I could also connect the INA219 to the Raspberry PI and read the voltage directly, if it were possible to do that. In that case I would save to use a Sonoff device
What I am trying to do is to send to HASS the voltage of a 12V car battery.
Is there anybody who can help me?

Thank you!

1 Like

Nobody there?

completed…
as above… enable I2c in tasmota user.h file before you re-compile and program to your sonoff.
connect the INA219 pins to the respective I2C pins set on the Sonoff

login to the sonoff console and select the GPIO for SCL and SCA, save and exit

in your “switch” section, find the sonoff with the INA219 attached and get the state topic name: for this example i used .

In your home assistant config add the following…

  • platform: mqtt
    name: “Voltage”
    state_topic: “tele//SENSOR”
    value_template: “{{ value_json[‘INA210’].Voltage }}”
    unit_of_measurement: “Volts”

save config and restart.
Enjoy…

Currently from what I have, there appears to be some “rounding” going on. I am monitoring a leisure battery and it will report 10,11,12,13 or 14 volts. I would like to display 12.6 or 11.9 etc. I dont know at this point if this is rounding on the Sonoff or HA at this point…

EDITED… completed…
as above… enable I2c in tasmota user.h file before you re-compile and program to your sonoff.
connect the INA219 pins to the respective I2C pins set on the Sonoff

login to the sonoff console and select the GPIO for SCL and SCA, save and exit

in your “switch” section, find the sonoff with the INA219 attached and get the state topic name: for this example i used “yoursonoffname”.

In your home assistant config add the following…

  • platform: mqtt
    name: “Voltage”
    state_topic: “tele/yoursonoffname/SENSOR”
    value_template: “{{ value_json[‘INA219’].Voltage }}”
    unit_of_measurement: “Volts”

save config and restart.
Enjoy…

Currently from what I have, there appears to be some “rounding” going on. I am monitoring a leisure battery and it will report 10,11,12,13 or 14 volts. I would like to display 12.6 or 11.9 etc. I don’t know at this point if this is rounding on the Sonoff or HA at this point…

1 Like

Hi,
to overcome the issue of the rounding in the voltage readings, you have to send the command:
VoltRes 2 (for 2 decimals) or VoltRes 3 (for 3 decimals)

Bye

Hi Robert,

I’m looking at doing the same thing with a solar setup I’ve created. Very new to learning how to flash firmware. What specific sonoff device did you use to connect the ina219 via i2c? Anything else you learned from this process?

Thanks!

I would recommend using a devolopment board like the nodeMCU or the Wemos D1 mini for this purpose as you dont need the relay or anything that is in the sonoff just something that connects your sensor to home assistant.
For flashing you should check out the tasmota wiki. They created a program called Tasmotizer which makes flashing really easy.
Connecting an I2C device requires finding the SCL and SDA pins of the device you are using. You can check this out in the manuel of the chip that your device is using. For example the D1 mini uses D1 and D2 for SDA and SCL, the sonoff basic R2 uses GPIO2 and GPIO14 for SDA and SCL.
To connect the I2c sensor you will also have to connect power (Usually 3V3 or 5V) and ground.

Having this issue as well, want to read 12v battery, Testing using 12v ac to dc power connected to fan. v- comes from power supply and v+ goes to fan. negative is connected direct. I have i2c setup. Currently showing 1v, .063a, 0 w. Even though i have 12v .1 amp fan on it