Syntax error template sensor

After updating my templates, I find I’m getting an error in one of my templates. I get this error:

TemplateSyntaxError: expected token ':', got '}'

- name: Toggle Outside Lights
      state: >-
            {% if((state_attr('sun.sun', 'rising') == false and {{ state_attr('sun.sun', 'elevation') }} | float <= 6 and states('sensor.outside_luminance') | int <= 400) == true) %}
                on
            {% elif((state_attr('sun.sun', 'rising') == true and {{ state_attr('sun.sun', 'elevation') }} | float >= -12 and states('sensor.outside_luminance') | int > 0 ) == true) %}
                off
            {% else %}
                {% if states('input_boolean.outside_lights_status') == 'on' %}
                  on
                {% else %}
                  off
                {% endif %}
            {% endif %}
```

As a value_template, it worked just fine. I can’t find the problem. Any ideas appreciated. Also are there new docs on templating? What I’ve found still relates to old format.

It couldn't have... you have expressions nested inside both the if and elif statements:

Also, if you aren't going to provide defaults for the float() and int() filters you should assign an availability:

- name: Toggle Outside Lights
  state: |
    {% set raising = state_attr('sun.sun', 'rising') %}
    {%- if (not raising) and state_attr('sun.sun', 'elevation') | float <= 6
    and states('sensor.outside_luminance') | int <= 400 %}
      on
    {%- elif raising and state_attr('sun.sun', 'elevation') | float >= -12
    and states('sensor.outside_luminance') | int > 0 %}
      off
    {%- else %}
      {{ 'on' if is_state('input_boolean.outside_lights_status', 'on') else 'off' }}
    {%- endif %}
  availability: |
    {{ has_value('sensor.outside_luminance') 
    and has_value('input_boolean.outside_lights_status')
    and has_value('sun.sun') }}


1 Like

Thanks it’s working now.