Media_player.template

I probably forgot to add a capability. Will check it tomorrow. The media cover is a problem I need to fix but don’t now how at this moment. For the artist name could you check the entity state in the developers tools?

I checked this 3 sensor and all report correct info

    title_template: "{{ state_attr('media_player.soggiorno', 'media_title') }}"
    album_template: "{{ state_attr('media_player.soggiorno', 'media_album_name') }}"
    artist_template: "{{ state_attr('media_player.soggiorno', 'media_artist') }}"

And the attributes off the media player itself does it has artist value?

I don’t understand :roll_eyes:

if you go to the developer tools and search for the media_player you created with my custom component this entity should have some attributes. Example for a chromecast media_player:

Sorry for the delay. I missed the post.

Below the status of the created media_player.

Hi @Sennevds, I’m looking to test out your component but having some issues installing it. Are your installation instructions still accurate? I still need to copy all the files from https://github.com/home-assistant/core/tree/dev/homeassistant/components/template into \custom_components\template directory?

I saw there is a manifest.json and __init__.py file in your repo. Should that replace the files in the \template\ directory?

Also, is there any way to set other attributes like entity_picture? I’m hoping to use your template player to show the cover art from the Steam game I’m currently playing.

you need to place the files in the following folder: {configfolder}/custom_components/media_player_template
Entity picture isn’t possible at this moment. Maybe if I have time this week I will integrate it

1 Like

Any update on the artist attribute?

hadn’t had the time to check this out. Hoping to have some time this week.

great! :slight_smile: I look forward for the updates

I’ve updated the repo. Artist and album works(but you need to set the media_content_type_template to music)
Entity_picture is set by using media_image_url_template

1 Like

Thanks for adding the feature! I defined the media_image_url_template for my Steam media player and the game image shows up. I tried adding the template media player with Universal media player , but it seems to have some problems pulling the entity picture. I think it’s a problem with Universal media player component, not with your component.

Do you know why template media player’s attribute is called entity_picture_local instead of entity_picture? That might be the reason why the entity picture is not picked up by the Universal media player.

Your template media player looks like this in my dashboard:

Media players have a switch if the picture you try to show is only locally available.
(for technical info: https://github.com/home-assistant/core/blob/fcdb54d8780900fb85e6c20d5382cfd13b69a0b3/homeassistant/components/media_player/init.py#L780-L801)
I didn’t implement this. So at this moment the picture it shows needs to be remotely available.

You steam media player looks nice. Is it the standard steam integration or did you do something special?

I use the mini-media-player custom lovelace card to display my media players. I’m also using the Steam component and setup some templates in your component to show the state, title, and entity picture.

- platform: media_player_template
  media_players:
    steam:
      friendly_name: Steam
      current_source_template: "{{ states('input_text.selected_source') }}"
      value_template: >-              
        {% if state_attr('sensor.steam_76561197977455441', 'game_image_main') != None %}
          on
        {% else %}
          off
        {% endif %}          
      title_template: "{{ state_attr('sensor.steam_76561197977455441', 'game') }}"
      album_template: "{{ state_attr('sensor.steam_76561197977455441', 'game') }}"    
      media_image_url_template: "{{ state_attr('sensor.steam_76561197977455441', 'game_image_main') }}"       
1 Like

Hi, It’s me again.

Please can you specify where I have to add "media_content_type_template "

This is my config now but it’s invalid:

- platform: media_player_template

    media_players:

      denon:

        friendly_name: Denon

        value_template: >

          {% if is_state_attr("remote.soggiorno", "current_activity", "Ascolta Spotify") -%}

            on

          {%- else -%}

            off

          {%- endif %}

        turn_on:

          service: remote.turn_on

          entity_id: remote.soggiorno

          data:

            activity: 'Ascolta Spotify'

        turn_off:

          service: remote.turn_on

          data:

            entity_id: remote.soggiorno

            activity: 'PowerOff'

        volume_up:

          service: remote.send_command

          data:

            entity_id: remote.soggiorno

            command:

                - VolumeUp

            device: 45938921

        volume_down:

          service: remote.send_command

          data:

            entity_id: remote.soggiorno

            command:

                - VolumeDown

            device: 45938921

        play:

          service: media_player.media_play

          data:

            entity_id: media_player.soggiorno

        pause:

          service: media_player.media_pause

          data:

            entity_id: media_player.soggiorno

        next:

          service: media_player.media_next_track

          data:

            entity_id: media_player.soggiorno

        previous:

          service: media_player.media_previous_track

          data:

            entity_id: media_player.soggiorno

        mute:

          service: remote.send_command

          data:

            entity_id: remote.soggiorno

            command:

                - Mute

            device: 45938921

        inputs:

          Spotify:

            service: remote.send_command

            data:

              entity_id: remote.soggiorno

              command:

                  - InputMediaPlayer

              device: 45938921

        # # album_art_template: "{{ states('input_text.album_art') }}"

        title_template: "{{ state_attr('media_player.soggiorno', 'media_title') }}"

        album_art_template: "{{ state_attr('media_player.soggiorno', 'entity_picture_local') }}"

        album_template: "{{ state_attr('media_player.soggiorno', 'media_album_name') }}"

        artist_template: "{{ state_attr('media_player.soggiorno', 'media_artist') }}"

        media_content_type_template: "music"

EDIT: maybe because it’s available only within HACS? But I searched for it and I didn’t found it the repository.

I will check your config tomorrow. I’ve created a pull request to add it to hacs but it hasn’t been merged. Did you download the latest version from github?

Edit:
I’ve just tested it myself and if I add media_content_type_template: "music" it works like expected

I copied the media_player_template folder inside my custom_components

and reboot.

Now I see this error message:

Invalid config

The following integrations and platforms could not be set up:

* template
* media_player_template.media_player

Please check your config and logs).

Could you give me the error in the log file?

Sure.

I have different error messages:

Logger: homeassistant.setup
Source: setup.py:138
First occurred: 0:19:07 (1 occurrences)
Last logged: 0:19:07

Setup failed for template: No setup function defined.


Logger: homeassistant.setup
Source: setup.py:118
First occurred: 0:19:07 (1 occurrences)
Last logged: 0:19:07

Unable to set up dependencies of media_player_template. Setup failed for dependencies: template


Logger: homeassistant.setup
Source: setup.py:280
First occurred: 0:19:07 (1 occurrences)
Last logged: 0:19:07

Unable to prepare setup for platform media_player_template.media_player: Could not set up all dependencies.