Template in action... Missed comma?

Hello all,

I got this action in an automation :

  - metadata: {}
    data:
      pos: 1
      topic: awtrix_903604/custom/Mppt Power
      text: "{{ ((states('sensor.awtrix_mppt_power')|float(0))/1000)|round(2) }}"
      icon: "49139"
      color: FFFFFF
      progress: "{{ states('sensor.bmv_soc')|int(0) }}"
      progressc: >
      {% set Progress = states('sensor.bmv_soc')|int(0) %}
      {% if Progress < 25 %}
        FF0000
      {% elif Progress < 50 %}
        FFA500
      {% elif Progress < 75 %}
        E4FF7F
      {% else %}
        00FF00
      {% endif %}
    action: script.Awtrix_Publish_Power
    enabled: true

Still generate a “Error in parsing YAML: missed comma between flow collection entries (line: 29, column: 8)” error … i can’t see why …!
I’m in an Automation and want the color to be selefted depending on the state of charge value.
This will be passed to a script for display to an Awtrix screen.

If i remove the whole “{% set … endif %}”, error disepear.
The line 29 is the “{% set …” line

Right now we cannot see what is up with the code as the forum already changed it since you did not use code tags.
Plz edit the post to use code tags (paste in the code again with code tags)

One issue is that elseif is not supported, Jinja uses elif… though that may not be the cause of the error.

Also, States are always strings. So your if/elif statements will fail since they are essentially asking “Is this string greater than that integer?” That question is nonsense as far as the template engine is concerned, so it will throw a different error. You need to use the int filter where you are setting the value of the variable Progress.

… which is why it is wise to test templates in developer tools before putting them where they are needed.

Sorry, i’ve update the post with code tags

This is not a syntax problem, it seems that templates are not acepted here …

It is a formatting error. You need to indent your multiline template:

      progressc: >
        {% set Progress = states('sensor.bmv_soc')|int(0) %}
        {% if Progress < 25 %}
          FF0000
        {% elif Progress < 50 %}
          FFA500
        {% elif Progress < 75 %}
          E4FF7F
        {% else %}
          00FF00
        {% endif %}
1 Like

The hell … just for that, i though i tried many indentation wnd still your is obviously the right one …
And the error is gone !!!
Well … i feel stupid to have wasted your time for a so simple problem…
Thanks a lot … !