Template sensor not recognize it as an integer in automations

Hi,
I have a similary issue and tried to follow these steps, but no luck.

I want to use the sensor possible_charging_phases as an integer input for an automation, but it seems like it dosent recognize it as an integer

This is from the trace log for the automation

this is a snippet of the action sequence. Is it possible to cast this to an integer?

- conditions:
  - condition: template
    value_template: '{{states(''sensor.possible_charging_phases'') | int == 1}}'
  sequence:
  - service: easee.set_circuit_dynamic_limit
    data:
      currentP1: 0
      currentP2: 0
      currentP3: sensor.possible_charging_power
      time_to_live: 0
      device_id: e58dfa2f3706cf4b5df0fca52ca75825

and finally the sensor

template:
- sensor  
  - name: "Possible Charging Power"
    unique_id: "possibleChargingPower"
    state: >
      {% set currentSpareProduction = states('sensor.current_spare_production') | float %}

      {% if currentSpareProduction > 4200 -%} 
        {{ (min(max((currentSpareProduction / (400 * 1.73)) | round(0, default=0),6),16)) | int}}
      {% elif currentSpareProduction > 1000 -%}
        {{ (min(max((currentSpareProduction / (240 * 1)) | round(0, default=0),6),16)) | int}}
      {%- else -%}
        0
      {%- endif %}

Can anyone help?

Thanks

  sequence:
  - service: easee.set_circuit_dynamic_limit
    data:
      currentP1: 0
      currentP2: 0
      currentP3: "{{ states('sensor.possible_charging_power')|int(0) }}"
      time_to_live: 0
      device_id: e58dfa2f3706cf4b5df0fca52ca75825

Thanks Tom, that worked nicely. What indicate the (0)

That is the default value that will be used if the state can not be converted into an integer. You should nearly always supply a default value to prevent errors.