Quick question about data_template with select_option

Why would this give me a configuration error?

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.family_lamps
      option: >
          {% if is_state("input_select.family_lamps", "Turn-on") %}
            "Motion-always"
          {% elif if is_state("input_select.family_lamps", "Motion-always") %}
            "Turn-on"
          {% endif %}

Error Message:

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'is_state') for dictionary value @ data['action'][0]['data_template']. Got None. (See /config/configuration.yaml, line 127)

Cheers, Richard

Remove the extra if, after elif:

` {% elif is_state("input_select.family_lamps", "Motion-always") %}`

Thanks. Perfect.

Hmmm. that took care of the configuration error, but I’m not getting the expected results

This works:

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.family_lamps
      option: "Motion-always"

But this doesn’t, even when input_select.family_lamps does equal “Turn-on”

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.family_lamps
      option: >
          {% if is_state("input_select.family_lamps", "Turn-on") %}
            "Motion-always"
          {% endif %}

It could be extra whitespace around the string. Maybe try this:

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.family_lamps
      option: >-
        {%- if is_state("input_select.family_lamps", "Turn-on") -%}
          "Motion-always"
        {%- endif -%}

Thanks, I think it was maybe too many leading spaces on the template. This now works

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.family_lamps
      option: >-
        {% if is_state('input_select.family_lamps', 'Turn-on') %}
          Motion-always
        {% elif not is_state('input_select.family_lamps', 'Turn-on') %}
          Turn-on
        {% endif %}