Calibration of a NTC Sensor for water temperature

Hello everyone,
this is my first experience with ESPHome so please be patience with me :slight_smile:

I bought this combined sensor which allows me to read the water flow with Hall effect, which has also a temperature probe to measure the temperature of the water

As board I’m using this ESP32 (version: ESP-32-CP2102):
https://it.aliexpress.com/item/1005005396344075.html
because I read that for ADC reading, ESP8266 is not very reliable

This is the probe:
https://it.aliexpress.com/item/1005004651835855.html

My understanding is that I need to use a NTC sensor which read a resistance value and convert it to a °C temperature: NTC Sensor — ESPHome

Following this I created the circuit with the resistance:

From the item description, I found the specifications of the probe

Terminal 5  Temp. Sensor
(13) Connector:  Housing XH2.5-3P
TEMPERATURE VS RESISTANCE TABLE
Resistance         50k Ohms at 25deg. C
B Value            3950K at 25/50 deg. C
Temp. Range:-40-+150℃

This is the circuit I made so far:

And this is the yaml code I uploaded:

  - platform: adc
    id: source_sensor
    pin: GPIO34
    name: "ADC Temperature"
    attenuation: auto
    update_interval: never

  - platform: resistance
    id: resistance_sensor
    sensor: source_sensor
    configuration: DOWNSTREAM
    resistor: 50.9kOhm
    name: Resistance Sensor
    reference_voltage: 3.3V

  - platform: ntc
    sensor: resistance_sensor
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 50kOhm
    name: Water Temperature

switch:
  - platform: gpio
    pin: GPIO32
    id: ntc_vcc

interval: 
  - interval: 60s
    then:
      - switch.turn_on: ntc_vcc
      - delay: 1s
      - component.update: source_sensor
      - delay: 1s
      - component.update: source_sensor
      - delay: 1s
      - component.update: source_sensor
      - delay: 1s
      - switch.turn_off: ntc_vcc

While the code is working, the values that are given are too much apart for the same reading, check this example:

[08:53:20][D][switch:012]: 'ntc_vcc' Turning ON.
[08:53:20][D][switch:055]: 'ntc_vcc': Sending state ON
[08:53:21][D][sensor:094]: 'ADC Temperature': Sending state 1.81772 V with 2 decimals of accuracy
[08:53:21][D][resistance:039]: 'Resistance Sensor' - Resistance 62418.5Ω
[08:53:21][D][sensor:094]: 'Resistance Sensor': Sending state 62418.45703 Ω with 1 decimals of accuracy
[08:53:21][D][ntc:026]: 'Water Temperature' - Temperature: 20.1°C
[08:53:21][D][sensor:094]: 'Water Temperature': Sending state 20.08983 °C with 1 decimals of accuracy
[08:53:22][D][sensor:094]: 'ADC Temperature': Sending state 1.82594 V with 2 decimals of accuracy
[08:53:22][D][resistance:039]: 'Resistance Sensor' - Resistance 63051.0Ω
[08:53:22][D][sensor:094]: 'Resistance Sensor': Sending state 63050.96484 Ω with 1 decimals of accuracy
[08:53:22][D][ntc:026]: 'Water Temperature' - Temperature: 19.9°C
[08:53:22][D][sensor:094]: 'Water Temperature': Sending state 19.87050 °C with 1 decimals of accuracy
[08:53:23][D][sensor:094]: 'ADC Temperature': Sending state 1.74221 V with 2 decimals of accuracy
[08:53:23][D][resistance:039]: 'Resistance Sensor' - Resistance 56925.9Ω
[08:53:23][D][sensor:094]: 'Resistance Sensor': Sending state 56925.94141 Ω with 1 decimals of accuracy
[08:53:23][D][ntc:026]: 'Water Temperature' - Temperature: 22.1°C
[08:53:23][D][sensor:094]: 'Water Temperature': Sending state 22.10882 °C with 1 decimals of accuracy
[08:53:24][D][switch:016]: 'ntc_vcc' Turning OFF.
[08:53:24][D][switch:055]: 'ntc_vcc': Sending state OFF

3 readings with 1 seconds apart and I’m getting 20° and 22°
(and the actual room temperature, given by 2 other devices, is 18.4).

