Another noob config endif question

Hi,
trying to figure out what#s wrong here as my Battery sensor show negative values for charging

      state:>
      {{% set battery_power = states('PV_Batterie_ksem') | float %}}
      {% if battery_power > 0 %}
      {((battery_power )) | round (2)}
      {% else %} 0
      {% endif %}

any idea?

there are some extra brackets and spaces in there. Try this:

state: >
  {% set battery_power = states('PV_Batterie_ksem') |float %}
  {% if battery_power > 0 %}
    {{ battery_power |round(2) }}
  {% else %} 0
  {% endif %}

note:

  • line 1: {% and %}
  • line 3: double brackets {{ and }} around the whole thing
  • line 3: (( and )) not necessary around battery_power
  • line 3: no spaces between round and (2)

perfect, working. thanks

I made some changes after posting so perhaps double check.