Auto-entities Stack for Plex media-players

Continuing the discussion from :small_blue_diamond: Card-mod - Add css styles to any lovelace card:

as a separate post, since this is no longer on card-mod, but has turned into a cool little project of its own.

selecting the active Plex players using:

  - type: custom:auto-entities
    card:
      type: entities
#      title: Plex dashboard
#      card_mod: *header
    show_empty: false
    filter:
      include:
        - entity_id: media_player.plex_*
          state: /playing|paused|'on'/
          options:
            !include /config/lovelace/includes/include_plex_playing.yaml
#      exclude:
#        - state: unavailable
#        - state: idle
#        - state: 'off'

(in commented bits some other experiments that can still be used, but I chose to leave out for now. Include and exclude do the same, just listed for reference)

the include moves the auto-entities selected entity to the underlying config. Which was a bit of a search I must admit. Ive started out with config.entity in the templates in the single card from the other post. I then realized I had to use this.entity_id but that didnt work plainly like that. It needs to be quoted in the templates like 'this.entity_id':

type: custom:stack-in-card
card_mod:
  style: |
    ha-card {
      margin: -16px;
      box-shadow: none;
    }
keep:
  background: true
cards:
  - type: custom:button-card
    template: button_default_title
    name: >
      [[[ var caption = 'Plex playing:&nbsp';
          var title = states['this.entity_id'].attributes.media_title;
          var artist = states['this.entity_id'].attributes.media_artist;
          var album  = states['this.entity_id'].attributes.media_album_name;
          return `<div style='display: flex; padding: 0px 16px 0px 0px;'>
              <div>${caption}</div>
              <marquee>
              <span style='color:silver;align-items:center;'>${artist} - ${album} - ${title}</span>
              </marquee>`;]]]
    show_icon: false
    styles:
      card:
        - color: orange
        - background-color: black

  - type: custom:hui-element
    card_type: markdown
    theme: plex
    card_mod:
      style: |
        ha-card.type-markdown {
          background-image: url('/local/various/plex.png');
          background-position: right top;
          background-size: 180px; /*contain works too, but the size then changes according to space used in markdown */
          background-repeat: no-repeat;
          /*box-shadow: none;*/
          color: silver;
        }
    content: >
      {% set player = 'this.entity_id' %}
      {% if states(player) not in ['unknown','unavailable'] %}
      <font color='orange'>**User:**</font> {{state_attr(player,'username')}}
      {% for attr in states[player].attributes %}
        {%- if not attr in ['media_content_id','icon','entity_picture','hide_attributes',
                            'media_position_updated_at','media_duration','media_position',
                            'player_source','media_content_rating',
                            'is_volume_muted','username','friendly_name','volume_level',
                            'supported_features'] %}
       <font color=orange> **{{attr.split('media_')[1]|replace('_',' ')|title}}:**</font> {{states[player].attributes[attr]|title}} {% endif %}
      {%- endfor %}
      {% else %} Nothing playing
      {% endif %}

  - type: custom:button-card
    aspect_ratio: 1/1
    show_name: false
    show_icon: false
    tap_action: none
    card_mod:
      style: |
        ha-card {
          background: url({{state_attr('this.entity_id','entity_picture')}});
          /*box-shadow: none;*/
          background-size: cover;
        }

The above config results in a separate stack for each individual media player playing a Plex media source.

If you check closely, you’ll see a theme: plex for the middle card in the stack, the markdown. This is a neat little trick I discovered to be able to use both a background-image And a background-color (in the theme). the theme is nothing more than:

plex:
  - card-background-color: black

result:

Feb-03-2022 09-42-15

2 Likes

very cool Marius, can you share a link to your github/source for the image files and template called “button_default_title” ?

the images are form the source material :wink:
the template is in my Gist
btw my adjusted code (no longer using stack-in-card) is below:

