Using variable in an automation

H,
I would like to finetune my automation.
I want to compute my availablePower differently when the wallbox is charging in ecomode.

I tried to replace with {{ availablePower }} but it will not work and I kow Why now.

So I tried to compute new energy values to change the automation later.

My main problem is, that the result of the template is not transferred to the automation. I tried tos end it in the last step but I get an empty string.
In the template esitor it shows correct values. Whats wrong?

alias: Überschussheizen Spa
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_boolean.uberschussheizbetrieb_spa
  - trigger: time_pattern
    minutes: /5
conditions:
  - condition: state
    entity_id: input_boolean.uberschussheizbetrieb_spa
    state: "on"
    enabled: false
  - condition: state
    entity_id: binary_sensor.spa_connected
    state: "on"
    enabled: false
  - condition: state
    entity_id: switch.spa_power
    state: "on"
    enabled: false
actions:
  - variables:
      availablePower: >
        {% if is_state('select.wattpilot_charging_mode', 'Eco') and
        is_state('input_select.vorrang_uberschussverbrauch', 'Pool') %}
          {{ (states('sensor.wattpilot_charging_power') | float + states('sensor.solarnet_leistung_netzeinspeisung') | float)  }}
        {% else %}
          {{ states('sensor.solarnet_leistung_netzeinspeisung') | float }}
        {% endif %}
      horst: kevin
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: numeric_state
                    entity_id: sensor.solarnet_leistung_netzeinspeisung
                    above: 1900
                  - condition: numeric_state
                    entity_id: sensor.schalter_spa_power
                    below: 100
              - condition: and
                conditions:
                  - condition: numeric_state
                    entity_id: sensor.solarnet_leistung_netzeinspeisung
                    above: 100
                  - condition: numeric_state
                    entity_id: sensor.schalter_spa_power
                    above: 105
        sequence:
          - action: climate.turn_on
            target:
              entity_id: climate.spa_thermostat
            data: {}
      - conditions:
          - condition: state
            entity_id: climate.spa_thermostat
            state: heat
        sequence:
          - action: climate.turn_off
            target:
              entity_id: climate.spa_thermostat
            data: {}
  - action: notify.mobile_app_handy_nils
    metadata: {}
    data:
      message: Leistung "{{ availablePower }}"
mode: single

okay, first mistake:
I forgot the quotation marks:

variables:
  availablePower: >
    {% if is_state('select.wattpilot_charging_mode', 'Eco') and
    is_state('input_select.vorrang_uberschussverbrauch', 'Pool') %}
      "{{ (states('sensor.wattpilot_charging_power') | float + states('sensor.solarnet_leistung_netzeinspeisung') | float)  }}"
    {% else %}
      "{{ states('sensor.solarnet_leistung_netzeinspeisung') | float }}"
    {% endif %}

Okay,
did it like that:

alias: Überschussheizen Spa
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_boolean.uberschussheizbetrieb_spa
  - trigger: time_pattern
    minutes: /5
conditions:
  - condition: state
    entity_id: input_boolean.uberschussheizbetrieb_spa
    state: "on"
    enabled: true
  - condition: state
    entity_id: binary_sensor.spa_connected
    state: "on"
    enabled: true
  - condition: state
    entity_id: switch.spa_power
    state: "on"
    enabled: true
actions:
  - variables:
      availablePower: >
        {% if is_state('select.wattpilot_charging_mode', 'Eco') and
        is_state('input_select.vorrang_uberschussverbrauch', 'Pool') %}
          "{{ (states('sensor.wattpilot_charging_power') | float + states('sensor.solarnet_leistung_netzeinspeisung') | float)  }}"
        {% else %}
          "{{ states('sensor.solarnet_leistung_netzeinspeisung') | float }}"
        {% endif %}
      horst: kevin
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: template
                    value_template: "{{ availablePower > 1900 }}"
                  - condition: numeric_state
                    entity_id: sensor.schalter_spa_power
                    below: 100
              - condition: and
                conditions:
                  - condition: template
                    value_template: "{{ availablePower > 100 }}"
                  - condition: numeric_state
                    entity_id: sensor.schalter_spa_power
                    above: 105
        sequence:
          - action: climate.turn_on
            target:
              entity_id: climate.spa_thermostat
            data: {}
      - conditions:
          - condition: state
            entity_id: climate.spa_thermostat
            state: heat
        sequence:
          - action: climate.turn_off
            target:
              entity_id: climate.spa_thermostat
            data: {}
  - action: notify.mobile_app_handy_nils
    metadata: {}
    data:
      message: Leistung "{{ availablePower }}"
    enabled: false
mode: single

Those quotation marks shouldn’t be there… you have already used the > multi-line quote indicator.