How can I get a reliable value when every reading has a span of 1-2° apart?
I have multiple example of reading, some times the first value is higher than the last one.

Thank you

Hello,
I did some additional reading but while some of the values are actually as expected (19.3/19.4) some reading are too much of out expected range

[10:21:17][D][switch:012]: 'ntc_vcc' Turning ON.
[10:21:17][D][switch:055]: 'ntc_vcc': Sending state ON
[10:21:18][D][sensor:094]: 'ADC Temperature': Sending state 1.76770 V with 2 decimals of accuracy
[10:21:18][D][resistance:039]: 'Resistance Sensor' - Resistance 58719.3Ω
[10:21:18][D][sensor:094]: 'Resistance Sensor': Sending state 58719.28906 Ω with 1 decimals of accuracy
[10:21:18][D][ntc:026]: 'Water Temperature' - Temperature: 21.4°C
[10:21:18][D][sensor:094]: 'Water Temperature': Sending state 21.42585 °C with 1 decimals of accuracy
[10:21:19][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:21:19][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:21:27][D][switch:012]: 'ntc_vcc' Turning ON.
[10:21:27][D][switch:055]: 'ntc_vcc': Sending state ON
[10:21:28][D][sensor:094]: 'ADC Temperature': Sending state 1.77545 V with 2 decimals of accuracy
[10:21:28][D][resistance:039]: 'Resistance Sensor' - Resistance 59276.4Ω
[10:21:28][D][sensor:094]: 'Resistance Sensor': Sending state 59276.44922 Ω with 1 decimals of accuracy
[10:21:28][D][ntc:026]: 'Water Temperature' - Temperature: 21.2°C
[10:21:28][D][sensor:094]: 'Water Temperature': Sending state 21.21853 °C with 1 decimals of accuracy
[10:21:29][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:21:29][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:21:37][D][switch:012]: 'ntc_vcc' Turning ON.
[10:21:37][D][switch:055]: 'ntc_vcc': Sending state ON
[10:21:38][D][sensor:094]: 'ADC Temperature': Sending state 1.84504 V with 2 decimals of accuracy
[10:21:38][D][resistance:039]: 'Resistance Sensor' - Resistance 64546.8Ω
[10:21:38][D][sensor:094]: 'Resistance Sensor': Sending state 64546.80078 Ω with 1 decimals of accuracy
[10:21:38][D][ntc:026]: 'Water Temperature' - Temperature: 19.4°C
[10:21:38][D][sensor:094]: 'Water Temperature': Sending state 19.36172 °C with 1 decimals of accuracy
[10:21:39][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:21:39][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:21:47][D][switch:012]: 'ntc_vcc' Turning ON.
[10:21:47][D][switch:055]: 'ntc_vcc': Sending state ON
[10:21:48][D][sensor:094]: 'ADC Temperature': Sending state 1.76324 V with 2 decimals of accuracy
[10:21:48][D][resistance:039]: 'Resistance Sensor' - Resistance 58401.3Ω
[10:21:48][D][sensor:094]: 'Resistance Sensor': Sending state 58401.30078 Ω with 1 decimals of accuracy
[10:21:48][D][ntc:026]: 'Water Temperature' - Temperature: 21.5°C
[10:21:48][D][sensor:094]: 'Water Temperature': Sending state 21.54519 °C with 1 decimals of accuracy
[10:21:49][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:21:49][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:21:57][D][switch:012]: 'ntc_vcc' Turning ON.
[10:21:57][D][switch:055]: 'ntc_vcc': Sending state ON
[10:21:58][D][sensor:094]: 'ADC Temperature': Sending state 1.84419 V with 2 decimals of accuracy
[10:21:58][D][resistance:039]: 'Resistance Sensor' - Resistance 64479.1Ω
[10:21:58][D][sensor:094]: 'Resistance Sensor': Sending state 64479.10938 Ω with 1 decimals of accuracy
[10:21:58][D][ntc:026]: 'Water Temperature' - Temperature: 19.4°C
[10:21:58][D][sensor:094]: 'Water Temperature': Sending state 19.38445 °C with 1 decimals of accuracy
[10:21:59][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:21:59][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:22:07][D][switch:012]: 'ntc_vcc' Turning ON.
[10:22:07][D][switch:055]: 'ntc_vcc': Sending state ON
[10:22:08][D][sensor:094]: 'ADC Temperature': Sending state 1.85082 V with 2 decimals of accuracy
[10:22:08][D][resistance:039]: 'Resistance Sensor' - Resistance 65007.3Ω
[10:22:08][D][sensor:094]: 'Resistance Sensor': Sending state 65007.28906 Ω with 1 decimals of accuracy
[10:22:08][D][ntc:026]: 'Water Temperature' - Temperature: 19.2°C
[10:22:08][D][sensor:094]: 'Water Temperature': Sending state 19.20781 °C with 1 decimals of accuracy
[10:22:09][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:22:09][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:22:17][D][switch:012]: 'ntc_vcc' Turning ON.
[10:22:17][D][switch:055]: 'ntc_vcc': Sending state ON
[10:22:18][D][sensor:094]: 'ADC Temperature': Sending state 1.78058 V with 2 decimals of accuracy
[10:22:18][D][resistance:039]: 'Resistance Sensor' - Resistance 59648.7Ω
[10:22:18][D][sensor:094]: 'Resistance Sensor': Sending state 59648.71484 Ω with 1 decimals of accuracy
[10:22:18][D][ntc:026]: 'Water Temperature' - Temperature: 21.1°C
[10:22:18][D][sensor:094]: 'Water Temperature': Sending state 21.08125 °C with 1 decimals of accuracy
[10:22:19][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:22:19][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:22:26][D][switch:012]: 'ntc_vcc' Turning ON.
[10:22:27][D][switch:055]: 'ntc_vcc': Sending state ON
[10:22:28][D][sensor:094]: 'ADC Temperature': Sending state 1.76184 V with 2 decimals of accuracy
[10:22:28][D][resistance:039]: 'Resistance Sensor' - Resistance 58301.8Ω
[10:22:28][D][sensor:094]: 'Resistance Sensor': Sending state 58301.77734 Ω with 1 decimals of accuracy
[10:22:28][D][ntc:026]: 'Water Temperature' - Temperature: 21.6°C
[10:22:28][D][sensor:094]: 'Water Temperature': Sending state 21.58269 °C with 1 decimals of accuracy
[10:22:29][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:22:29][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:22:37][D][switch:012]: 'ntc_vcc' Turning ON.
[10:22:37][D][switch:055]: 'ntc_vcc': Sending state ON
[10:22:38][D][sensor:094]: 'ADC Temperature': Sending state 1.87498 V with 2 decimals of accuracy
[10:22:38][D][resistance:039]: 'Resistance Sensor' - Resistance 66971.8Ω
[10:22:38][D][sensor:094]: 'Resistance Sensor': Sending state 66971.76562 Ω with 1 decimals of accuracy
[10:22:38][D][ntc:026]: 'Water Temperature' - Temperature: 18.6°C
[10:22:38][D][sensor:094]: 'Water Temperature': Sending state 18.56500 °C with 1 decimals of accuracy
[10:22:39][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:22:39][D][switch:055]: 'ntc_vcc': Sending state OFF
[10:22:46][D][switch:012]: 'ntc_vcc' Turning ON.
[10:22:47][D][switch:055]: 'ntc_vcc': Sending state ON
[10:22:48][D][sensor:094]: 'ADC Temperature': Sending state 1.86431 V with 2 decimals of accuracy
[10:22:48][D][resistance:039]: 'Resistance Sensor' - Resistance 66096.1Ω
[10:22:48][D][sensor:094]: 'Resistance Sensor': Sending state 66096.14844 Ω with 1 decimals of accuracy
[10:22:48][D][ntc:026]: 'Water Temperature' - Temperature: 18.8°C
[10:22:48][D][sensor:094]: 'Water Temperature': Sending state 18.84881 °C with 1 decimals of accuracy
[10:22:49][D][switch:016]: 'ntc_vcc' Turning OFF.
[10:22:49][D][switch:055]: 'ntc_vcc': Sending state OFF

How can I get a reliable value when a lot of reading need to be discarded?

  - interval: 5s  
    then:
      - switch.turn_on: ntc_vcc
      - component.update: source_sensor
      - switch.turn_off: ntc_vcc    

I use this interval and seems good