#https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/2193?u=mariusthvdb
#type: custom:stack-in-card
#card_mod:
#  style: |
#    ha-card {
#      margin: -16px;
#      box-shadow: none;
#    }
#keep:
#  background: true
#cards:
type: custom:mod-card
card_mod:
  style: |
    ha-card {
      margin: -16px;
      box-shadow: none:
    }
    :host {
      --stack-card-margin: 0px;
    }
card:
  type: vertical-stack
  cards:
    - type: custom:button-card
      template: button_default_title
      name: >
        [[[ var caption = 'Plex playing:&nbsp';
            var title = states['this.entity_id'].attributes.media_title;
            var artist = states['this.entity_id'].attributes.media_artist;
            var album  = states['this.entity_id'].attributes.media_album_name;
            return `<div style='display: flex; padding: 0px 16px 0px 0px;'>
                <div>${caption}</div>
                <marquee>
                <span style='color:silver;align-items:center;'>${artist} - ${album} - ${title}</span>
                </marquee>`;]]]
      show_icon: false
      styles:
        card:
          - color: orange
          - background-color: black

    - type: custom:hui-element
      card_type: markdown
      theme: plex
      card_mod:
        style: |
          ha-card.type-markdown {
            background-image: url('/local/various/plex.png');
            background-position: right top;
            background-size: 180px; /*contain works too, but the size then changes according to space used in markdown */
            background-repeat: no-repeat;
            color: silver;
          }
      content: >
        {% set player = 'this.entity_id' %}
        {% if states(player) not in ['unknown','unavailable'] %}
        <font color='orange'>**User:**</font> {{state_attr(player,'username')}}
        {% for attr in states[player].attributes %}
          {%- if not attr in ['media_content_id','icon','entity_picture','hide_attributes',
                              'media_position_updated_at','media_duration','media_position',
                              'player_source','media_content_rating',
                              'is_volume_muted','username','friendly_name','volume_level',
                              'supported_features'] %}
         <font color=orange> **{{attr.split('media_')[1]|replace('_',' ')|title}}:**</font> {{states[player].attributes[attr]|title}} {% endif %}
        {%- endfor %}
        {% else %} Nothing playing
        {% endif %}

    - type: custom:hui-element
      card_type: picture
      image: /local/images/transparent.png
      card_mod:
        style: |
          ha-card.type-picture {
            padding: 8px;
            background: url({{state_attr('this.entity_id','entity_picture')}});
            background-size: cover;
          }

Plex:

awesome, thanks heaps - can I trouble you for your “transparent” png file as well? :smiley:

transparent

sure here you go

I can’t see it :wink: hahaha

transparent

should be here…so transparent it doesnt even throw the image placeholder

was joking - it’s very transparent :slight_smile:

1 Like

Hi @Mariusthvdb - great implementation.
One question - where do you need to store the template “button_default_title” so that the card can pick it up?

see the docs GitHub - custom-cards/button-card: ❇️ Lovelace button-card for home assistant

you need to set the path for each dashboard if you use more than 1

title: Your title

button_card_templates: !include_dir_merge_named ../button_card_templates
decluttering_templates: !include_dir_named ../decluttering_templates
kiosk_mode: !include ../kiosk-mode/kiosk-mode.yaml


views:

ofc, adapt the paths to your system config

1 Like

hi,
as a great Plex fan i admire this player of yours and i’ve been trying to start up your wonderfull card but i’m struggling with this this.entity_id.
As shown on the picture, this is how far i got. i just can’t start the player to be visual
image
all is installed accordingly i guess, but i have missed something.
Installed all cards correctly and the top card is running when music is played
Any advice?

uhm, long time since I reviewed that… tbh, I never use HA to stream my media, but hey this was a nice templating exercise :wink:

also, the image should auto extract, and Ive fired Plex for you just now, and it still just works…
the this.entity_id should take care of that really.

Can you see any picture at all in dev tools when you enter the actual entity?

