Need a little help getting Arduino code into ESP Home

So I am reading from ADC and I need to convert this into a liquid level. I have this working in C++ but trying to work out in ESP.

#dataVoltage = analogRead(ANALOG_PIN)/ 1024.0 * VREF;

##dataCurrent = dataVoltage / 120.0; //Sense Resistor:120ohm

#depth = (dataCurrent - CURRENT_INIT) * (RANGE/ DENSITY_WATER / 16.0); //Calculate depth from current readings

#define ANALOG_PIN A2

#define RANGE 5000 // Depth measuring range 5000mm (for water)

#define VREF 5000 // ADC's reference voltage on your Arduino,typical value:5000mV

#define CURRENT_INIT 4.00 // Current @ 0mm (uint: mA)

#define DENSITY_WATER 1 // Pure water density normalized to 1
#define DENSITY_GASOLINE 0.74 // Gasoline density
#define PRINT_INTERVAL 1000

I beleive i have to use filter, and lambda but im struggling with below

lambda: return x / 120 - 4 * (5000 / 0.74 / 16.0) ;

Can anyone help an old dog out :slight_smile:

More info needed. What is your existing yaml code, and what problem are your experiencing?

Here is my current YMAL

sensor:
  - platform: adc
    pin: A0
    name: "ADC-IN"
    update_interval: 5s
    filters: 
      
   #  - lambda: return x * (9.0/5.0) + 32.0;
   #   - lambda: return x / 120 - 4 * (5000 / 0.74 / 16.0) ;

The output is a totally different value to when I run the C++ code on my Adunio :slight_smile:

I think you need brackets around x/120-4