Dark sky icon if statement syntax issue

Something about this syntax is wrong and I can’t figure it out. I’ve even copy and pasted this from other posts on the forum.

  - service_template:
      "{% if is_state('sensor.dark_sky_icon', 'rain') %}
        script.abbott_rain
      {% elif is_state('sensor.dark_sky_icon', 'snow') %}
        script.abbott_snow
      {% endif %}"

That should be all anyone needs to help me out, but in case not, here’s the full automation:

- id: auto_lifx_weather_jelly
  alias: Weather Jelly
  trigger:
  - at: '11:02:00'
    platform: time
  condition: []
  action:
  - service_template: "{% if states('sensor.dark_sky_daytime_high_temperature_0de') | float > 80 %}\n  script.turn_abbott_red\n\
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 70 %}\n  script.turn_abbott_orange\n\
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 60 %}\n  script.turn_abbott_yellow\n\
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 50 %}\n  script.turn_abbott_green\n\
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 30 %}\n  script.turn_abbott_blue\n\
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 0 %}\n  script.turn_abbott_icey_blue\
      \  \n{% else %}\n  script.turn_abbott_purple\n{% endif %}\n"
  - service: persistent_notification.create
    data:
      message: "Temp high = {{ states('sensor.dark_sky_daytime_high_temperature_0d') | float }}"
      title: "Debugging"
  - service_template:
      "{% if is_state('sensor.dark_sky_icon', 'rain') %}
        script.abbott_rain
      {% elif is_state('sensor.dark_sky_icon', 'snow') %}
        script.abbott_snow
      {% endif %}"

And the error code:

Error while executing automation automation.weather_jelly. Invalid data for call_service at pos 3: Service does not match format .

Remove the quotations from around your multi-line templates and use the > character to indicate it is a multi-line template. Quotes are only required for single line templates. There is no need for the newline characters. e.g:

  - service_template: >
      {% if is_state('sensor.dark_sky_icon', 'rain') %}
        script.abbott_rain
      {% elif is_state('sensor.dark_sky_icon', 'snow') %}
        script.abbott_snow
      {% endif %}

That template is missing an else statement. What happens if the sensor state is not snow or rain (e.g. undefined or sunny)?

  - service_template: >
      {% if states('sensor.dark_sky_daytime_high_temperature_0de') | float > 80 %}
        script.turn_abbott_red
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 70 %}
        script.turn_abbott_orange
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 60 %}
        script.turn_abbott_yellow
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 50 %}
        script.turn_abbott_green
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 30 %}
        script.turn_abbott_blue
      {% elif states('sensor.dark_sky_daytime_high_temperature_0d') | float > 0 %}
        script.turn_abbott_icey_blue
      {% else %}
        script.turn_abbott_purple
      {% endif %}

Thank you, that was it!

I don’t need an else statement for this. The idea is that the light will turn a solid color when I wake up to let me know what temperature range to expect, and pulse/breathe blue or white if it’s going to rain or snow so I can grab the appropriate coat.

The service template will generate errors if snow or rain is not forecast. You need an else statement, even if it appears to do nothing.

Oh. That’s dumb. Why is HA written that way?

Guess I’ll add in a dummy script and point to it.