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 ā€¦)