Media_player.template

so the direct script service calls were never actually removed?

ok, I actually did a new installation in a qemu vm in ProxMox and I’m in the process of only copying necessary stuff from the old Raspberry Pi installation.

My script entity id did not change actually. I still have both instances running. The same config works on the old installation. The only difference is the following:

. pi vm
Installation method Home Assistant OS Home Assistant OS
Core 2026.3.1 2026.3.2
Supervisor 2026.03.2 2026.03.2
Operating System 17.1 17.1
Frontend 20260304.0 20260312.0

so I thought direct script service calls were removed.

the script intentifier in scripts.yaml for both installations are the same, I guess that is the slug right? I don’t know what changed.

No, they have not been removed. They will never be removed either. Calling a script directly blocks the script from moving forward where calling the script from script.turn_on calls in without blocking the script from moving forward. That distinction alone will keep the functionality in HA forever.

Go to settings → developer tools → actions and search for the action by name and see what it has as a service name.

So,
calling script direct = blocking,
calling script via script.turn_on = non-blocking.
Good to know :slight_smile:

in both installations it appears as

action: script.turn_on_avr_and_google_tv_4k
data: {}

Now I’m really confused why I got that error.

Then it should be working for you in the template entity. The rewrites of the integration a couple months back onboards the scripts the same way as every other template platform. So the issue is likely not related to this integration, unless there are errors in the logs.

I’ll change it back to direct-calling and let you know what happens.

I just changed it back to direct-calling and get the problem again when I hit power on.

this appears on the gui:
Action media_player.turn_on uses action script.turn_on_avr_and_google_tv_4k which was not found.

and I get this in the log:

Log details (ERROR)
Logger: homeassistant.helpers.script.sony_audio_video_receiver_turn_on
Source: helpers/script.py:2098
First occurred: 3:12:20 PM (2 occurrences)
Last logged: 3:12:42 PM

Sony Audio-Video Receiver turn_on: Error executing script. Service not found for call_service at pos 1: Action script.turn_on_avr_and_google_tv_4k not found

Can you show me the full configuration of that script in scripts.yaml?

