ESPHome lambda thermistor

Here it goes in all it’s glory! But still doesn’t work properly wrong values

sensor:
  - platform: adc
    pin: GPIO32
    name: "Probe 1 Temp"
    id: probe1_temp
    update_interval: 2s
    # filters:
    #   - lambda: |-
    #       return ( 1 / (0.001129148  + (0.000234125 * std::log(x)) + (8.76741*10e-8 * (std::log(x))^3))) - 273.15;
    unit_of_measurement: "°F"
    accuracy_decimals: 0
    icon: mdi:thermometer
    filters:
      - lambda: !lambda >-
            float analog = x;
            float R1 = 10000 * (1023.0 / analog - 1.0);
            float steinhart;
            steinhart = 0.2476197866e-03;                      
            steinhart += 2.943226015e-04 * log(R1);                   
            steinhart += -2.129189836e-07 * log(R1) * log(R1)* log(R1);
            steinhart = 1.0 / steinhart;
            steinhart -= 273.15;
            steinhart = (steinhart * 9.0) / 5.0 + 32.0;
            return steinhart;

As I understand this is all c++ like arduino code but I dont understand how to get the sensors raw value into the equation is th “x” all I need like above?

I also tried that one line but it spits back an error.

Thanks

Hard to tell without the error!

Ok I ended up using this:

- platform: adc
    pin: GPIO33
    name: "Probe 2 Temp"
    id: probe2_temp
    update_interval: 5s
    unit_of_measurement: "°F"
    accuracy_decimals: 0
    icon: mdi:thermometer
    filters:
      - lambda: |-
          static double uMax = 1.0;
          static double tStatic = 25 + 273.15;
          static double beta = 4090;
          static double rStatic = 10000;
          double rThermistor = rStatic * (uMax / x - 1);
          double tKelvin = 1.0 / ( (1.0/tStatic) + (1.0/beta)*log(rThermistor/rStatic) );
          tKelvin -= 273.15;
          tKelvin = (tKelvin * 9.0) / 5.0 + 32.0;
          return tKelvin;

Works like a charm!
I was just at wits end trying to get it figured out. :wink: Now even got a nifty thermostat inside of ESPHome so now have a self contained BBQ/Smoker controller!

how do you have it wired?

pretty basic like this.
https://bildr.org/2012/11/thermistor-arduino/

Ok more like this