Invalid config for [switch.template] using template entity_id

I’m trying to use an entity id based on input_select state.
Here is my template_switch :

bedroom_ac_by_input:
    friendly_name: AC By input
    value_template: "{{ is_state('switch.bedroom_ac_25_cool_auto_fan', 'on') }}"
    turn_on:
      service: switch.turn_on
      data_template:
        entity_id: >
            {% if is_state("input_select.bedroom_ac", "Cool - Auto fan") %}
              switch.bedroom_ac_25_cool_auto_fan
            {%-elif is_state("input_select.bedroom_ac", "Cool - Low fan") %}
              switch.bedroom_ac_25_cool_low_fan
            {%-elif is_state("input_select.bedroom_ac", "Heat - Auto fan") %}
              switch.bedroom_ac_25_heat_auto_fan
            {%-elif is_state("input_select.bedroom_ac", "Heat - Low fan" %}
              switch.bedroom_ac_25_heat_low_fan
            {%-else %}
              none
            {% endif %}
    turn_off:
      service: switch.turn_off
      data_template:
        entity_id: >
            {% if is_state("input_select.bedroom_ac", "Cool - Auto fan'" %}
              switch.bedroom_ac_25_cool_auto_fan
            {%-elif is_state("input_select.bedroom_ac", "Cool - Low fan") %}
              switch.bedroom_ac_25_cool_low_fan
            {%-elif is_state("input_select.bedroom_ac", "Heat - Auto fan") %}
              switch.bedroom_ac_25_heat_auto_fan
            {%-elif is_state("input_select.bedroom_ac", "Heat - Low fan") %}
              switch.bedroom_ac_25_heat_low_fan
            {%-else %}
              none
            {% endif %}

Here is the error :

2018-01-02 13:14:16 ERROR (MainThread) [homeassistant.config] Invalid config for [switch.template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['switches']['bedroom_ac_by_input']['turn_off'][0]['data_template']['entity_id']. Got None
invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['switches']['bedroom_ac_by_input']['turn_on'][0]['data_template']['entity_id']. Got None. 
(See ?, line ?). Please check the docs at https://home-assistant.io/components/switch.template/

I’ve compared all the characters (I hope) to the example at:


At I can’t see any difference.

You’re missing the close bracket

)

After cool auto fan in the turn off part.

@anon43302295 oh god, this yaml is the worst.
Thanks a lot !

1 Like