I have a D1 Mini running ESPHome
Connected, I have a ADS115 ADC and to that an ACS712.
This working fine and I read approx. 2.5v with no current.
The ACS712 is a bi-directional current sensor
Therefore at 0 amps it reads 2.5V
It produces 0.1V per amp up and down from 2.5V
I am really struggling to work out the way to describe the formulas to return the correct value.
The calculation is not hard but I am struggling with the syntax
I have tried this with the template editor but failed
What I am hoping to get is âcurrent 1â = the current ( like 1.2A, or -10.6A, etc )
I would appreciate some help with the syntax or if there is a better way to do this.
Here is what I have done so far
sensor:
platform: template
scan interval: 1
sensors:
current_1:
friendly_name: âcurrent 1â
value_template: >-
{% if states(âsensor.ads1115_channel_a0_gndâ)|float < 2.5 %} # for negative current
{% (2.5 - x) * (-10.0) %}
{% elif states(âsensor.ads1115_channel_a0_gndâ)|float > 2.5 %} # for positive current
{% (x - 2.5) * (10.0) %}
{% elif states(âsensor.ads1115_channel_a0_gndâ)|float == 2.5 %} # for zero current
{% (2.5 - x) * (0.0) %}
{% endif %}