Conditional Cards for Media Players

I’ve placed 3 media player cards on one of my UI tabs.

  • One card displays the Spotify media player.
  • One card displays the kitchen speaker - a google device.
  • One card displays the living room speaker - also a google device.

We have created a dedicated login in Spotify for Home Assistant, and that is also the authenticated player for the Google devices.

We also each have our own Spotify account so we can login individually on our phones. When we’re playing music on our phones and we want to cast to a google device, we simply select that device and away it goes.

If we ask Google to play a song on spotify, it uses the Home Assistant account. We’ve run into a few conflicts here or there, but overall it works well.

Here’s the problem to solve. When the spotify account for home assistant is being used to play music on a media player, the artwork is displayed on the Spotify card. If we cast to all speakers using the same account, all three media player cards display the same information.

It’s screen real estate that doesn’t need to be used. Ideally, in this scenario, I’d like there to be only one player shown. If we use our phones to cast to another speaker, then an additional media player card would pop up on the screen with that information.

The conditional card seems to be limited to the state of the entity. What I need to do is create logic that checks what’s actually playing on the media player to determine if the card should be shown or not.

Is this possible?

1 Like

First of all: I don’t know, so I’ll ask some questions that might help (or not)

  1. Is there an attribute of your media player(s) that is showing a relevant information about source/media that could be used?
  2. Is there cases where 2 of the 3 are showing the artwork when you want only one?

My first idea, maybe not the best, is to create a template binary_sensor that will be true if the source of the media_players are somewhat the same (false otherwise)

Then the state of this binary_sensor can be the condition to hide the google devices and only keep the Spotify media player, maybe?

Something like:
show_kitchen: spotify source/media <> kitchen source/media
show_living: spotify source/media <> living room source/media

Then, you always (?) show the spotify card and condition the 2 others based on those templates.
EDIT: You can also include the state of the media_player (idle, pause, …)