well, it’s not clear to me how to point out this “this.entity_id” part of the set up.
this is nmy card config;

type: custom:mod-card
card_mod:
style: |
ha-card {
margin: -16px;
box-shadow: none:
}
:host {
–stack-card-margin: 0px;
}
card:
type: vertical-stack
cards:
- type: custom:auto-entities
show_empty: false
card:
type: entities
title: Plex Playing
card_mod:
style: |
.card-header {
background-color: black;
color: orange;
padding-top: 0px;
padding-bottom: 0px;
}
filter:
include:
- entity_id: media_player.plex*
state: /playing|paused|‘on’/
options:
type: custom:hui-element
card_type: markdown
theme: plex
card_mod:
style: |
ha-card.type-markdown {
background-image: url(’/local/plex.png’);
background-position: right;
background-size: contain;
background-repeat: no-repeat;
box-shadow: none;
color: silver;
margin: 8px -16px -16px -16px;
}
content: >
{% set player = config.entity %} {% if states(player) not in
[‘unknown’,‘unavailable’] %} User:
{{state_attr(player,‘username’)}} {% for attr in
states[player].attributes %}
{%- if not attr in [‘media_content_id’,‘icon’,‘entity_picture’,‘hide_attributes’,
‘media_position_updated_at’,‘media_duration’,‘media_position’,
‘player_source’,‘media_content_rating’,
‘is_volume_muted’,‘username’,‘friendly_name’,‘volume_level’,
‘supported_features’] %}
- {{attr.split(‘media_’)[1]|replace(’_’,’ ')|title}}: {{states[player].attributes[attr]|title}} {% endif %}
{%- endfor %} {% else %} Nothing playing {% endif %}
sort:
method: name
- type: custom:hui-element
card_type: markdown
theme: plex
card_mod:
style: |
ha-card.type-markdown {
background-image: url(’/local/plex.png’);
background-position: right top;
background-size: 180px; /*contain works too, but the size then changes according to space used in markdown */
background-repeat: no-repeat;
color: silver;
}
content: >
{% set player = ‘this.entity_id’ %} {% if states(player) not in
[‘unknown’,‘unavailable’] %} User:
{{state_attr(player,‘username’)}} {% for attr in
states[player].attributes %}
{%- if not attr in [‘media_content_id’,‘icon’,‘entity_picture’,‘hide_attributes’,
‘media_position_updated_at’,‘media_duration’,‘media_position’,
‘player_source’,‘media_content_rating’,
‘is_volume_muted’,‘username’,‘friendly_name’,‘volume_level’,
‘supported_features’] %}
{{attr.split(‘media_’)[1]|replace(’_’,’ ')|title}}: {{states[player].attributes[attr]|title}} {% endif %}
{%- endfor %} {% else %} Nothing playing {% endif %}
- type: custom:hui-element
card_type: picture
image: /local/images/transparent.png
card_mod:
style: |
ha-card.type-picture {
padding: 8px;
background: [quote=“Mariusthvdb, post:12, topic:387888, full:true”]
uhm, long time since I reviewed that… tbh, I never use HA to stream my media, but hey this was a nice templating exercise :wink:

also, the image should auto extract, and Ive fired Plex for you just now, and it still just works…
the this.entity_id should take care of that really.

Can you see any picture at all in dev tools when you enter the actual entity?
[/quote]

        background-size: cover;
      }

This entity would be the actual media_player entity that is currently playing your Plex content

What I meant was you enter that entity in dev templates with the above template to see what it returns. Or in dev states, and check the attributes list.

Can’t check your card, but please format it correctly so we have an option at least

sorry for the inconvienent posting, i am fresh on the block.
it was an exact copy of what you have posted that i copied into my card.
should i replace the word THIS ENTITY with the target media player?

Uhm. You should try to understand what this does…

Auto entities fills this with entities it filters based on the config.

Tbh, I am not sure what you are asking, as the whole function of auto-entities is based on this.entity_id …

Did you read the docs in the repo? It’s rather well documented.

hi Marius,
i figured out how to post properly :wink:
the previous question i had regarding this.entity id is now clear to me as well.
It is just that the top part of the card is working correctly. the bottom part shows only nothing playing instead of showing a player or picture eventhough that the player is playing activly.
image
if i change player, the info changes aswell.

type: custom:mod-card
card_mod:
  style: |
    ha-card {
      margin: -16px;
      box-shadow: none:
    }
    :host {
      --stack-card-margin: 0px;
    }
card:
  type: vertical-stack
  cards:
    - type: custom:auto-entities
      show_empty: false
      card:
        type: entities
        title: Plex Playing
        card_mod:
          style: |
            .card-header {
              background-color: black;
              color: orange;
              padding-top: 0px;
              padding-bottom: 0px;
            }
      filter:
        include:
          - entity_id: media_player.plex*
            state: /playing|paused|'on'/
            options:
              type: custom:hui-element
              card_type: markdown
              theme: plex
              card_mod:
                style: |
                  ha-card.type-markdown {
                    background-image: url('/local/plex.png');
                    background-position: right;
                    background-size: contain;
                    background-repeat: no-repeat;
                    box-shadow: none;
                    color: silver;
                    margin: 8px -16px -16px -16px;
                  }
              content: >
                {% set player = config.entity %} {% if states(player) not in
                ['unknown','unavailable'] %} <font
                color='orange'>**User:**</font>
                {{state_attr(player,'username')}} {% for attr in
                states[player].attributes %}
                  {%- if not attr in ['media_content_id','icon','entity_picture','hide_attributes',
                                      'media_position_updated_at','media_duration','media_position',
                                      'player_source','media_content_rating',
                                      'is_volume_muted','username','friendly_name','volume_level',
                                      'supported_features'] %}
                 <font color=orange> **- {{attr.split('media_')[1]|replace('_',' ')|title}}:**</font> {{states[player].attributes[attr]|title}} {% endif %}
                {%- endfor %} {% else %} Nothing playing {% endif %}
            sort:
              method: name
    - type: custom:hui-element
      card_type: markdown
      theme: plex
      card_mod:
        style: |
          ha-card.type-markdown {
            background-image: url('/local/plex.png');
            background-position: right top;
            background-size: 180px; /*contain works too, but the size then changes according to space used in markdown */
            background-repeat: no-repeat;
            color: silver;
          }
      content: >
        {% set player = 'this.entity_id' %} {% if states(player) not in
        ['unknown','unavailable'] %} <font color='orange'>**User:**</font>
        {{state_attr(player,'username')}} {% for attr in
        states[player].attributes %}
          {%- if not attr in ['media_content_id','icon','entity_picture','hide_attributes',
                              'media_position_updated_at','media_duration','media_position',
                              'player_source','media_content_rating',
                              'is_volume_muted','username','friendly_name','volume_level',
                              'supported_features'] %}
         <font color=orange> **{{attr.split('media_')[1]|replace('_',' ')|title}}:**</font> {{states[player].attributes[attr]|title}} {% endif %}
        {%- endfor %} {% else %} Nothing playing {% endif %}
    - type: custom:hui-element
      card_type: picture
      image: /local/images/transparent.png
      card_mod:
        style: |
          ha-card.type-picture {
            padding: 8px;
            background: url({{state_attr('this.entity_id','entity_picture')}});
            background-size: cover;
          }

          }

is this the card with the transparent image?

I Belize it is yes

you have that too? It would probably return an error if you didnt, but just to be sure

Aha! no i don’t have that. i’ve read the previous posts from you and the reaction of him not seeing the picture. well i didn’t see any links so i thought it was a prank. :blush:
but, if needed where can i find this transparent png?

I’m sure I’ve posted it before… it’s a bit, well, invisible :wink:

transparent

but here it is once more (click in the white space above and select save as …)