Template if then else

Gooday you all,

I have some trouble with conditional expression in a template.
There is a json result with a smartmeter rate of “1” or “2” so I tried:

    rate:
      friendly_name: 'Tarief'
      value_template: >
        {% if is_state_attr('sensor.smartmeter', 'rate', '1') %}
          dal
        {% else %}
          normaal
        {% endif %}

It gives me “normaal” whatever the json returns.
Then I tried:

   rate:
      friendly_name: 'Tarief'
      value_template: >
        {% if is_state_attr('sensor.smartmeter', 'rate', '1') %}
          dal
        {% elif is_state_attr('sensor.smartmeter', 'rate', '2') %}
          normaal
        {% endif %}

But then I have an empty result.
Can someone help me with the right syntax please?

Franklin

I think at last I found out.

        {%if state_attr('sensor.smartmeter', 'rate') == 1 %}
           dal
        {% else %}
           normaal
        {% endif %}

is giving me “dal” what it should be at this time as the json is giving me value “1”. I have a look tomorrow when the json returns a “2”.
I will keep you informed.

Today, I can confirm that the problem is solved with above solution.