Change negative template output to positive

Hello,

I’m starting to get in to ESP Home, and a lot of questions are answered bij using search engines but this is something I can’t find on the internet.
In our floor heating Ive made two dallas sensors wich measure the ingoing and outgoing temperature of the water. In summer time we use it as floor cooling and in winter as heating.
I want to compare these two values as a DeltaT so i made a substraction from the two values. This can turn out negative if cooling. How to adjust the code that when it turn out negative it will be changed to positive, but when it is positive it will remain positive?
Thanks for helping out in advance

The code I have for so far:
sensor:

sensor:
  - platform: dallas
    address: 0x413ce1e3809a9628
    id: aanvoer
    name: "Temperatuur Aanvoer" 
  - platform: dallas 
    address: 0x853ce10457c0cd28
    id: retour
    name: "Temperatuur Retour" 
  - platform: template
    id: temperatuurverschil
    name: "Temperatuur Verschil"
    unit_of_measurement: °C
    update_interval: 15s
    lambda: 'return id(aanvoer).state - id(retour).state;'

You want the “absolute value”. There’s no native filter so you can extend your lambda.

I think it might be like this from memory.

abs(id(aanvoer).state - id(retour).state);

Thanks a lot! It does exactly what I needed!
The final code now is:

sensor:
  - platform: dallas
    address: 0x413ce1e3809a9628
    id: aanvoer
    name: "Temperatuur Aanvoer" 
  - platform: dallas 
    address: 0x853ce10457c0cd28
    id: retour
    name: "Temperatuur Retour" 
  - platform: template
    id: temperatuurverschil
    name: "Temperatuur Verschil"
    unit_of_measurement: °C
    update_interval: 15s
    lambda: 'return abs(id(aanvoer).state - id(retour).state);'
1 Like