Media player template behaves not as expected

Okay, I’m tinkering around with Mushroom cards again and I build a chip card that should do the following. The chip should change:

  • the icon should change depending on state.attr of the media player (Arbeitszimmer = Office) → working
  • the icon color should change to → working
  • the service being called should change dependiung on the state.attr → not working

This code is working flawlessly in Developer Tools\Services:

service: |-
  {% if is_state_attr('media_player.arbeitszimmer', 'group_members',
  [
    "media_player.arbeitszimmer",
  ]) %}
    script.join_bad
  {% elif is_state_attr('media_player.arbeitszimmer',
  'group_members', [
    "media_player.arbeitszimmer",
    "media_player.bad"
  ]) %} 
    script.unjoin_bad
  {% endif %}

But if I put it in with the rest of it in my chip card I get

Failed to call service <{% if is_state_attr('media_player.arbeitszimmer', 'group_members',["media_player. Service not found

Here’s the full chip card and if I replace the service with just ‘script.join.bad’ or ‘script.unjoin.bad’ everything is working fine so the card is okay.

type: custom:mushroom-chips-card
chips:
  - type: template
    entity: media_player_bad
    icon: >-
      {% if is_state_attr('media_player.arbeitszimmer', 'group_members',
      [
        "media_player.arbeitszimmer",
      ]) %}
        hue:room-bathroom
      {% elif is_state_attr('media_player.arbeitszimmer',
      'group_members', [
        "media_player.arbeitszimmer",
        "media_player.bad"
      ]) %} 
        hue:room-bathroom-off
      {% else %}
        mdi:cloud-question
      {% endif %}
    icon_color: >-
      {% if is_state_attr('media_player.arbeitszimmer', 'group_members',
      [
        "media_player.arbeitszimmer",
      ]) %}
        disabled
      {% elif is_state_attr('media_player.arbeitszimmer',
      'group_members', [
        "media_player.arbeitszimmer",
        "media_player.bad"
      ]) %} 
        blue
      {% else %}
        mdi:cloud-question
      {% endif %}
    content: ''
    hold_action:
      action: call-service
      service: |-
          {% if is_state_attr('media_player.arbeitszimmer', 'group_members', ["media_player.arbeitszimmer", ]) %}
            script.join_bad
          {% elif is_state_attr('media_player.arbeitszimmer','group_members', ["media_player.arbeitszimmer", "media_player.bad" ]) %} 
            script.unjoin_bad
          {% endif %}
      service_data: {}
      target: {}

Hope that’s just a ',{ somewhere that has to be in the card code and Developer Tools is that picky.

I don’t think that the tap action is templatable.

In general or with chip card?

I tried it a while ago in Mushroom and it didn’t work, at least in UI. Might work in yaml mode.

Tried again now with a simple


  service: >
    {{ 'light.turn_on' if states('light.leselampen') == 'off' else
    'light.turn_off'}}

No luck.

Tried like everything and yes, won’t work.

Helped myself out with 3 scripts…ugly but working now.

Chip:

  type: custom:mushroom-chips-card
  chips:
    - type: template
      entity: media_player_bad
      icon: |-
        {% if is_state_attr('media_player.arbeitszimmer', 'group_members', [
          "media_player.arbeitszimmer",
        ]) %}
          hue:room-bathroom
        {% elif is_state_attr('media_player.arbeitszimmer', 'group_members', [
          "media_player.arbeitszimmer",
          "media_player.bad"
        ]) %} 
          hue:room-bathroom-off
        {% else %}
          mdi:cloud-question
        {% endif %}
      icon_color: |-
        {% if is_state_attr('media_player.arbeitszimmer', 'group_members', [
          "media_player.arbeitszimmer",
        ]) %}
          disabled
        {% elif is_state_attr('media_player.arbeitszimmer', 'group_members', [
          "media_player.arbeitszimmer",
          "media_player.bad"
        ]) %} 
          blue
        {% else %}
          mdi:cloud-question
        {% endif %}
      content: ''
      hold_action:
        action: call-service
        service: script.1652637642637
        service_data: {}
        target: {}

Join script:

alias: 'Bad: join Arbeitszimmer'
sequence:
  - service: media_player.join
    data:
      group_members: media_player.bad
    target:
      entity_id: media_player.arbeitszimmer
mode: single
icon: mdi:lan-connect

Unjoin script:

alias: 'Bad: unjoin group'
sequence:
  - service: media_player.unjoin
    data: {}
    target:
      entity_id: media_player.bad
mode: single
icon: mdi:lan-disconnect

Toggle join/unjoin script:

alias: 'Arbeitszimmer --> Bad: join/unjoin'
sequence:
  - service: |-
      {% if is_state_attr('media_player.arbeitszimmer', 'group_members',
      [
        "media_player.arbeitszimmer",
      ]) %}
        script.bad_join
      {% elif is_state_attr('media_player.arbeitszimmer',
      'group_members', [
        "media_player.arbeitszimmer",
        "media_player.bad"
      ]) %} 
        script.bad_unjoin_group
      {% endif %}
mode: single
icon: mdi:sync