SOLVED: Value Template Error / TemplateSyntaxError: Encountered unknown tag

hi there,
didn’t found any solution on the web after 30 Minutes of searching.

Very easy “script” :

- name: "Akkukapazität %"
    unique_id: "akkukapa_prozent"
    state_class: "measurement"
    unit_of_measurement: "%"
    state: >-
      {% set akku = states('sensor.battery_state_of_capacity') | float(2) %}      
      {% akku = akku * 15 / 100 %}
      {% akku = akku - 2.25 %}
      {% if akku <= 0 %}
        {{ 0 }}
      {% else %}
        {{ akku }}
      {% endif %}

Error:

Invalid config for [template]: invalid template (TemplateSyntaxError: Encountered unknown tag 'akku'.) for dictionary value @ data['sensor'][8]['state']. Got "{% set akku = states('sensor.battery_state_of_capacity') | float(2) %} {% akku = akku * 15 / 100 %} {% akku = akku - 2.25 %} {% if akku <= 0 %}\n {{ 0 }}\n{% else %}\n {{ akku }}\n{% endif %}". 

Please help.
regards
Daniel

You need the set instruction in lines 7 and 8 like you have in line 6.

very easy, thanks a lot

1 Like