Need help for an if statement for sending url attachement as notification

Hi!
I want to send an image along with my temperature readings from a sensor to my iPhone as a notification. It seems to work alright when I hardcode the url, but since its symbol can wary I wanted to do some if, else statement. (The best option would be if I could send the sensor.yr_symbol state directly into the url, but that doesn’t seems to work either.)

Her is my try that still sends the temperature readings correct to my phone but the image attachment is missing. I even put en else at the bottom but it didn’t pick that last url either.

action:
  service: notify.ios_robbans_iphone
  data:
    message: "Utetemperatur: {{ states('sensor.bod') }} °C"
    data:
      attachment:
        url: >
          {% if is_state('sensor.yr_symbol', '1') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=1;content_type=image/png"
          {% elif is_state('sensor.yr_symbol', '2') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=2;content_type=image/png"
          {% elif is_state('sensor.yr_symbol', '4') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=4;content_type=image/png"
          {% elif is_state('sensor.yr_symbol', '15') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=15;content_type=image/png"
          {% else %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=15;content_type=image/png"
          {% endif %}
        content-type: png
        hide-thumbnail: false​

So, is it not possible to do it like this?

Regards
Robert

This might help

I’m not sure if the notification component can use templates or not but if so then try replacing data: with data_template.

If templates are OK then I don’t know of any reason why this won’t work:

action:
  service: notify.ios_robbans_iphone
  data_template:
    message: "Utetemperatur: {{ states('sensor.bod') }} °C"
    data:
      attachment:
        url: >
          {% if is_state('sensor.yr_symbol', '1') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=1;content_type=image/png"
          {% elif is_state('sensor.yr_symbol', '2') %}
            "https://api.met.no/weatherapi/weathericon/1.1/?symbol=2;content_type=image/png"
          {% elif is_state('sensor.yr_symbol', '4') %}
           .
           .      
           .

Hi!
Thanks for the reply.

It seems there is two problems here. The first you pointed out, I do need to use data_template.
But having everything on several rows does not seem to work for a reason. Pasting everything on one line fixes the problem.
I suppose it is a problem with indentation or something when having it on several rows.

Thanks again for the tip.
Regards
Robert

I got it to work. No indentation for the text under the if statement

{% if is_state('sensor.yr_symbol', '1') %}
https://api.met.no/weatherapi/weathericon/1.1/?symbol=1;content_type=image/png

I don’t think that was a problem.

I’ve got several places that I use similarly coded templates and they always work fine if I indent them a couple of spaces if for no other reason than easier readability.

For example, the following works fine:

  value_template: >
    {% if value_json is defined and value_json.zones.INZ009 is defined %}
      {{ value_json.zones.INZ009 }}
    {% elif value_json is defined and value_json.zones.INC033 is defined %}
      {{ value_json.zones.INC033 }}
    {% else %}
      0
    {% endif %}

I noticed you dropped the quotation marks on your last example. If that works then maybe that was the problem.