Help Needed Conditional Card Based on Attribute

I’ve configured the following templated mini-media-player card to display artist and song information when my Nest speaker is streaming a particular radio station. The station now playing information is obtained via the multiscrape custom add-on.

type: 'custom:card-templater'
card:
  type: 'custom:mini-media-player'
  entity: media_player.office_speaker
  hide:
    info: true
  name_template: '{{ states.sensor.kgbi_artist.state }} - {{states.sensor.kgbi_song.state }}'
entities:
  - sensor.kgbi_artist
  - sensor.kgbi_song

What I’m trying to do now is to display this card only if that scraped station is the one playing, as defined by media_content_id:. If media_content_id: = [kgbi url] then this card is displayed. Otherwise, the standard mini-media-player card is displayed. I’m new to conditionals and see that I can choose the entity and state, but not attribute. Is there a way to test the attribute and display my card when appropriate?

I’m reviving my thread because this has been requested over the years and I was able to solve my 3-year-old request by reading how other people had accomplished this.

In Settings > Devices & services > Helpers I chose the “Create Helper” button. I chose Template > Binary Template Sensor. For the state template, I used:

{{ 'kgbi' in state_attr('media_player.basement_speaker', 'media_content_id') }}

This is because the attribute reads the full url when streaming, but the special characters messed it up. Searching for just “kgbi” in the attribute works.

My media card is now different, but the important thing is the conditional card. I created a conditional with the following two conditions:

conditions:
  - condition: state
    entity: binary_sensor.life_100_playing_in_basement
    state: 'on'
  - condition: state
    entity: media_player.basement_speaker
    state: playing

I was able to select these graphically, but it’s easier to display the code.

Now when the basement speaker is playing and it’s streaming Life 100 (KGBI), my desired media card appears with the artist, song title, and album art for the currently playing song. Pretty slick!

Thanks for posting your solution! I was looking for the exact same thing.