Template sensor error (invalid template)

Can someone tell me what is the Problem here:

      - name: "Stromverbrauch"
        unit_of_measurement: "W"
        state: >
          {% set einspeisung = states('sensor.einspeisung_p') | float %}
          {% set bezug = states('sensor.bezug_p') | float %}
          {% set pv_aktuell = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_130') | float %}       
          {% set verbrauch = bezug + pv_aktuell - einspeisung}                
              {% if states('verbrauch') | float >= 0 }
                {{ verbrauch | round(1, default=0) }}
              {% endif %}

in the log i got:
Logger: homeassistant.config
Source: config.py:454
First occurred: 12:43:18 (3 occurrences)
Last logged: 12:48:13

* Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}') for dictionary value @ data['sensor'][1]['state']. Got "{% set einspeisung = states('sensor.einspeisung_p') | float %} {% set bezug = states('sensor.bezug_p') | float %} {% set pv_aktuell = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_130') | float %} {% set verbrauch = (bezug + pv_aktuell - einspeisung)} {% if states('verbrauch') | float >= 0 }\n {{ verbrauch | round(1, default=0) }}\n{% endif %} \n". (See /config/configuration.yaml, line 227).
* Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}') for dictionary value @ data['sensor'][1]['state']. Got "{% set einspeisung = states('sensor.einspeisung_p') | float %} {% set bezug = states('sensor.bezug_p') | float %} {% set pv_aktuell = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_130') | float %} {% set verbrauch = (bezug + pv_aktuell - einspeisung)} \n {% if states('verbrauch') | float >= 0 }\n {{ verbrauch | round(1, default=0) }}\n {% endif %} \n". (See /config/configuration.yaml, line 227).
* Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}') for dictionary value @ data['sensor'][1]['state']. Got "{% set einspeisung = states('sensor.einspeisung_p') | float %} {% set bezug = states('sensor.bezug_p') | float %} {% set pv_aktuell = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_130') | float %} {% set verbrauch = bezug + pv_aktuell - einspeisung} \n {% if states('verbrauch') | float >= 0 }\n {{ verbrauch | round(1, default=0) }}\n {% endif %} \n". (See /config/configuration.yaml, line 227).

thank you very much

{% set einspeisung = states('sensor.einspeisung_p') | float %}
{% set bezug = states('sensor.bezug_p') | float %}
{% set pv_aktuell = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_130') | float %}       
{% set verbrauch = bezug + pv_aktuell - einspeisung %}   ## missing % here
{% if states('verbrauch') | float >= 0 %} ## and here
  {{ verbrauch | round(1, default=0) }}
{% endif %}
1 Like