Lovelace Auto Entities - Filter duplicate Media Player entities playing the same media

The Problem

Hello everyone! I am using the lovelace-auto-entities (GitHub) custom card to filter and show all the active media players in my house, but one problem I have ran into is duplicates. I have a Google Cast group with all my Google Nest speakers contained in, but if I cast media to this group, all the members show playing the same media. Below is an example of what I mean, instead with Spotify and my Desktop.

image

Configuration

This is my current configuration, resulting in the above image.

type: custom:auto-entities
card:
  type: entities
  show_header_toggle: false
filter:
  include:
    - domain: media_player
      state: playing
sort:
  method: none
else:
  type: tile
  icon: fas:circle-question
  name: No Media Playing
  hide_state: true
  show_entity_picture: false
  entity: weather.forecast_home_assistant
  tap_action:
    action: none
  icon_tap_action:
    action: none
unique: true

Solution

I need to somehow prevent the showing of different devices playing the same media, and if possible in the situation that they’re in a group, only show the group player, not the group members. Any and all help is greatly appreciated, thanks.

@TheFrontlineGen
Use template filter. Something like the following (it assumes that all players use the same media_title attribute value):

type: custom:auto-entities
card:
  type: entities
  show_header_toggle: false
filter:
  template: |-
    {% set data = namespace(player_titles=[]) %}
    {%- for state in states.media_player -%}
      {%- if state.state == 'playing' -%}
        {%- if state.attributes.media_title not in data.player_titles -%}
          {%- set data.player_titles = data.player_titles + [state.attributes.media_title] -%}
          {{ state.entity_id}},
        {%- endif -%}
      {%- endif -%}
    {%- endfor -%}
sort:
  method: none
else:
  type: tile
  icon: fas:circle-question
  name: No Media Playing
  hide_state: true
  show_entity_picture: false
  entity: weather.forecast_home
  tap_action:
    action: none
  icon_tap_action:
    action: none
unique: true
1 Like