Set up a calculated value as sensor

Hi. I have several sensors reporting to home assistant.
Now i like to do some math and present the result.
I can get it work under Developer tool -template. with the code bellow

Then i belive i have to add this to configuration.yaml, but i cant get it woring in this file, i get errors , so i beliw i dont have the right syntax.

The variable cop hold my result and i would like to displayit, the pwg (power generated) i also of interst to display and summaraze

{% set t1 = states('sensor.temperature_radiator_retur') | float %}
{% set t2 = states('sensor.temperature_radiator_ut') | float %}
{% set f = states('sensor.water_flow') | float %}
{% set pw = states('sensor.current_power') | float %}
{% set pwg = ((t1 - t2)*f)*0.06 | float %}
{% set cop = pwg / pw | float %}

{{ t1  }}                   water temp out from heatpump
{{ t2  }}                   water temp in to heatpump
{{ pw }}                   kW incoming power
{{ pwg }}     kW power generated from heatpump
{{ t1 - t2 }}                    temperatur increase in heatpump
{{ f  }}                  l/m flow of water trew the heatpump
{{ pwg / pw }}     effecency  COP
{{ cop  }} 

You may need a template sensor. See here

You can define them in a file and then have that file included in your configuration.yaml