Trying to make an entity from a calculation

Good day,
I’m trying to plot the difference between a Hive TRV and a Netatmo room monitor to be able to trend the results for the future settings of the TRV.

I tried it in the Template Editor and it works to show a change as the TRV learns.

But no matter how I attempt to use the code to make an Entitiy the Check Configuration throws up an error.

Has anyone a method I could use to move the code out of the Template Editor ??

Use that template in a template helper or if you prefer YAML a template sensor.

That worked - Thank you very much