Conditional card with all entities beginning with "media_player.plex", possible?

It is so annoying having to add all specific media_player.plex.* entities in my conditional cards (plus doubled since I want as state “playing” and “paused”.

Any way to have a entity variable that shows all entities beginning with “media_player.plex” in one conditional card?

This would just show me any plex player whatever their entity name is…

Now, I need to figure out which is what and add it manually (plus if for some reason, it changes name, need to add it again…

  - type: vertical-stack
    cards:
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__bur_syl
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__bur_syl
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__bur_syl
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__bur_syl 
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__bur_syl_2
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__bur_syl_2   
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__bur_syl_2
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__bur_syl_2            
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__salon
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__salon  
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__salon
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__salon  
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__salon_2
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__salon_2            
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__salon_2
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__salon_2             
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__chambre_2
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__chambre_2            
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__chambre_2
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__chambre_2 
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_3__soussol
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_3__soussol 
    - type: conditional
      conditions:
        - entity: media_player.plex_sfiphone_7_plus
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfiphone_7_plus
    - type: conditional
      conditions:
        - entity: media_player.plex_sfiphone_7_plus
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfiphone_7_plus            
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_stick
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_stick            
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_stick
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_stick 
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_stick_2 
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfroku_stick_2             
    - type: conditional
      conditions:
        - entity: media_player.plex_sfroku_stick_2 
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfroku_stick_2                         
    - type: conditional
      conditions:
        - entity: media_player.plex_sfappletv
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfappletv   
    - type: conditional
      conditions:
        - entity: media_player.plex_sfappletv
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfappletv
    - type: conditional
      conditions:
        - entity: media_player.plex_sfappletv_2
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_sfappletv_2   
    - type: conditional
      conditions:
        - entity: media_player.plex_sfappletv_2
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_sfappletv_2                                    
        
    - type: conditional
      conditions:
        - entity: media_player.plex_lg_g7_thinq
          state: "playing"
      card:
        type: media-control
        entity: media_player.plex_lg_g7_thinq   
    - type: conditional
      conditions:
        - entity: media_player.plex_lg_g7_thinq
          state: "paused"
      card:
        type: media-control
        entity: media_player.plex_lg_g7_thinq

Thanks in advance for any advice about this matter :slight_smile:

I mean, seems like you are making this extra verbose when it can be simplified. Also, you didn’t follow the code posting guidelines highlighted in blue above. Click the link provided in the blue banner to see exactly how to post code so that it doesn’t format it incorrectly. If you see bullets, its formatted wrong.

condtional cards can take multiple conditions:

- type: conditional
  conditions:
    - entity: media_player.plex_lg_g7_thinq
      state: "playing"
    - entity: media_player.plex_lg_g7_thinq
      state: "paused"
  card:
    type: media-control
    entity: media_player.plex_lg_g7_thinq

Hell, if you want it to appear when it’s on…

- type: conditional
  conditions:
    - entity: media_player.plex_lg_g7_thinq
      state_not: "off"
  card:
    type: media-control
    entity: media_player.plex_lg_g7_thinq

not to mention, you can have the template editor write the code for you:

{% for s in states.media_player %}
{% if 'plex' in s.entity_id %}
- type: conditional
  conditions:
    - entity: {{ s.entity_id }}
      state: "playing"
    - entity: {{ s.entity_id }}
      state: "paused"
  card:
    type: media-control
    entity: {{ s.entity_id }}
{% endif %}
{% endfor %}
2 Likes

OK sorry about the code, went too fast lol

Very interesting, just to confirm, the following code, I simply put this in my ui-lovelace.yaml?

{% for s in states.media_player %}
{% if 'plex' in s.entity_id %}
- type: conditional
  conditions:
    - entity: {{ s.entity_id }}
      state: "playing"
    - entity: {{ s.entity_id }}
      state: "paused"
  card:
    type: media-control
    entity: {{ s.entity_id }}
{% endif %}
{% endfor %}

I’m missing something obvious I think
### while scanning for the next token found character '%' that cannot start any token in "/home/homeassistant/.homeassistant/ui-lovelace.yaml", line 1008, column 2

No, that code is placed into your template editor. Then you copy the output into your lovelace.yaml. You may need to add spacing.

1 Like

oh ok, so still, this won’t give me a dynamic card (that would add any new media_player.plex.* entity right?

where is the template editor BTW, never used that… (sorry, newbie questions I guess…)
***update: never mind about the template editor, just found it :slight_smile:

1 Like

Thanks a lot, that helped a lot with the template editor code, at least, I can just refresh the list like this without going through all my entities…
I really appreciate this! thanks again

So there is no dynamic way to fill all the media_player.plex.* in the card setting?

No, there are custom cards that can do that, but they are not conditional. Search for the monster card.

1 Like

Maybe this isn’t exactly what you’re looking for, but I did something similar to this with an entity-filter card (ignore custom:mini-media-player):

- type: entity-filter
  title: Active Media
  show_header_toggle: false
  state_filter:
    - playing
    - paused
  show_empty: false
  card: custom:mini-media-player
  entities:
    - entity: media_player.one
    - entity: media_player.two
    - entity: media_player.three
    - ...

I tried listing multiple entities and states like this and it would not load the card, I re-did them like the OP with a condition for every state and it works for play and paused. I am not sure why it didnt work combined?

It won’t work combined because the contitions are ‘anded’. It’s impossible to have a media_player both simultaneously playing and paused.

Personally, i’d make a template binary_sensor called is_visible or something like that. And use that as the conditional.

this idea seems really cool but is there a way to make it completely dynamic instead of building it in the Developer–>Template thing and copy/pasting the output into a card? I mean, if devices are coming and going from my network and I want to see what’s there real-time I’d have to build this card list every time to see how it looks right then and in a day it’d be stale again.