Media_player.template

what version of Home Assistant are you running?

Home Assistant 0.117.5

I don’t know why you get this errors. I’ve just started hass with following config:

- 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
      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"

and I don’t receive any error’s. The only thing I could suggest is that you remove all the files in custom_components\media_player_template and redownload the latest release from https://github.com/Sennevds/media_player.template/releases/tag/0.0.3

That’s exaclty what I done, twice: first time when I installed it and now after your suggestion.

Unfortunately the issue appears.

You also deleted the pycache folder

I tried also. Nothing changed.

I downgraded to 0.1 leaving the template config and now the issue is different:

Invalid config

The following integrations and platforms could not be set up:

* [media_player.media_player_template](https://github.com/Sennevds/media_player.template)

Please check your config and [logs](http://192.168.2.101:8123/config/logs).

Version 0.1 of my component has less options. You should use the latest version.
It works when I add it to my setup(hass 0.117.5) so the problem is somewhere else.
Could you try to install the latest version with the config I posted above and send me your log file?
The log file is in het config folder

Yes I tested 0.1 just to understand better the issue. Normally I always used 0.3 erasing pycache every ti,e

Mi setup is 0.117.6 so similar to yours.

Below the full steps I made.

  1. Deleted folder for media_player_template in custom_components and pychache folder in custom_components folder. Commented the media_player_template code.
  2. Reboot - No error in logs
  3. Copy pasted the 3 files from 0.3 in custom_components folder (/config/custom_components/media_player_template) : media_player.py - manifest.json and init.py.
    4: uncommented the following code:
media_player:
  - 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
        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"
  1. Checked config and reboot.
  2. Now in notification 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.

Here’s the log related:

2020-11-13 11:30:56 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for media_player_template which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

2020-11-13 11:30:56 ERROR (MainThread) [homeassistant.setup] Setup failed for template: No setup function defined.

2020-11-13 11:30:56 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of media_player_template. Setup failed for dependencies: template

2020-11-13 11:30:56 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform media_player_template.media_player: Could not set up all dependencies.

Here’s the config used:

Here’s the full log:

Thank you for your patience and your support

Thanks for the files. I’ve finally found the problem!. I’ve added following code to the manifest.json

"dependencies": ["template"],

for integration in hacs but apparantly this tries to initiate template as a integration.
For now change that line to

"dependencies": [],

I will check what I need to change to be compatible with hacs! Sorry it took me so long to find out!

1 Like

The issue is now gone with 0.4 :slight_smile:

Great work! I’m looking for a solution and I think this might be of great use. My goal is to create a media player that combined the volume attributes of other media players and gives an average number. But the important part is that when changing volume, the players linked to it need to change relatively.

Example:

Player A = 20% volume
Player B = 40% volume
This gives Player.template a volume attribute of 30%. When changing the volume to 31%, then all players need to add that difference relatively. So they don’t both go to 32%, but increase it to 21% and 41%.

Is this possible with this component?

Hmm this is a special case of course. I don’t think it’s currently possible to define 2 services to activate and you would need to have 2 different services because the volume_set service can only accept one entity(I think). But maybe I could change the code to accept multiple services like so:

set_volume :
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.player_a
      volume_level: {{  }}
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.player_b
      volume_level: {{  }}

And then use as volume level a template that calculates the volume level needed based on a sensor which holds the current main volume

edit:
So I just checked and following works:

set_volume:
  - service: input_number.set_value
    data:
      entity_id: input_number.volume_1
      value: "{{ volume + 1 }}"
  - service: input_number.set_value
    data:
      entity_id: input_number.volume_2
      value: "{{ volume + 2 }}"

volume is the variable between 0 and 1

1 Like

The integration is released to hacs!

1 Like

Hi,

I tested it and it works smoothy. Thank you!

Only one thing: when I turn on the device it can correctly take source info as template but the input_select source at start it empty while the tv-receiver will always start with a source of corse. Can it be implemented?

Below some screenshot

original device
image

template
image

You need to set the current_source_template to the right input

The issue was that the source had different names :slight_smile:

Hi,

any chance to have also fw re commands in ui?

This is my config:

  - platform: media_player_template
    media_players:
      televisionecucina:
        friendly_name: Televisione Cucina Template
        current_source_template: >
          {% if is_state('media_player.tv_cucina', 'off') %}
            off
          {% elif is_state('media_player.chromecast_cucina', 'playing') %}
            HDMI
          {% else %}
            TV
          {% endif %}
        value_template: >
          {% if is_state("media_player.tv_cucina", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          service: media_player.turn_on
          data:
            entity_id: media_player.tv_cucina
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.tv_cucina
        volume_up:
          service: media_player.volume_up
          data:
              entity_id: media_player.tv_cucina
        volume_down:
          service: media_player.volume_down
          data:
              entity_id: media_player.tv_cucina
        mute:
          service: media_player.volume_mute
          data:
              entity_id: media_player.tv_cucina
        play:
          service: media_player.media_play
          data:
              entity_id: media_player.chromecast_cucina
        pause:
          service: media_player.media_play_pause
          data:
              entity_id: media_player.chromecast_cucina
        stop:
          service: media_player.media_stop
          data:
              entity_id: media_player.chromecast_cucina
        next:
          service: media_player.media_next_track
          data:
              entity_id: media_player.chromecast_cucina
        previous:
          service: media_player.media_previous_track
          data:
              entity_id: media_player.chromecast_cucina
        inputs:
          TV:
            - service: remote.send_command
              data:
                entity_id: remote.rmini_cucina_remote
                command: b64:JgAaAA4JCRIMOggADJ8GZAYAAQgKxQsAAT0RAA0FAAAAAAAAAAAAAAAAAAA=
          HDMI:
            - service: remote.send_command
              data:
                entity_id: remote.rmini_cucina_remote
                command:
                  - b64:JgCEAFYfDh4ODw0QDR8cDw0RDRANEA0QDRANEA4PDg8NEBwQDRANHg4PDRAOAArKVx4OHg0QDRANHxwPDhANEA0QDRANEA0QDRAODw4PHBANEA0eDg8PDg8ACslXHw0eDg8NEA0fHA8OEA0QDRANEA0QDRAODw0QDRAcEA0QDh0ODw4PDgANBQAAAAA=
                  - b64:JgBMAFYfDR4NEA0QLCwNEA0QDRANEA0QDRANEA0QHB4cEA0eHBANAAraVh8OHQ0QDRAqLg4PDRAODw4PDRANEA0QDRAcHh0PDh0dDw0ADQUAAAAAAAAAAAAAAAA
                  - b64:JgBMAFYfDR4NEA0QLCwNEA0QDRANEA0QDRANEA0QHB4cEA0eHBANAAraVh8OHQ0QDRAqLg4PDRAODw4PDRANEA0QDRAcHh0PDh0dDw0ADQUAAAAAAAAAAAAAAAA
                  - b64:JgBMAFYfDR4NEA0QLCwNEA0QDRANEA0QDRANEA0QHB4cEA0eHBANAAraVh8OHQ0QDRAqLg4PDRAODw4PDRANEA0QDRAcHh0PDh0dDw0ADQUAAAAAAAAAAAAAAAA
                  - b64:JgB4AFYfDh4ODw0QKi4ODw0QDRANEA0QDRANEA0QGx8bEA4PDh4NEA0ACstWHw0fDRANECotDg8OEA0QDRANEA4PDRANEBsfGxAODw0fDg8NAArLVh8OHg0QDRAqLQ0QDg8OEA0PDhANEA0QDg8bHxsQDRANHw0QDQANBQ==
        title_template: >
            {% if is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Plex') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_title') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Netflix') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_title') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Spotify') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_title') }}
            {% else %}
              Live TV
            {% endif %}
        media_image_url_template : >
            {% if is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Plex') %}
              {{ state_attr('media_player.chromecast_cucina', 'entity_picture_local') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Spotify') %}
              {{ state_attr('media_player.chromecast_cucina', 'entity_picture') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Netflix') %}
              https://xxxx.xxxx.it/local/netflix.png
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Prime Video') %}
              https://xxxx.xxxx.it/local/amazonprime.png
            {% else %}
              https://xxxx.xxxx.it/local/antenna.png
            {% endif %}
        artist_template: >
            {% if is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Plex') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_artist') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Netflix') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_artist') }}
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Spotify') %}
              {{ state_attr('media_player.chromecast_cucina', 'media_artist') }}
            {% else %}
              Live TV
            {% endif %}
        media_content_type_template: >
            {% if is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Plex') %}
              tv_show
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Netflix') %}
              tv_show
            {% elif is_state_attr('media_player.chromecast_cucina', 'app_name' , 'Spotify') %}
              music
            {% else %}
              video
            {% endif %}

As you may see buttons are not there :

Template media player:
image

Chromecast media player:
image

Hmm strange I’ve just added next and previous in my test setup and it shows the buttons. Do you got any errors?

I’m giving this a go. I’m currently using the Universal Media Player to mash together my TV and receiver, and it is making me insane because I can’t customize the sources. I literally have two devices, an Xbox and an Apple TV, and I ultimately want to be able to tell Siri to switch to one or the other, and pick the correct inputs on both the TV and receiver when I do so. Hopefully this will achieve those aims–if not, maybe someone knows an easier way?

Works like magic, thank you so much for creating this! Wife and kids-approved!

1 Like