Struggeling with Template Float in an If-Then-Else-Phrase

Hi,
what am i doing wrong here. My sensor “strom_zaehlerstand_kwh_total” shows the complete used power consumption. Its also a energy_class with a “total_inceasing” state_class. But sometimes i got wrong values, that are lower then the time before. To filter these values for my energy dashboard i createt an extra sensor “stromzaehler_total_test”.
This sensor should only store values from my powermeter_sensor “strom_zaehlerstand_kwh_total” that are greater like the time before. For the case, that the “strom_zaehlerstand_kwh_total” is lower then before, just use the same value, stored in “stromzaehler_total_test” from the time before.

    stromzaehler_total_test:
        value_template:  >
           {% if float(states('sensor.strom_zaehlerstand_kwh_total'))  | round(3) >= float(states('sensor.stromzaehler_total_test')) | round(3) %} 
            {{ float(states('sensor.strom_zaehlerstand_kwh_total')) | round(3) }}
            {% else %}
            {{ float(states('sensor.stromzaehler_total_test')) | round(3) }}
            {% endif %}                            
        unique_id: "stromzaehler_total_test"
        unit_of_measurement: 'kWh'
        device_class: "energy"
        attribute_templates:
            state_class: total_increasing

But my sensor stromzaehler_total_test is always unavailable. It seems that the
float(states(‘sensor.stromzaehler_total_test’)) | round(3)
in my first IF clause is not correct. When i use a fix value instead, the whole if-then-else clause works as expected. Some suggenstions ?

Regards Vala

Remove both float( and its corresponding )

Instead, use |float() at the end. You need to put the default result in the brackets as well. I am currently in a phone so cannot copy/paste and edit your code, but will try when I am back at my PC later.

thanks jchh i will try this that way you showed me

stromzaehler_total_test:
        value_template:  >
            {% set total = states('sensor.strom_zaehlerstand_kwh_total') |float() |round(3) %}
            {% set test = states('sensor.stromzaehler_total_test') |float(0) |round(3) %}
            {% if total >= test %} {{ total }}
            {% else %} {{ test }}
            {% endif %}

Now i only have to wait, until these errors occure, to see if it really works like i want to. Thanks so far