Template in automations

Trying to add an automation that sets the required charge needed to Octopus Intelligent. However it seems I can’t run the template in the service call to number.set_value the way I though I could…

This should set the Octopus required value to the max value needed - State of charge of the car with a minimum value of 10% and a max of 80%

service: number.set_value
target:
  entity_id: number.octopus_energy_a_533ea5d2_intelligent_charge_limit
data:
  value: >
  {% set maxVal = 80 %} 
  {% set state = maxVal - states('sensor.enyaq_battery_level') | int %} 
  {{ min(maxVal, max(state,10)) }}

Just get an error of

Message malformed: must contain at least one of below, above.

I don’t think that error is referenceing the config you posted.

It was the error, however the actual problem was indentation! doh!

service: number.set_value
target:
  entity_id: number.octopus_energy_a_533ea5d2_intelligent_charge_limit
data:
  value: > 
    {% set maxVal = 80 %}
    {% set state = maxVal - states('sensor.enyaq_battery_level') | int %} 
    {{ min(maxVal, max(state,10)) }}