media_player:
  - platform: media_player_template
    media_players:
      str_dn1080_template:
        unique_id: media_player.str_dn1080_template
        friendly_name: "Sony Audio-Video Receiver"
        device_class: "receiver"
        value_template: >
          {%- if is_state("switch.avr_power_state", "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')=="idle" or
                    states('media_player.google_tv_4k')=="off" -%}
                on
              {%- else -%} 
                {{ states('media_player.google_tv_4k') }} 
              {%- endif -%}            
            {%- else -%}
              {%- if states('media_player.str_dn1080_googlecast')=="unavailable" or
                    states('media_player.str_dn1080_googlecast')=="unknown" or
                    states('media_player.str_dn1080_googlecast')=="off" -%}
                on
              {%- else -%} 
                {{ states('media_player.str_dn1080_googlecast') }} 
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            off
          {%- endif %}
        turn_on:
          - service: script.turn_on_avr_and_google_tv_4k
            data: {}
        turn_off:
          - action: button.press
            target:
              entity_id: button.avr_power_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
          # End of Sound Modes --------------------------------------------
        current_source_template: |-
          {%- set source_map = {
            "TV": "Turntable",
            "SA-CD/CD": "Google TV", 
            "Video 2": "CD",
            "SAT/CATV": "Computer",
            "BD/DVD": "TV"
          } -%}
          {{ source_map.get(states("sensor.avr_source"), 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
          Computer: # 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
          TV: # 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
          Chromecast:
          AirPlay:
          # End of Inputs --------------------------------------------
        current_volume_template: "{{ states('number.avr_volume')| replace('unavailable', 0)|default(0)|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: "{{ is_state('switch.avr_mute', 'on') }}"
        mute:
          service: switch.turn_{%- if is_muted -%}on{%- else -%}off{%- endif -%}
          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_googlecast
              {%- 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_googlecast
              {%- 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_googlecast
              {%- 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_googlecast
              {%- 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_googlecast
              {%- 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_googlecast
              {%- 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') -%}
              {{ state_attr('media_player.spotify_tor', 'media_title') or '' }}
            {%- else -%}
              {{ state_attr('media_player.google_tv_4k', 'media_title') or state_attr('media_player.google_tv_4k', 'app_name') or '' }}
            {%- endif -%}
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            {%- set preset_names = {
              1: "TRT 3", 2: "CNN Türk", 3: "Bloomberg", 4: "TRT 1", 5: "Lounge FM",
              6: "Eksen", 7: "Metro", 8: "RS FM", 9: "TRT Haber", 10: "Power FM",
              11: "Fenomen", 12: "Ulusal Radyo", 13: "TRT Nağme", 14: "Number 1",
              15: "PAL FM", 16: "Radyo Voyage"
            } -%}
            {%- set frequency = states('number.avr_tuner_frequency') -%}
            {%- set preset = states('number.avr_tuner_preset') | int(0) -%}
            {{ frequency }}{% if preset in preset_names %}: {{ preset_names[preset] }}{% endif %}
          {%- else -%}
            {{ state_attr('media_player.str_dn1080_googlecast', 'media_title') or '' }}
          {%- endif -%}
        # Sub Title (regular) ---
        artist_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- set spotify_source = state_attr('media_player.spotify_tor', 'source') -%}
            {%- if spotify_source == 'Google TV 4K' and is_state('media_player.spotify_tor','playing') -%}
              {{ state_attr('media_player.spotify_tor', 'media_artist') or '' }}
            {%- else -%}
              {{ state_attr('media_player.google_tv_4k', 'media_artist') or state_attr('media_player.google_tv_4k', 'media_title') or '' }}
            {%- endif -%}
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            FM Tuner
          {%- else -%}
            {{ state_attr('media_player.str_dn1080_googlecast', 'media_artist') or '' }}
          {%- endif -%}
        # Hidden Title ---
        album_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- set spotify_source = state_attr('media_player.spotify_tor', 'source') -%}
            {%- if spotify_source == 'Google TV 4K' and is_state('media_player.spotify_tor','playing') -%}
              {{ state_attr('media_player.spotify_tor', 'media_album_name') or '' }}
            {%- else -%}
              {{ state_attr('media_player.google_tv_4k', 'media_album_name') or state_attr('media_player.google_tv_4k', 'app_name') or state_attr('media_player.google_tv_4k_adb', 'source') or '' }}
            {%- endif -%}
          {%- else -%}
            {%- if is_state('media_player.str_dn1080_googlecast', 'playing') -%}
              {{ state_attr('media_player.str_dn1080_googlecast', 'media_album_name') or '' }}
            {%- endif -%}
          {%- endif -%}
        media_content_type_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%} 
            music
          {%- elif is_state("sensor.avr_source", "FM Tuner") -%}
            music
          {%- elif state_attr('media_player.str_dn1080_googlecast', 'media_content_type') is not none -%} 
            {{ state_attr('media_player.str_dn1080_googlecast', 'media_content_type') }}
          {%- else -%}
            None
          {%- endif -%}
        media_image_url_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%} 
            {%- set google_tv_picture = state_attr('media_player.google_tv_4k', 'entity_picture') -%}
            {%- if google_tv_picture -%} 
              {{ google_tv_picture }}
            {%- else -%} 
              {%- set spotify_source = state_attr('media_player.spotify_tor', 'source') -%}
              {%- if spotify_source and spotify_source == 'Google TV 4K' and is_state('media_player.spotify_tor','playing') -%}
                {{ state_attr('media_player.spotify_tor', 'entity_picture') or '' }}
              {%- else -%}
                {{ state_attr('media_player.google_tv_4k_adb', 'entity_picture') or '' }}
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            {{ state_attr('media_player.str_dn1080_googlecast', 'entity_picture') or '' }}
          {%- endif -%}
        media_duration_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- set spotify_source = state_attr('media_player.spotify_tor', 'source') -%}
            {%- if spotify_source == 'Google TV 4K' and is_state('media_player.spotify_tor','playing') -%}
              {{ state_attr('media_player.spotify_tor', 'media_duration') or '' }}
            {%- elif is_state('media_player.google_tv_4k', 'playing') -%}
              {{ state_attr('media_player.google_tv_4k', 'media_duration') or '' }}
            {%- endif -%}
          {%- elif is_state('media_player.str_dn1080_googlecast', 'playing') -%}
            {{ state_attr('media_player.str_dn1080_googlecast', 'media_duration') or '' }}
          {%- endif -%}
        current_position_template: |-
          {%- if is_state("sensor.avr_source", "Google TV") -%}
            {%- set spotify_source = state_attr('media_player.spotify_tor', 'source') -%}
            {%- if spotify_source == 'Google TV 4K' and is_state('media_player.spotify_tor','playing') -%}
              {{ state_attr('media_player.spotify_tor', 'media_position') or '' }}
            {%- elif is_state('media_player.google_tv_4k', 'playing') -%}
              {{ state_attr('media_player.google_tv_4k', 'media_position') or '' }}
            {%- endif -%}
          {%- elif is_state('media_player.str_dn1080_googlecast', 'playing') -%}
            {{ state_attr('media_player.str_dn1080_googlecast', 'media_position') or '' }}
          {%- endif -%}

        # End or receiver --------------------------------------------------------------------------

turn_on_avr_google_tv_4k:
  alias: Turn on AVR & Google TV 4K
  sequence:
  - if:
    - condition: state
      entity_id: switch.home_theater_power_2
      state: 'off'
    then:
    - data: {}
      target:
        entity_id: switch.home_theater_power_2
      action: switch.turn_on
    - delay:
        hours: 0
        minutes: 0
        seconds: 7
        milliseconds: 0
    - repeat:
        sequence:
        - data: {}
          target:
            entity_id: button.avr_power_on
          action: button.press
        - delay: 00:00:01
        until:
        - condition: template
          value_template: '{{ not is_state(''media_player.str_dn1080_template'', ''off'')  and
            not is_state(''media_player.str_dn1080_template'', ''unavailable'')  and
            not is_state(''media_player.str_dn1080_template'', ''unknown'')  and repeat.index
            < 4 }} '
    else:
    - repeat:
        sequence:
        - data: {}
          target:
            entity_id: button.avr_power_on
          action: button.press
        - delay: 00:00:01
        until:
        - condition: template
          value_template: '{{ not is_state(''media_player.str_dn1080_template'', ''off'')  and
            not is_state(''media_player.str_dn1080_template'', ''unavailable'')  and
            not is_state(''media_player.str_dn1080_template'', ''unknown'') and repeat.index
            < 4  }}'
  mode: single
  icon: mdi:power-socket-eu
  description: ''

oh wait, I think I found the problem.
action: script.turn_on_avr_google_tv_4k
vs
action: script.turn_on_avr_and_google_tv_4k
:man_facepalming:

I dont understand why I have slug turn_on_avr_and_google_tv_4k originally, which is same as its entity id, but it became turn_on_avr_google_tv_4k when I copied the script to new installation and got the same entity id but got different slug.

1 Like

If you made it from the UI, it’s possible it made the original script name from your alias.

Was this changed? I think I noticed a while ago that YAML created scripts were no longer using the slug, but were using the alias for the entity_id (and maybe also for the action, not sure there)

Well, originally when the UI was made, the slug was autogenerated from a uuid. People didn’t like that so at some point it changed to making a slug from the alias. But if anyone changes the alias and copies script from machine A to machine B, the new system will likely have a slug that differs from the alias which will result in some oddities. Not saying that happened, but it could happen.

I really hope templating the browse feature would be included at some point.

The integration stopped working in HA 2026.6.0 :sob:

Logger: homeassistant.components.media_player
Source: helpers/entity_platform.py:490
Integration: Media player (documentation, issues)
First occurred: 10:23:03 PM (1 occurrence)
Last logged: 10:23:03 PM

Error while setting up media_player_template platform for media_player: async_setup_template_platform() takes from 7 to 8 positional arguments but 9 were given
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 490, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/media_player_template/media_player.py", line 143, in async_setup_platform
    await async_setup_template_platform(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        hass,
        ^^^^^
    ...<7 lines>...
        CONF_MEDIAPLAYER,
        ^^^^^^^^^^^^^^^^^
    )
    ^
TypeError: async_setup_template_platform() takes from 7 to 8 positional arguments but 9 were given

It's due to the final deprecation of the legacy template platform I think.

Petro has submitted a PR - I just edited the relevant file by copying the changes he proposes, and it works for me.

3 Likes