Calculating difference between two Temperature sensors

Hi there,
I want to calculate and show the difference between two temperature sensors.
Copied and re-worked some script exemples but it doesn’t work.
Got this after installing:

Failed config
sensor.template: [source /config/esphome/wplogger.yaml:56]
  platform: template
  name: delta_T_out_in
  unit_of_measurement: C
  
  [value_template] is an invalid option for [sensor.template]. Please check the indentation.
  value_template: |-
    {{ states(('Supply water Temperature')|float(0) - states('Retour water Temperature')|float(0))|round(1) }}

This what I worked out

# Individual temperature sensors
sensor:
  - platform: dallas
    address: 0x05092330588d5028
    name: "Retour water Temperature"
    filters:
      throttle_average: 300s
  - platform: dallas
    address: 0x9509233033081b28
    name: "Supply water Temperature"
    filters:
      throttle_average: 300s
  - platform: template
    name: "delta_T_out_in"
    unit_of_measurement: "C"
    value_template: >
      {{ states(('Supply water Temperature')|float(0) - states('Retour water Temperature')|float(0))|round(1) }}

What did I wrong?

Regards,
Harry

You’re using the legacy format for defining template sensors, which is still supported, but is no longer recommended. It looks like you might have mixed some config style from the new format and the old format.

You also need to use the entity id, not the friendly name as the argument to states()
In the legacy format, it would look like this:

# Individual temperature sensors
sensor:
  - platform: dallas
    address: 0x05092330588d5028
    name: "Retour water Temperature"
    filters:
      throttle_average: 300s
  - platform: dallas
    address: 0x9509233033081b28
    name: "Supply water Temperature"
    filters:
      throttle_average: 300s
  - platform: template
    sensors:
      delta_T_out_in:
        unit_of_measurement: "C"
        value_template: >
          {{ states(('sensor.supply_water_temperature')|float(0) - states('sensor.retour_water_temperature')|float(0))|round(1) }}

But while you’re making changes, you might as well switch to the new style for template sensors which uses template as a top level platform and would look like this:

# Individual temperature sensors
sensor:
  - platform: dallas
    address: 0x05092330588d5028
    name: "Retour water Temperature"
    filters:
      throttle_average: 300s
  - platform: dallas
    address: 0x9509233033081b28
    name: "Supply water Temperature"
    filters:
      throttle_average: 300s

template:
  - sensor:
    - name: "delta_T_out_in"
      unit_of_measurement: "C"
      state: >
        {{ states(('sensor.supply_water_temperature')|float(0) - states('sensor.retour_water_temperature')|float(0))|round(1) }}

Is this an ESPHome question or a Home Assistant question? Seems to be a lot of confusion in the question and the first response.