Media_player.template

hey thanks for responding @Mr.ToR . Below i have shared the state attrubites of both android_tv and android_tv_adb media players.

Output of media_player.android_tv

volume_level: 0.019999999552965164
is_volume_muted: false
media_content_id: 
media_duration: 281.52
media_position: 0.707
media_position_updated_at: 2022-09-12T17:59:14.792282+00:00
media_title: Luis Fonsi - Despacito ft. Daddy Yankee
media_artist: Luis Fonsi
app_id: 2C6A6E3D
app_name: YouTube
entity_picture_local: null
friendly_name: Android TV
supported_features: 152511

Output of media_player.android_tv_192_168_0_137

source_list: com.google.android.inputmethod.latin, com.android.systemui, com.google.android.tv.remote.service, com.google.android.gms.persistent, com.android.providers.tv, com.google.process.gservices, com.xiaomi.android.tvsetup.partnercustomizer, com.google.android.tvrecommendations, com.mitv.tvhome.atv, YouTube, Google Cast, Android TV Launcher, com.google.android.katniss:interactor, com.google.android.partnersetup, com.miui.tv.analytics, com.googlecode.eyesfree.setorientation, com.google.android.gms, com.yablio.sendfilestotv, de.cyberdream.androidtv.notifications.google, SonyLIV, Play Store, com.google.process.gapps, android.process.media, com.android.vending:background, dex2oat
volume_level: 0.02
is_volume_muted: false
app_id: com.google.android.youtube.tv
app_name: YouTube
source: YouTube
adb_response: null
hdmi_input: null
entity_picture: /api/media_player_proxy/media_player.android_tv_192_168_0_137?token=3ead231ce92cdf211150aec37baf99c25ee18341579015f6c2c579a5f0cbbb43&cache=1663005651.919918
friendly_name: Android TV 192.168.0.137
supported_features: 23997

what i want to merge :
i want to have all the media_player.android_tv_192_168_0_137 attributes and in addition add few attributes of media_player.android_tv

reason: media_player.android_tv_192_168_0_137 does not allow to seek peek forward or backward and also it has no attribute to show what song is playing(media_title)
hope you could help me get this

OK, I’ll try to help you get started on this.

First let’s start by creating your template media player.
You can start with something like this:

media_player:
  - platform: media_player_template
    media_players:
      android_tv2:
        unique_id: media_player.android_tv2
        friendly_name: "Android TV2"
        device_class: tv

Now let’s set how your new media player will obtain its power state (on/off/unavailable/etc):
value_template is the parameter how your new media_player presents its power state.

        value_template: "{{ states('media_player.android_tv_192_168_0_137') }}"

You see, if you type the above line (the part between double quotes) to: developer tools->template->template editor, you should be able to see in real time what value your android_tv_192_168_0_137 is providing. Also you are providing that to value_template parameter of your new media_player. That’s what the above line does basically.

You can also type {{ states.media_player.android_tv_192_168_0_137}} to see everything it provides. And you can get a specific value, such as for exampple the source attribute like this
{{states.media_player.android_tv_192_168_0_137.attributes.source}}

Since your new media player can correctly display the power state, now let’s set what your new player should do when you change the power setting:
You need to set the turn_on: and turn_off: actions of your new media_player.
turn_on and turn_off actions will be calling or triggering a service. You can check how the services work in: Developer tools-> services. Select a service and see what it will do there and test if your service action works.

In your case, you need to set the power of a media_player entity or device. In Developer tools-> services, look for something relevant;
Let’s try the service ‘Media player: Turn on’, select the service then choose your device or entitiy. After you do so, you can check if it works by clicking ‘call service’. If it works, click ‘go to yaml mode’.
You should be seeing something like:

service: media_player.turn_on
data: {}
target:
  entity_id: media_player.android_tv_192_168_0_137

Let’s use that service for what your new template media_player will do for the turn_on action.

        turn_on:
          service: media_player.turn_on
          data: {}
          target:
            entity_id: media_player.android_tv_192_168_0_137

Now do the same for turn_off.

