Media Player Universal source in overview

Hello,

Today I started to add a the media_player universal entity to my setup. One thing I can’t get to work is the current source displayed in the overview. I’ve setup a source_list based on an input_select and the current source based on the selected value (state) from the input_select.

I thought the overview (shown on picture below) would show the current selected source from the source_list but it’s actually showing the current selected source from the children.

How do I get Playstation on the spot of HDMI 1?

current_source

Relevant code:

...
attributes:
  source: input_select.tv_source_list
  source_list: input_select.tv_source_list|options
  ...

Thanks in advance

1 Like

EDIT: Scratch what i said before, there’s an easier way.


You need to defined the service to call to change the source.

...
    select_source:
      service: input_select.select_option
      data_template:
        entity_id: input_select.tv_source_list
        option: '{{ source }}'
...
    attributes:
      source: input_select.tv_source_list
      source_list: input_select.tv_source_list|options

the select_source section calls the action to change the input_select. The attribute section looks at the input select and updates based on it’s state.

And now that I see your other thread, I’m starting to gather the whole picture.

You’ll need to have a list of services. 1 that changes your media player source, one that changes the input_select.

...
    select_source:
      - service: input_select.select_option
        data_template:
          entity_id: input_select.tv_source_list
          option: {{ source }}
      - service: media_player.select_source
        data_template:
          entity_id: media_player.xxx
          source: >
            {% mapper = {
                'Mediabox':'HDMI 1',
                'Chromecast':'HDMI 2/MHL',
                'Apple TV':'HDMI 3',
                'Playstation 4':'HDMI 4' } %}
            {{ mapper[source] if source in mapper else 'HDMI 1' }}
...
    attributes:
      source: input_select.tv_source_list
      source_list: input_select.tv_source_list|options
3 Likes

Thanks a lot for your reply and checking out the other thread I started. This is indeed the solution where I was looking for. The only thing I changed was I moved the select_source code to a script because select_source only accept 1 service.

1 Like

Hmm, that’s a limitation of that component. That should be changed. Template switches can have more than 1 service, no reason the universal media player shouldn’t either.

Will this also work for HomeKit or just in Lovelace?

I don’t know much about homekit. Sorry. I would assume yes because you’re creating a new media_player and ignoring the one crated by your tv integration.

Hi Petro, I think I’m almost there. Created the following universal mediaplayer

  - platform: universal
    name: Beamer
    children:
      - media_player.optoma_beamer
    commands:
        select_source:
          - service: input_select.select_option
            data_template:
              entity_id: input_select.beamer_source_list
              option: {{ source }}
          - service: media_player.select_source
            data_template:
              entity_id: media_player.optoma_beamer
              source: >
                {% mapper = {
                    'PS4':'DIGITAL 1',
                    'CCBeamer':'DIGITAL 2',
                    'RGB':'RGB 1'} %}
                {{ mapper[source] if source in mapper else 'DIGITAL 1' }}
        attributes:
          source: input_select.beamer_source_list
          source_list: input_select.beamer_source_list|options 

and a input_select called beamer_source_list with the following options PS4, CCBeamer & RGB. But when I restart Home Assistant i get the following error “Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘source’, None)])” in “/config/mediaplayers.yaml”, line 19, column 0” whch points to an error for the option: {{ source }}

Yah, that needs to be in quotes

              option: "{{ source }}"

or use the multiline indicator (>)

              option: >
                {{ source }}
1 Like

Almost there :slight_smile: Thanks for the help so far

I’m now getting an error on the select_source attribute of the universal media_player integration. It expect a dictionary and to me, it looks like it gets a dictionary

invalid config for [media_player.universal]: expected a dictionary for dictionary value @ data[‘commands’][‘select_source’]. Got [OrderedDict([(‘service’, ‘input_select.select_option’), (‘data_template’, OrderedDict([(‘entity_id’, ‘input_select.beamer_source_list’), (‘option’, ‘{{ source }}’)]))]), OrderedDict([(‘service’, ‘media_player.select_source’), (‘data_template’, OrderedDict([(‘entity_id’, ‘media_player.optoma_beamer’), (‘source’, “{% mapper = {\n ‘PS4’:‘DIGITAL 1’,\n ‘CCBeamer’:‘DIGITAL 2’,\n ‘RGB’:‘RGB 1’} %}\n{{ mapper[source] if source in mapper else ‘DIGITAL 1’ }}\n”)]))])]. (See ?, line ?).

will post the complete code if I got it working for others

You probably have to separate that into a script if it doesn’t accept more than one service.

script:
  change_source:
    sequence:
           - service: input_select.select_option
            data_template:
              entity_id: input_select.beamer_source_list
              option: >
                {{ source }}
          - service: media_player.select_source
            data_template:
              entity_id: media_player.optoma_beamer
              source: >
                {% mapper = {
                    'PS4':'DIGITAL 1',
                    'CCBeamer':'DIGITAL 2',
                    'RGB':'RGB 1'} %}
                {{ mapper[source] if source in mapper else 'DIGITAL 1' }}
  - platform: universal
    name: Beamer
    children:
      - media_player.optoma_beamer
    commands:
        select_source:
          service: script.change_source
          data_template:
            source: "{{ source }}"
        attributes:
          source: input_select.beamer_source_list
          source_list: input_select.beamer_source_list|options 

Yes! Thank you I finally got it working!

Solution: How to create aliases for sources of mediaplayer

  1. add your media_player config
    for example:
  - platform: pjlink
    name: Optoma Beamer
    host: 192.168.0.212
  1. create an input_select to store the aliases for the sources
    for example:
