Help with if-statement

Hey, I’m stuck.

If sensor.niclas:status and sensor.sara_status is ‘Anlände’ play Favorites
elif only sensor.niclas_status is ‘Anlände’ play Raubtier
else play P3 Star

How to translate the above statement to the code below?

Something is wrong with my coding.

source: "{{ 'Favorites' if states.sensor.niclas_status.state == 'Anlände' and if states.sensor.sara_status.state == 'Anlände' elif 'Raubtier' if states.sensor.niclas_status.state == 'Anlände' else 'P3 Star' }}"

You should review the Jinja2 syntax.

{{......}} These are expressions
{%.....%} These are statements

{% if states.sensor.niclas_status.state == 'Anlände' and states.sensor.sara_status.state == 'Anlände' %}
  do something
{% elif states.sensor.niclas_status.state == 'Anlände' %}
  do something else
{% endif %}

Okey this is a script that is working but I want to do the if statement longer like above, so I dont think your suggestion going to work…

As you see in the bottom of the script I get Raubtier playlist in sonos if sensor.niclas_status is ‘Anlände’ othervise I get P3 Star.
Now I would like to add sensor.sara_status, and if both these sensors are ‘Anlände’ så play Favorites, if only sensor.niclas_status is ‘Anlände’ play Raubtier and else play P3 Star

script:
  sonos_notplaying:
    alias: "Sonos Not PLaying"
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: "{{ sonos_entity }}"
          volume_level: "{{ volume }}"
      - delay: '00:00:05'
      - service: tts.google_say
        data_template:
          entity_id: "{{ sonos_entity }}"
          message: "{{ message }}"
      - delay: '00:00:03'
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.kok
          volume_level: 0.35
      - service: media_player.select_source
        data_template:
          entity_id: media_player.kok
          source: "{{ 'Raubtier' if states.sensor.niclas_status.state == 'Anlände' else 'P3 Star' }}"

Dont anyone know this?

With some help from a friend I got it to work by doing this:

{% if is_state('sensor.niclas_status', 'Anlände') and is_state('sensor.sara_status', 'Anlände') %}
  STAR FM 96.3 (60-tal)
{% elif is_state('sensor.niclas_status', 'Anlände') %}
  Raubtier
{% else %}
  P3 Star
{% endif %}