so far we have:

media_player:
  - platform: media_player_template
    media_players:
      android_tv2:
        unique_id: media_player.android_tv2
        friendly_name: "Android TV2"
        device_class: tv

        value_template: "{{ states('media_player.android_tv_192_168_0_137') }}"
        turn_on:
          service: media_player.turn_on
          data: {}
          target:
            entity_id: media_player.android_tv_192_168_0_137
        turn_off:
          service: media_player.turn_off
          data: {}
          target:
            entity_id: media_player.android_tv_192_168_0_137

You now have a media player that can receive and control power.

I believe you can now go through with all the other parts of the media player template configuration with this method.

Also, this thread has examples for all the parts you need.

Check this YouTube video for better understanding how templates work:
Home Assistant Templates - A Beginner’s Guide

Try to make your own configuration, checking each part step by step. Then ask about specific problems you might run into about a part of your configuration.

I hope this helps.

2 Likes

thanks for the response, i understand what you have explained but how do i add all the existing attributes of the media_player.android_tv_192_168_0_137 in custom template media player?
for example entity_picture attribute ?

did you read https://github.com/Sennevds/media_player.template

Check the implemented features in media_player.template.
entity_picture attribute is probably what your android device provides. As you can see from the examples, you can link it to an appropriate feature of the media_player.template.

Like I said, do not jump to the pictures. First get a simple media_player working and start adding features to it slowly. First get power to work, then add next/previous etc. Did you get a basic player working?

Did you check the documentation and this thread? There are multpile examples.
Which example are you trying or taking advantage of?
check post #64 on this thread for example.

I don’t think anyone would write you a template config for you.
However, people are pretty helpful here in general especially about helping one to learn how to do stuff, but you have to do the reading. Usually best help is just a pointer to a feature or some documentation.

I believe I gave you a very detailed and helpful outline to get you started.
First get yourself to be able to make the volume to work on your basic template media player for example. Follow my post about using a feature of the media_player.template and how you can assign values to it or howto get the template to control something with a service.

1 Like

I noticed that this is marked as no longer maintained.
Is it still working ? Has anyone come across an alternative ?

The universal media player integration is … OK … but i cant seem to find a way to make it display an image.

1 Like

I haven’t posted a update so github badge shows it as unmaintained. I still use it myself and it still works for me.

1 Like

Thanks!

So its not so much that its unmaintained, more that maintenance hasnt been required

Some months ago there was an update that crippled the medial_player.template but @Sennevds quickly fixed it. The only update you might see at some point might be the mediabrowser feature since I believe that is the only thing missing in this awesome media_player.template.

You might be able to merge your media_player.template with universal media player to add the mediabrowser feature… maybe (i’m not sure). However, I believe the universal media player only merges media players so it can not do what media_player.template can do.

1 Like

This is incredibly useful. I have a complex setup and Universal Media Player, although it worked ok, was a configuraiton mess. A few hours after I discovered this component my system is elegent and more reliable. Thank you!

Thanks. It’s far from feature complete but does what it needs to do :blush:

Hi all,

Need some help with using mqtt.publish on the template. Am trying to control a Lyngdorf amplifer, which accepts commands via TCP control.

