the Plex Recently Added integration has been in uPreformatted text
se for well over a year, just changed dev recently.
Plex Recently Added should have nothing to do with what is currently playing.
this line is an if statement
return data && (data[variables.i].fanart || data[variables.i].poster)
? `url("${data[variables.i].fanart}"), url("${data[variables.i].poster}")`
: `url("${variables.entity_picture}")`;
it read like so
if we have data (data is the entity attributes)
and
if that data has an attribute called fanart or poster (Eg Plex recently added)
then use a url that consists of the fanart and poster
if we dont have any data
or
if we dont have an attribute called fanart or poster
then use the variables.entity_picture (set is base as entity.attributes.entity_picture)
so in short, if you dont have an entity_picture attribute you won’t have a background.
looking into @Laffer setup he has this
- type: conditional
conditions:
- entity: select.conditional_media
state: SHIELD
card:
type: custom:button-card
entity: sensor.shield_real_state
template:
- conditional_media
- icon_nvidia_shield
- media_volume
variables:
player: '[[[ return entity.attributes.player; ]]]'
entity_picture: sensor.active_media_players
volume_control: media_player.denon_receiver
triggers_update:
- sensor.active_media_players
see this line entity_picture: sensor.active_media_players
looks like he is setting a custom entity_picture like so
# SENSOR - CONDITIONAL MEDIA BACKGROUND
- unique_id: active_media_players
name: 'Active Media Players'
state: >
{% set media_players = [
states.media_player.apple_tv_1,
states.media_player.apple_tv_2,
states.sensor.shield_real_state,
states.media_player.plex_plex_for_windows_sagasdesktop
] %}
{{ media_players | selectattr('state','search','(playing|paused)') | list | count }}
attributes:
active: >
{% set media_players = [
states.media_player.apple_tv_1,
states.media_player.apple_tv_2,
states.sensor.shield_real_state,
states.media_player.plex_plex_for_windows_sagasdesktop
] %}
{%- set media_players_playing = media_players | selectattr('state','eq','playing') | list %}
{%- set media_player_id_playing = media_players_playing | map(attribute='entity_id') | join(', ') %}
{%- set media_players_paused = media_players | selectattr('state','eq','paused') | list %}
{%- set media_player_id_paused = media_players_paused | map(attribute='entity_id') | join(', ') %}
{%- if (media_players_playing | length > 0) -%}
{{ media_player_id_playing }}
{%- elif (media_players_paused | length > 0) -%}
{{ media_player_id_paused }}
{%- endif -%}
app: >
{%- if this.state not in ['unavailable','undefined','unknown','none','null', '0'] %}
{% set players = (state_attr('sensor.active_media_players', 'active')).split(', ') %}
{% if players[0] is defined %}
{% if 'plex' in players[0] %}
plex
{% else %}
{% set app = state_attr(players[0], 'app_name') | lower %}
{% if app not in ['unavailable','undefined','unknown','none','null'] %}
{{ app }}
{% else %}
{% set app = state_attr(players[0], 'app_id') | lower %}
{% if app not in ['unavailable','undefined','unknown','none','null'] %}
{{ app }}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
media_title: >
{%- if this.state not in ['unavailable','undefined','unknown','none','null', '0'] %}
{% set players = (state_attr('sensor.active_media_players', 'active')).split(', ') %}
{% if players[0] is defined %}
{% if 'plex' in players[0] or state_attr('sensor.active_media_players', 'app') == 'plex' %}
{% if state_attr(players[0], 'media_content_type') == 'tvshow' %}
{{state_attr(players[0], 'media_series_title')}} - {{state_attr(players[0], 'media_title')}}
{% else %}
{{state_attr(players[0], 'media_title')}}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
media_content_type: >
{% if this.state not in ['unavailable','undefined','unknown','none','null', '0'] %}
{% set players = (state_attr('sensor.active_media_players', 'active')).split(', ') %}
{% if players[0] is defined %}
{% if 'plex' in players[0] or state_attr('sensor.active_media_players', 'app') == 'plex' %}
{% if state_attr(players[0], 'media_content_type') %}
{{ state_attr(players[0], 'media_content_type') }}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
entity_picture: >
{%- if this.state not in ['unavailable','undefined','unknown','none','null', '0'] %}
{%- set players = (state_attr('sensor.active_media_players', 'active')).split(', ') %}
{% if players[0] is defined %}
{%- set entitypic = state_attr(players[0],'entity_picture') %}
{%- set app = state_attr('sensor.active_media_players','app') | lower %}
{%- if app is defined %}
{% if 'plex' in app %} /local/images/Plex_bg.png
{% elif 'infuse' in app %} /local/images/Plex_bg.png
{% elif 'com.apple.tvwatchlist' in app %} /local/images/ATVPlus_bg.jpg
{% elif 'airplay' in app %} /local/images/AirPlay_bg.jpg
{% elif 'com.amazon' in app %} /local/images/AmazonPrime_bg.jpg
{% elif 'disneyplus' in app %} /local/images/dp_bg.jpg
{% elif 'youtube' in app %} /local/images/yt_bg.jpg
{% elif 'tv2' in app %} /local/images/tv2play_bg.jpg
{% elif 'hbo' in app %} /local/images/HBOMax_bg.jpg
{% elif 'netflix' in app %} /local/images/netflix_bg.jpg
{% elif 'nrk' in app %} /local/images/nrk_bg.jpg
{% elif 'viasat' in app %} /local/images/ViaPlay_bg.jpg
{% elif 'viaplay' in app %} /local/images/ViaPlay_bg.jpg
{% elif 'viafree' in app %} /local/images/ViaFree_bg.jpg
{% elif 'kanal5' in app %} /local/images/discovery_bg.jpg
{% elif 'twitch' in app %} /local/images/twitch_bg.jpg
{% else %} null
{% endif %}
{%- elif 'plex' in players %}
{{ '/local/images/Plex_bg.png' }}
{%- endif %}
{%- endif %}
{%- endif %}
# SENSOR - SHIELD REAL STATE
- unique_id: shield_real_state
name: 'SHIELD Real State'
state: >
{% set players = [
states.media_player.plex_plex_for_android_tv_shield_android_tv,
states.media_player.shield
] %}
{% if players | selectattr('state','eq','playing') | list | count >= 1 %}
playing
{% elif players | selectattr('state','eq','paused') | list | count >= 1 %}
paused
{% elif players | selectattr('state','eq','idle') | list | count >= 1 %}
idle
{% else %}
off
{% endif %}
attributes:
player: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set app = state_attr('media_player.shield', 'app_name') %}
{%- if app is defined %}
media_player.shield
{% endif %}
{% endif %}
app_name: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set app = states.media_player.shield.attributes.app_name %}
{%- if app is defined %}
{%- if app != '' and app not in ['unknown','unavailable','none','off'] %}
{{ app | lower }}
{% endif %}
{% else %}
plex
{% endif %}
{% endif %}
app_id: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set app = states.media_player.shield.attributes.app_id %}
{%- if app is defined %}
{%- if app != '' and app not in ['unknown','unavailable','none','off'] %}
{{ app }}
{% endif %}
{% else %}
plex
{% endif %}
{% endif %}
entity_picture: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set current_app = states.sensor.shield_real_state.attributes.app_name %}
{% set picture = states.media_player.plex_plex_for_android_tv_shield_android_tv.attributes.entity_picture %}
{%- if picture is defined %}
{%- if picture != '' and picture not in ['unknown','unavailable','none'] %}
{%- if current_app is defined and current_app == 'plex' %}
{{- '/local/images/Plex_bg.png' if current_app == 'plex' else picture -}}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
media_artist: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set artist = states.media_player.shield.attributes.media_artist %}
{%- if artist is defined %}
{%- if artist != '' and artist not in ['unknown','unavailable','none'] %}
{{ artist }}
{% endif %}
{% endif %}
{% endif %}
media_title: >
{% if states.sensor.shield_real_state.state | lower not in ['unknown','unavailable','none','off'] %}
{% set media_title = states.media_player.shield.attributes.media_title %}
{%- if media_title is defined %}
{%- if media_title != '' and media_title not in ['unknown','unavailable','none'] %}
{{ media_title }}
{% endif %}
{% endif %}
{% endif %}
media_content_type: >
{% if this.state not in ['unavailable','undefined','unknown','none','null', '0'] %}
{% set app = state_attr('sensor.shield_real_state', 'app_name') %}
{% if app is defined and app == 'plex' %}
{% if state_attr('media_player.plex_plex_for_android_tv_shield_android_tv', 'media_content_type') %}
{{ state_attr('media_player.plex_plex_for_android_tv_shield_android_tv', 'media_content_type') }}
{% endif %}
{% endif %}
{% endif %}