Hey @Mattias_Persson I’m having issues trying to get the primary Media button to display my Plex playing any media. At the moment if I have my Plex playing a video, the primary Media button only displays the recently added thumbnail and the swipe page shows the Plex button is playing/paused. This is what my code currently has:
Template.yaml
####################################################
# #
# SELECT #
# #
####################################################
- select:
- name: conditional_media
state: >
{% set recently_added = 'Recently Added' %}
{% set paused_timeout_minutes = 15 %}
{% set media_players = [
states.media_player.plex_plex_for_lg_lg_oled55b6p_u,
states.media_player.sovrum,
states.media_player.spotify,
states.media_player.kok ] %}
{% macro media(state) %}
{% set state = media_players | selectattr('state','eq',state) | list %}
{% set last_changed = recently_added if state | length == 0 else state | map(attribute='last_changed') | list | max %}
{{ state | selectattr('last_changed','eq', last_changed) | map(attribute='name') | list | join }}
{% endmacro %}
{% set playing = media_players | selectattr('state','eq','playing') | list %}
{% set timeout_playing = False if playing | length == 0 else
(as_timestamp(now()) - as_timestamp(playing | map(attribute='last_changed') | list | max)) < paused_timeout_minutes * 60 %}
{% set paused = media_players | selectattr('state','eq','paused') | list %}
{% set timeout_paused = False if paused | length == 0 else
(as_timestamp(now()) - as_timestamp(paused | map(attribute='last_changed') | list | max)) < paused_timeout_minutes * 60 %}
{% if playing %}
{{ media('playing') if timeout_playing else media('paused') if timeout_paused else media('playing') }}
{% elif paused %}
{{ media('paused') if timeout_paused else recently_added }}
{% else %}
{{ recently_added }}
{% endif %}
options: >
{% set recently_added = ['Recently Added'] %}
{% set media_players = [
states.media_player.plex_plex_for_lg_lg_oled55b6p_u,
states.media_player.sovrum,
states.media_player.spotify,
states.media_player.kok ] %}
{{ recently_added + media_players | map(attribute='name') | list }}
select_option:
service: select.select_option
target:
entity_id: select.conditional_media
data:
option: >
{{ option }}
- name: vacuum_speed
state: >
{% set fan_speed = state_attr('vacuum.morty', 'fan_speed') %}
{{ iif(fan_speed == None, 'Standard', fan_speed) }}
options: >
{% set fan_speed_list = state_attr('vacuum.morty', 'fan_speed_list') %}
{{ iif(fan_speed_list == None, ['Standard'], fan_speed_list) }}
select_option:
service: vacuum.set_fan_speed
target:
entity_id: vacuum.morty
data:
fan_speed: >
{{ option }}
- name: hdmi_lg
state: >
{% set source = state_attr('media_player.lg_webos_smart_tv', 'source') %}
{{ iif(source == None, 'HDMI', source) }}
options: >
{% set source_list = state_attr('media_player.lg_webos_smart_tv', 'source_list') %}
{{ iif(source_list == None, ['HDMI'], source_list) }}
select_option:
service: media_player.select_source
target:
entity_id: media_player.lg_webos_smart_tv
data:
source: >
{{ option }}
ui-lovelace.yaml
#################################################
# #
# MEDIA #
# #
#################################################
- type: grid
title: Media
view_layout:
grid-area: media
columns: 1
cards:
- type: custom:swipe-card
parameters:
speed: 550
spaceBetween: 40
threshold: 5
cards:
- type: horizontal-stack
cards:
- type: conditional
conditions:
- entity: select.conditional_media
state_not: LivingRoom
- entity: select.conditional_media
state_not: Bedroom
- entity: select.conditional_media
state_not: Spotify
- entity: select.conditional_media
state_not: Kök
card:
type: custom:button-card
entity: sensor.plex_recently_added
name: Recently Added
tap_action:
action: none
template:
- conditional_media
- icon_plex
- type: conditional
conditions:
- entity: select.conditional_media
state: LivingRoom
card:
type: custom:button-card
entity: media_player.plex_plex_for_lg_lg_oled55b6p_u
template:
- conditional_media
- icon_plex
- type: conditional
conditions:
- entity: select.conditional_media
state: Bedroom
card:
type: custom:button-card
entity: media_player.sovrum
template:
- conditional_media
- icon_apple_tv
- type: conditional
conditions:
- entity: select.conditional_media
state: Spotify
card:
type: custom:button-card
entity: media_player.spotify
template:
- conditional_media
- icon_spotify
- type: conditional
conditions:
- entity: select.conditional_media
state: Kök
card:
type: custom:button-card
entity: media_player.kok
template:
- conditional_media
- icon_nest_mini
- type: grid
columns: 2
cards:
- type: custom:button-card
entity: media_player.plex_plex_for_lg_lg_oled55b6p_u
name: Living Room
template:
- media
- icon_plex
- type: custom:button-card
entity: media_player.sovrum
name: Bedroom
template:
- media
- icon_apple_tv
- type: custom:button-card
entity: media_player.spotify
name: Spotify
template:
- media
- icon_spotify
- type: custom:button-card
entity: media_player.kok
name: Nest Mini
template:
- media
- icon_nest_mini
Thanks.