input_select.beamer_source_list
  options:
    - PS4
    - CCBeamer
    - RGB
  editable: true
  friendly_name: beamer_source_list
  1. create a universal media_player as a proxy for the original media_player, map the commands you want to proxy. And add the configuration for select source. Which needs to be a script, since you need to call 2 services and supply the selected source as a variable.
    for example (left out all other commands for brevity)
  - platform: universal
    name: Beamer
    children:
      - media_player.optoma_beamer #the original mediaplayer
    commands:
      select_source:
        service: script.change_source # the script we create in step 4
        data_template:
          source: "{{ source }}" # supply the source as a variable
    attributes:
      source: input_select.beamer_source_list #get the source from the input_select created in step 2
      source_list: input_select.beamer_source_list|options #get the possible sources from the input_select created in step 2
  1. create a script to change the selected source on the input_select and select the new source on the mediaplayer
    for example:
change_source:
  sequence:
  - service: input_select.select_option
    data_template:
      entity_id: input_select.beamer_source_list #the input_select created in step 2
      option: >
       {{ source }}
  - service: media_player.select_source
    data_template:
      entity_id: media_player.optoma_beamer #the original media_player
      source: > 
        {% set mapper = { #this is a variabe to map the aliases to the original sources of the original mediaplayer
          'PS4':'DIGITAL 1',
          'CCBeamer':'DIGITAL 2',
          'RGB':'RGB 1'} %}
         {{ mapper[source] if source in mapper else 'DIGITAL 1' }}    
  1. add a new media control card (or other) to see the proxy mediaplayer with the aliases for the services
    alias for mediaplayer

Many thanks to @petro for figuring this out and explaining it to me

5 Likes

Since you guys seem to using the universal media player for source selection, can you give my media stack component a try?

Still in early stages, but I think it’s already quite useable for me. You should be able to add it as en extra repo in HACS.

2 Likes

will try, as soon as i get my instance running again

Hey everyone,

I am trying to create a remote that publishes the source selected in the drop-down menu, but I can’t access the variable that holds that information.

My goal is to select a source from the source_list and have that source selection broadcasted via MQTT.

I tried:

    select_source:
      service: mqtt.publish
      data:
        topic: 'home/livingroom/hifi/input/set'
        qos: 2
        payload_template: "{{source}}"
  attributes:
    state: switch.hifi
    volume_level: input_number.hifi_volume
    is_volume_muted: switch.hifi_mute
    source: input_select.hifi_input
    source_list: input_select.hifi_input|options

Thanks in advance everyone!

can’t help without a full configuration. If that’s your full configuration, you’re spacing is way off and you’re missing the platform. You’d also need to separate the select source service into a script and also select the correct input from the input_select.

This has been immensely helpful, thank you everyone. I’ve got this working except there’s one odd thing: the original source name (not my alias via the mapper) still shows up in the media control popup and in Lovelace cards (see the “CD” in the upper right, which I’ve aliased to “House Audio” in the dropdown via the method described in this thread):

image

And in the Lovelace view (as you can see, the drop down shows the correct “aliased” names, but the gray text under the entity name is still showing the original source name):

image

It’s not a dealbreaker, it’s just not a great user experience.

I thought maybe this was the “media title” attribute, but overriding that in the universal player had no effect. Here’s my current universal player configuration (the relevant bits, anyway):

- platform: universal
  name: Patio
  attributes:
    source_list: input_select.denon_sources_zone_2|options
    source: input_select.denon_sources_zone_2
    media_title: input_select.denon_sources_zone_2
    state: media_player.patio_receiver
    volume_level: media_player.patio_receiver|volume_level
    is_volume_muted: media_player.patio_receiver|is_volume_muted
  children:
    - media_player.patio_receiver
  commands:
    ...
    select_source:
      service: script.select_denon_source_zone_2
      data:
        source: "{{source}}"
   ...

And the associated source selection script:

select_denon_source_zone_2:
  alias: Select Denon Source Zone 2
  sequence:
    - service: input_select.select_option
      data_template:
        entity_id: input_select.denon_sources_zone_2
        option: "{{ source }}"
    - service: media_player.select_source
      data_template:
        entity_id: media_player.patio_receiver
        source: >
          {% set mapper = {
            'House Audio':'CD',
            'TV Audio':'MEDIA PLAYER' }  %}
          {{ mapper[source] if source in mapper else 'TV AUDIO' }}
1 Like

This thread is super helpful! To rogersmj, looks like your last line doesn’t match anything else above. The earlier example implies that you should change the last line to

{{ mapper[source] if source in mapper else 'MEDIA PLAYER' }}

Guys I am trying to add source_list, but it does not show. Any ideas?

- platform: universal
  name: NAD C388
  commands:
    turn_on:
      service: switch.turn_on
      target:
        entity_id: switch.nadrs232_power
    turn_off:
      service: switch.turn_off
      target:
        entity_id: switch.nadrs232_power
    volume_up:
      service: button.press
      target:
        entity_id: button.nadrs232_vol_up
    volume_down:
      service: button.press
      target:
        entity_id: button.nadrs232_vol_down
    volume_mute:
      service: switch.turn_on
      target:
        entity_id: switch.nadrs232_mute
  attributes:
    is_volume_muted: switch.nadrs232_mute
    state: switch.nadrs232_power
    volume_level: number.nadrs232_current_volume
    source: input_select.nad_source_list
    source_list: input_select.nad_source_list|options
  device_class: media_player
  unique_id: c388mediaplayer