If so, you should take a look at the conditional_media template.
In fact, rather than focusing on conditional_media, you should take a closer look at the other included templates: base_media and media.
base_media
The is_youtube and entity_picture variables must be defined among the variables of the base_media template.
variables:
media_on: >
[[[ return !entity || ['playing', 'paused'].indexOf(entity.state) !== -1; ]]]
media_off: >
[[[ return !entity || ['off', 'idle', 'standby', 'unknown', 'unavailable'].indexOf(entity.state) !== -1; ]]]
# entity_picture: >
# [[[ return !entity || entity.attributes.entity_picture; ]]]
entity_picture: >
[[[
if (!entity || entity.attributes.entity_picture === undefined) {
return entity.attributes.title_image;
}
return entity.attributes.entity_picture;
]]]
is_youtube: >
[[[
let is_youtube = entity?.attributes?.app_id === 'com.google.ios.youtube',
sensor = this?._config?.triggers_update,
media_title = entity?.attributes?.media_title,
watching_title = states[sensor]?.attributes?.title;
if (is_youtube && media_title === watching_title) {
return true;
}
]]]
media
media:
template:
- base
- base_media
styles:
custom_fields:
icon:
- width: 70%
- margin-left: 2%
- fill: '#9da0a2'
- display: >
[[[
if (variables.is_youtube) {
return `none`;
}
else {
return variables.media_off || variables.entity_picture === undefined
? 'initial'
: 'none';
}
]]]
card:
- background-color: none
- background-size: cover
- background-position: center
- background-image: >
[[[
if (variables.is_youtube) {
return `linear-gradient(0deg, rgba(0,0,0,.8) 0%, rgba(0,0,0,0) 100%), url(${states[this._config?.triggers_update].state})`;
} else {
return variables.media_on && variables.entity_picture === undefined
? 'linear-gradient(0deg, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0.8) 100%)'
: variables.media_off
? 'linear-gradient(0deg, rgba(115, 115, 115, 0.2) 0%, rgba(115, 115, 115, 0.2) 100%)'
: `linear-gradient(0deg, rgba(0,0,0,.8) 0%, rgba(0,0,0,0) 100%), url(${variables.entity_picture})`;
}
]]]
conditional_media
conditional_media:
aspect_ratio: 1000/996
template:
- base
- base_media
- icon_play_pause
variables:
i: >
[[[
if (entity) {
let data = entity.attributes.data;
return data === undefined || Math.floor(Math.random() * (data.length - 1)) + 1;
}
]]]
styles:
card:
- background: rgba(115, 115, 115, 0.2) center center/cover no-repeat
# - background-image: &media_background_image >
- background-image: >
[[[
if (entity) {
if (variables.is_youtube) {
return `url(${states[this._config?.triggers_update].state})`;
} else {
let data = entity.attributes.data;
return data && (data[variables.i].fanart || data[variables.i].poster)
? `url("${data[variables.i].fanart}"), url("${data[variables.i].poster}")`
: `url("${variables.entity_picture}")`;
}
}
Since I made a number of modifications from the original, there may be some differences.