Difference of Sensor Values

I am a real disaster at templating.

I need to determine the difference between two sensor values for one of my automations:

I tried with the following but it doesn’t work :

{{states('sensor.sensor1') - states('sensor.sensor2')}}

I get the following error in the Developer Tools

TypeError: unsupported operand type(s) for -: 'str' and 'str'

Any help would be appreciated.
Do you know of a good tutorial for newbie to learn templalting?

States returns a string, so you need to convert it to an integer/float first. Try this:

{{ states('sensor.sensor1') | float - states('sensor.sensor2') | float }}
1 Like

Understood.
Great! you made my day, thanks.