The workflow is to get media_player_template to mqtt_publish various commands into the tdai/tcp topic, where it will get picked up by a Node-RED flow (which pushes the topic payload into a TCP request node.

However, the mqtt.publish commands doesn’t work, and the tdai/tcp sensor remains unknown. Any idea why? The Node-RED flow works when I trigger a payload via script.

Thank you! Happy to share my Node-RED flow if needed.

media_player:
  - platform: media_player_template
    media_players:
      tdai_1120:
        friendly_name: TDAI-1120
        device_class: receiver
        current_source_template: "{{ states('input_text.selected_source') }}"
        value_template: >
          {% if is_state("binary_sensor.tdai_powerstatus", "on") -%}
            on
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          service: mqtt.publish
          data:
            topic: "tdai/tcp"
            payload: "!ON"
        turn_off:
          service: mqtt.publish
          data:
            topic: "tdai/tcp"
            payload: "!OFF"
        volume_up:
          service: mqtt.publish
          data:
            topic: "tdai/tcp"
            payload: "!VOLUP"
        volume_down:
          service: mqtt.publish
          data:
            topic: "tdai/tcp"
            payload: "!VOLDN"
        inputs:
          source 1:
            service: input_boolean.turn_on
            data_template:
              entity_id: input_boolean.source_1
          source 2:
            service: input_boolean.turn_on
            data_template:
              entity_id: input_boolean.source_2

EDIT: enabled MQTT debug - see that there was an error when using /tdai/tcp as the topic. Using /tdai fixed it (but I’ve no idea why that’s the case!)

2023-02-20 23:15:25.489 INFO (MainThread) [homeassistant.helpers.script.tdai_1120] TDAI-1120: Running media_player_template script
2023-02-20 23:15:25.490 INFO (MainThread) [homeassistant.helpers.script.tdai_1120] TDAI-1120: Executing step call service
2023-02-20 23:15:25.493 ERROR (MainThread) [homeassistant.helpers.script.tdai_1120] TDAI-1120: Error executing script. Invalid data for call_service at pos 1: MQTT topic name/filter must not contain control characters. for dictionary value @ data['topic']

Hi all!
This integration is great, but I noticed it is missing some features.
Because it is no longer maintained, I decided to create a new one based on the original:

Template Media Player supports the definition of arbitrary attributes and all of the available services in the media_player domain. I also added the option to define a global template for common variables and the possibility to specify an entity for the browse_media functionality.

The integration currently can only be installed using the custom repository option in HACS, but I plan to submit it to the HACS default repository.
I’d love for some of you to check it out and feedback is very welcome!

PS: Props to @Sennevds for the original idea and implementation!

You can always create pr’s. I’m still using it but I don’t change it because I don’t need additional features if someone makes a PR and I have time I will review it and merge it.

Hi @EuleMitKeule, your project seems interesting. However, you’re wrong about this project not being maintained. Infact, I can confidently say that it is actually maintained very well and I feel very safe knowing it will be quickly fixed if some problem arises due to a Home Assistant update in the future.

Also, this project has matured quite well since it was released 3 years ago. Your global template idea seems interesting but it is not critical and does not seem to be a reason to switch over. There are already many people using @Sennevds’s media_player.template and I don’t think that there is an apparent need for any additional features.

Additionally your configuration sceme is not compatible with @Sennevds’s media_player.template which is not making it easier for people to try your template. Many people are already happily used to how it is and there are many examples already on this forum.

There is already a community of people using this template. If you want to have your own template no one can stop you but if you think there is something missing in this template, everyone would appreciate it if you add that feature to this template with a PR than re-making the same thing with a different configuration.

Hey, thanks for the feedback! The reason I deduced this project was not maintained anymore is because the maintainer says so in the project’s Readme, and because there was an open PR from earlier this year that stood uncommented.
Therefore I thought it would be less work and would have a higher chance of being useful to other people if I just start a separate project.

About the original project not needing additional features: The only reason I started to work on this, was because for my use case (combining webOS, Android Debug Bridge, Chromecast, Plex and Spotify into a single entity for my TV) I had to be able to provide an entity for browse media and needed to define more attributes and services like shuffle and repeat that are missing in media_player.template.

About the breaking changes: You are right, this is something that could be improved upon. While the configuration is mostly identical, I think I could implement additional optional aliases for the configuration keys, so that the config can be used interchangeably. I do think though that the new keys improve the usability, since they are named exactly as the actual attributes and services defined by the media_player domain.

I guess I could create a PR, but would it be accepted though? Would I have to split up all the changes and added features into separate PRs? Also I plan to add more features like the ability to specify the supported features via templates in the future, and if @Sennevds does not have enough time to maintain this, I’m not too sure if this would be the best way.
Also to be frank, I reeeeeeally don’t like that there is a dot in the repo name… :grinning_face_with_smiling_eyes:

I don’t think you have a thread for your template in the forum. make a page announcing your project and post a sample configuration. You can help people there about configuration and features there. I understand your announcement on this page but any further communiaction about your project should be on your templates own thread. Also, please consider making your configuration sceme compatible with this template. It will make it easy for people to try. I’ll post my configuration and you’ll understand. good luck.

#--------------------------------------------------------------------------
#----- SONY Audio Video Receiver ------------------------------------------
#--------------------------------------------------------------------------
media_player:
  - platform: media_player_template
    media_players:
      receiver:
        unique_id: media_player.receiver
        friendly_name: "Sony Audio-Video Receiver"
        device_class: "Set-top box"
        #device_class: receiver
#       --------------------------------------------
        value_template: >
          {%- if is_state("switch.avr_power", "on") -%}
            {%- if is_state("sensor.avr_source", "Google TV") -%}
              {%- if states('media_player.google_tv_4k')=="unavailable" or
                    states('media_player.google_tv_4k')=="unknown" or
                    states('media_player.google_tv_4k')=="buffering" or
                    states('media_player.google_tv_4k')=="off" -%}
                on
              {%- else -%} 
                {{ states('media_player.google_tv_4k') }} 
              {%- endif -%}            
            {%- else -%}
              {%- if states('media_player.str_dn1080_2')=="unavailable" or
                    states('media_player.str_dn1080_2')=="unknown" or
                    states('media_player.str_dn1080_2')=="off" -%}
                on
              {%- else -%} 
                {{ states('media_player.str_dn1080_2') }} 
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          - service: script.turn_on_avr
            data: {}
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.avr_off
#       --------------------------------------------
        current_sound_mode_template: "{{ states('sensor.avr_sound_field') }}"
        sound_modes:
          Direct:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_direct
          Multi Channel Stereo:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_multi_channel_stereo
          2 Channel Stereo:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_2_channel_stereo
          Front Surround:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_front_surround
          Neural:X:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_neural_x
          Dolby Surround:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_dolby_surround
          A.F.D.:
            service: switch.turn_on
            data:
              entity_id: switch.avr_soundfield_a_f_d
#       --------------------------------------------
        current_source_template: "{{ states('sensor.avr_source') }}"
        inputs:
          Google TV:                                # SA-CD/CD
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_sa_cd_cd
          Video 1:                                  # VIDEO 1
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_video_1
          CD:                                       # VIDEO 2  
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_video_2
          TV:                                       # SAT/CATV
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_sat_catv
          Turntable:                                # TV
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_tv
          Computer:                                 # BD/DVD
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_bd_dvd
          Game:                                     # GAME
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_game
          FM Tuner:
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_fm_tuner
          USB:
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_usb
          Bluetooth:
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_bluetooth
          Home Network:
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_home_network
          Music Service List:
            service: switch.turn_on
            data:
              entity_id: switch.avr_source_music_service_list
#       --------------------------------------------      
        current_volume_template: "{{ states('number.avr_volume')|int/100 }}"    
        volume_up:
          service: switch.turn_on
          data:
            entity_id: switch.avr_volume_up
        volume_down:
          service: switch.turn_on
          data:
            entity_id: switch.avr_volume_down
        set_volume:
          service: number.set_value
          data:
            entity_id: number.avr_volume
            value: "{% set vol = ((volume*100)|round|string|replace('.0', ''))|int  -%}{% if vol > 74 %}74{% else %}{{vol}}{% endif %}"
#       --------------------------------------------      
        current_is_muted_template: >
          {% if is_state("switch.avr_mute", "on") -%}
            True
          {%- else -%}
            False
          {%- endif %}
        mute:
          service: switch.toggle
          data:
            entity_id: switch.avr_mute
#       --------------------------------------------
        play:
          service: media_player.media_play
          target:
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
        pause:
          service: media_player.media_pause
          target:
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
        stop:
          service: media_player.media_stop
          target:
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
        next:
          service: media_player.media_next_track
          target:
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
        previous:
          service: media_player.media_previous_track
          target:
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
        seek:
          service: media_player.media_seek
          data_template:
            seek_position: "{{ position }}"
            entity_id: |-
              {%- if is_state("sensor.avr_source", "Google TV") -%}
                media_player.google_tv_4k
              {%- else -%}
                media_player.str_dn1080_2
              {%- endif -%}
#       --------------------------------------------   
        # Main Title (bold) ---  
        title_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
              {{states.media_player.spotify_tor.attributes.media_title}}
            {%- else -%}
              {% if states.media_player.google_tv_4k.attributes.media_title is defined %}
                {{states.media_player.google_tv_4k.attributes.media_title}}
              {%- else -%}
                {{states.media_player.google_tv_4k.attributes.app_name}}
              {%- endif -%}
            {%- endif -%}
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            {{states.number.avr_tuner_frequency.state}}
            {%- set prst = states.number.avr_tuner_preset.state|int -%}
            {%- if prst == 1 -%}: TRT 3{%- endif -%}
            {%- if prst == 2 -%}: CNN Türk{%- endif -%}
            {%- if prst == 3 -%}: Bloomberg{%- endif -%}
            {%- if prst == 4 -%}: TRT 1{%- endif -%}
            {%- if prst == 5 -%}: Lounge FM{%- endif -%}
            {%- if prst == 6 -%}: Eksen{%- endif -%}
            {%- if prst == 7 -%}: Metro{%- endif -%}
            {%- if prst == 8 -%}: RS FM{%- endif -%}
            {%- if prst == 9 -%}: TRT Haber{%- endif -%}
            {%- if prst == 10 -%}: Power FM{%- endif -%}
            {%- if prst == 11 -%}: Fenomen{%- endif -%}
            {%- if prst == 12 -%}: Ulusal Radyo{%- endif -%}
            {%- if prst == 13 -%}: TRT Nağme{%- endif -%}
            {%- if prst == 14 -%}: Number 1{%- endif -%}
            {%- if prst == 15 -%}: PAL FM{%- endif -%}
            {%- if prst == 16 -%}: Radyo Voyage{%- endif -%}
          {%- else -%}
            {{states.media_player.str_dn1080_2.attributes.media_title}}
          {%- endif -%}
        # Sub Title (regular) --- 
        artist_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
              {{states.media_player.spotify_tor.attributes.media_artist}}
            {%- else -%}
              {% if states.media_player.google_tv_4k.attributes.media_artist is defined %}
                {{states.media_player.google_tv_4k.attributes.media_artist}}
              {%- else -%}
                {% if states.media_player.google_tv_4k.attributes.media_title is defined %}
                  {{states.media_player.google_tv_4k.attributes.app_name}}
                {%- endif -%}
              {%- endif -%}
            {%- endif -%}
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            FM Tuner
          {%- else -%}
            {{states.media_player.str_dn1080_2.attributes.media_artist}}
          {%- endif -%}
        # Hidden Title ---
        album_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
              {{states.media_player.spotify_tor.attributes.media_album_name}}
            {%- else -%}
              {% if states.media_player.google_tv_4k.attributes.media_album_name is defined %}
                {{states.media_player.google_tv_4k.attributes.media_album_name}}
              {%- else -%}
                {% if states.media_player.google_tv_4k.attributes.app_name is defined %}
                  {{states.media_player.google_tv_4k.attributes.app_name}}
                {%- else -%}
                  {{states.media_player.google_tv_4k_adb.attributes.source}}
                {%- endif -%}
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            {%- if states('media_player.str_dn1080_2')=='playing' -%}{{states.media_player.str_dn1080_2.attributes.media_album_name}}{%- endif -%}
          {%- endif -%}
        media_content_type_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            music
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            music
          {%- else -%}
            {{states.media_player.str_dn1080_2.attributes.media_content_type}}
          {%- endif -%}
        media_image_url_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {% if states.media_player.google_tv_4k.attributes.entity_picture is defined %}
              {{states.media_player.google_tv_4k.attributes.entity_picture}}
            {%- else -%}
              {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
                {{states.media_player.spotify_tor.attributes.entity_picture}}
              {%- else -%}
                {{states.media_player.google_tv_4k_adb.attributes.entity_picture}}
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            {{states.media_player.str_dn1080_2.attributes.entity_picture}}
          {%- endif -%}
        media_duration_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
              {{states.media_player.spotify_tor.attributes.media_duration}}
            {%- else -%}
              {%- if states('media_player.google_tv_4k')=='playing' -%}{{states.media_player.google_tv_4k.attributes.media_duration}}{%- endif -%}
            {%- endif -%}
          {%- else -%}
            {%- if states('media_player.str_dn1080_2')=='playing' -%}{{states.media_player.str_dn1080_2.attributes.media_duration}}{%- endif -%}
          {%- endif -%}
        current_position_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- if is_state_attr("media_player.google_tv_4k",'app_name', 'Spotify') or is_state("media_player.spotify_tor", 'playing') -%}
              {{states.media_player.spotify_tor.attributes.media_position}}
            {%- else -%}
              {%- if states('media_player.google_tv_4k')=='playing' -%}{{states.media_player.google_tv_4k.attributes.media_position}}{%- endif -%}
            {%- endif -%}
          {%- else -%}
            {%- if states('media_player.str_dn1080_2')=='playing' -%}{{states.media_player.str_dn1080_2.attributes.media_position}}{%- endif -%}
          {%- endif -%}

#--------------------------------------------------------------------------
#----- SONY 4K TV Controller ----------------------------------------------
#--------------------------------------------------------------------------
      sony_kd_65x89j_template:
        unique_id: media_player.sony_kd_65x89j_template
        friendly_name: "Sony KD-65X89J Template"
        device_class: "tv"
        value_template: "{{ states['input_text.sony_kd65x89j_power_state'].state}}"
#        value_template: >
#          {% if state_attr('media_player.sony_kd_65x89j_adb', 'adb_response')=='0'  -%}
#            on
#          {%- else -%}
#            off
#          {%- endif %}
        turn_on:
          - service: script.turn_on_livingroom_tv_and_hyperion
            data: {}
        turn_off:
          - service: input_text.set_value
            data:
              value: "off"
              entity_id: input_text.sony_kd65x89j_power_state
          - service: androidtv.adb_command
            data:
              command: 'SLEEP'
              entity_id: media_player.sony_kd_65x89j_adb
          - delay: 0.5
          - service: input_text.set_value
            data:
              value: "off"
              entity_id: input_text.sony_kd65x89j_power_state

        current_source_template: >
          {% if state_attr('media_player.sony_kd_65x89j', 'source')=='HDMI 3 (eARC/ARC)'  -%}
            HDMI 3
          {%- else -%}
            Other
          {%- endif %}
        inputs:
          HDMI 3:                                      # HDMI 3 (eARC/ARC)
            service: media_player.select_source
            data:
              entity_id: media_player.sony_kd_65x89j
              source: HDMI 3 (eARC/ARC)
          Other:

2 Likes

I know that this is not supported anymore, but maybe someone could help.
I’m getting the error:
Platform error media_player.template - No module named 'homeassistant.components.template.media_player'

How did you install it, with HACS?

Dear @Sennevds,

I’m experiencing a small issue.

running the mute service on the template works as a toggle eventhough the service specifically sets it as muted or non-muted.

here is the example. The following two code examples does the same thing.

service: media_player.volume_mute
data:
  is_volume_muted: false
target:
  entity_id: media_player.receiver
service: media_player.volume_mute
data:
  is_volume_muted: true
target:
  entity_id: media_player.receiver

Is there a way to maybe check what the current mute setting is and do the action accordingly?
How can I capture the mute-on and mute-off service calls from the template?

I need this because I’m muting advertisements with an automation.

ok just disregard my last message.

After checking the documentation, I used the provided {{is_muted}} template like the following and it is working fine now.

current_is_muted_template: "{{ is_state('switch.avr_mute', 'on') }}"
mute:
  service: switch.turn_{%- if is_muted -%}on{%- else -%}off{%- endif -%}
  data: 
    entity_id: switch.avr_mute