Issue with Universal Media Player

I’m having problems with Universal Media Player. I think I have it all setup, but I keep getting errors with mute. I get this error:

Failed to call service media_player/volume_mute. required key not provided @ data['is_volume_muted'].

As far as I can tell, my is_volume_muted is working correctly though.

Here’s my config:

media_player:
  platform: universal
  name: Test Universal
  device_class: tv
  children:
    - media_player.sony_xbr_75x90ch
    - media_player.sony_bravia_tv

  commands:
    turn_on:
      service: media_player.turn_on
      data:
        entity_id: media_player.sony_bravia_tv
    turn_off:
      service: media_player.turn_off
      data:
        entity_id: media_player.sony_bravia_tv
    volume_up:
      service: media_player.volume_up
      data:
        entity_id: media_player.sony_bravia_tv
    volume_down:
      service: media_player.volume_down
      data:
        entity_id: media_player.sony_bravia_tv
    volume_mute:
      service: media_player.volume_mute
      data:
        entity_id: media_player.sony_bravia_tv
    select_source:
      service: media_player.select_source
      data:
        entity_id: media_player.sony_bravia_tv
        source: "{{ source }}"
    volume_set:
      service: media_player.volume_set
      data:
        entity_id: media_player.sony_bravia_tv
        volume_level: "{{ volume_level }}"

  attributes:
    state: media_player.sony_bravia_tv
    is_volume_muted: media_player.sony_bravia_tv|is_volume_muted
    volume_level: media_player.sony_bravia_tv|volume_level
    source: media_player.sony_xbr_75x90ch|source
    source_list: media_player.sony_bravia_tv|source_list

When I put this in the Template Editor, I get False for both.

{{ state_attr('media_player.sony_xbr_75x90ch', 'is_volume_muted') }}

{{ state_attr('media_player.test_universal', 'is_volume_muted') }}

Apologies for resurrecting a relatively old thread, but there is surprisingly little information about this issue. I managed to figure out the solution, and wanted to add it here for anyone else who ends up here as I did.

Problem 1: The Universal Media Player documentation is wrong, it says the volume_mute service should toggle the current state. However it should actually set to muted/unmuted based on the is_volume_muted parameter passed with the service call.

Problem 2: I can’t find anywhere in the documentation that explains how to pass through the ‘is_volume_muted’ parameter from the original service call to the new one we are making to the backend. After digging through the source, I eventually found that the answer was simple: all the service data parameters just become variables in the template.

Solution: After figuring out the two issues above, the config was actually quite straightforward (I’ve omitted some of the services for brevity, but provided enough context to hopefully give you an idea of what’s needed where):

media_player:
  - platform: universal
    unique_id: living-room-tv-combined
    device_class: tv
    name: Living room TV
    children:
      - media_player.living_room_tv_chromecast
      - media_player.living_room_tv_kodi
      - media_player.lg_living_room_tv
    commands:
      volume_mute:
        service: media_player.volume_mute
        target:
          entity_id: media_player.lg_living_room_tv
        data_template:
          is_volume_muted: '{{ is_volume_muted }}'
      volume_set:
        service: media_player.volume_set
        target:
          entity_id: media_player.lg_living_room_tv
        data_template:
          volume_level: '{{ volume_level }}'
    attributes:
        is_volume_muted: media_player.lg_living_room_tv|is_volume_muted
        volume_level: media_player.lg_living_room_tv|volume_level

This example config ensures that most actions pass through to either Chromecast or Kodi, depending on whichever is currently active. But volume controls will always manage the volume of the TV itself. Don’t forget to define volume_up and volume_down, which I didn’t include here because they are shown in the Universal Media Player documentation already and work fine.

4 Likes