Help with errors in script

Please see my script here
script

This is generating the following errors

Error evaluating 'template' trigger for 'Tado Landing Offset': UndefinedError: 'offset' is undefined

and

Error while processing template: Template("{% if offset|float >= 2 or offset|float <= -2 %}true{% endif %}")

I suspect this is a syntax error with line 29, but I’ve been playing with it for a while and can’t seem to get it right.

  offset: {% if ((state_attr(target_tado, 'temperature')) | float) - actual_temp > 1 %}{{raw_offset * 2 | round}}{% else %}{{raw_offset | round}}{% endif %}

Any hints