Input_select value in "media_player_play_media" "entity_id"

Hello,

i try to use in the entity for my “media_player_play_media” my inputselect value.

entity_id: >-
                            {{
                            states("input_select.choose_media_player_plex_widget")
                            }}'

because I want to choose where he should play the file for me.

my input_select has the names of the media_player entity

input_select:
  choose_media_player_plex_widget:
    name: Wo soll es abgespielt werden
    options:
      - media_player.firetv_kueche
      - media_player.plex_shield
      - media_player.plex_plex_for_android_tv_aftmm_2
    initial: media_player.plex_shield
    icon: mdi:panda

when i now check if he changes the value of input_select everything is fine, for example actually you see here media_player.firetv_kueche .

here is my code for the media_player_play_media

tap_action:
                        action: call-service
                        service: media_player.play_media
                        service_data:
                          entity_id: >-
                            {{
                            states("input_select.choose_media_player_plex_widget")
                            }}
                          media_content_type: movie
                          media_content_id: >-
                            [[[ return '{ "library_name":' + ' "Filme",' + '
                            "title": ' +  ' "' +
                            entity.attributes.data[variables.i].title + '" ' +  
                            '}';  ]]]    

now i make a button under the input_select where i can press PLAY (Abspielen)

but he makes nothing, i get no error, but he dont play anything, when i only enter the direct entity name of the player “media_player.firetv_kueche” it works well, but then i cant choose the source player.

or need i a automation for it?

THX

Of the core Lovelace cards, only the markdown card accepts templates.

If you want tu use templates in other core Lovelace cards you have to use this:

1 Like

i tried it with the custom:button-card , but no luck, there are templates supported or

That was impossible to tell as you did not show the card type. And you are using a jinja template when the custom button card only supports JavaScript, like you did for your media_content_id

https://github.com/custom-cards/button-card#javascript-templates

1 Like

yeah with the cutom:button-card i tried to use this code:

|
                          [[[ return  entity.select_rooms; ]]]

with this i get the name, but i need the state, but i dont know how to get the state

i tried

 |
                          [[[ return states['entity.select_rooms'].state ]]]```

but no luck

What about:

[[[ return states['input_number.select_rooms'].state ]]]
2 Likes

almost, this did it :slightly_smiling_face:

states['input_select.select_rooms'].state

thank you

@tom_l

okay, one problem is still there, i had the input_select and the play button in one popup, when i now change the room (device) in input_select, the value is saved and dont refresh after change the room.

i must close and reopen the popup and then it works.

i tried it with triggers_update: all or triggers_update with the entitie of the input_select

triggers_update: 
 - input_select.select_rooms

but it dont works, gives a way to refresh it ?

here the complete card:

 - type: custom:button-card
                      triggers_update: all
                      entity: input_select.select_rooms
                      show_name: true
                      show_icon: false
                      show_state: false
                      tap_action:
                        action: call-service
                        service: media_player.play_media
                        service_data:
                          entity_id: >-
                            [[[ return 'media_player.' + 
                            states['input_select.select_rooms'].state ]]]
                          media_content_type: movie
                          media_content_id: >-
                            [[[ return '{ "library_name":' + ' "Filme",' + '
                            "title": ' +  ' "' +
                            entity.attributes.data[variables.i].title + '" ' +  
                            '}';  ]]]    
                      style: |
                        ha-card {
                                
                                height: 50px!important;
                                text-align: left;
                                font-weight: light !important;
                        } 
                      icon: mdi:home-search
                      name: Abspielen

and the input_select card

- type: entities
                      entities:
                        - entity: input_select.select_rooms
                          icon: mdi:play-network

i try the way over variables:

             variables:
                var_input_select: >-
                    [[[ 
                      return 'media_player.' +  states['input_select.select_rooms'].state
                    ]]]

hmmm it i get the value from the variable but it doesnt refresh on change of the input_select, same problem as above

 >-
                  [[[ return [variables.var_input_select] ]]]

i tried it with the config-template-card, but no luck, the same problem he doesnt refresh the card after i changed the input_select…

test

type: custom:config-template-card
variables:
  - states['input_select.test'].state
entities:
  - ${vars[0]}
card:
  type: button
  entity: ${vars[0]}
  name: ${[vars[0]].state}

can no one help?
with this problem its impossible to use a inout_select card for a player choose

@thomasloven

i tried now different cards, in my home page, i added two cards, one entity and one button, in the button i define the input_select.set_options in a tap_action, when i click, the entity card on the same home page, the entity card changes. it WORKS.

works

BUT when i put the same code in the browser_mod popup, it dont works. he doesnt change the entity, its the same code, i think its a browser:mod bug.