Attribute template for "is_volume_muted" not evaluated (universal media-player)

Hi!
I’m fairly new to HA and am trying to set up a universal media player to group my Sonos players into one media player.
I got it working nicely, with the exception of the is_volume_muted attribute of the new player.
The mute function will mute both sonos players, but the is_volume_muted attribute of the the universal medial player is not updated for some reason.
I tested the template first in the template editor and then added it as a sensor => works as expected in both cases.

    sensor:
      - platform: template
        sensors:
          sonos_muted:
            value_template: >
              {{ (state_attr('media_player.wohnzimmer','is_volume_muted')
              and state_attr('media_player.esszimmer','is_volume_muted')) }}

However, when I try to add the template to the universal media player’s attribute definiton for it’s is_volume_muted attribute, the state of the attribute is not evaluated (i.e., stays false, even if both players are muted)

Here’s the template in the universal media player definiton I currently have:

      attributes:
         is_volume_muted: > 
           "{{ (state_attr('media_player.wohnzimmer','is_volume_muted') 
            and state_attr('media_player.esszimmer','is_volume_muted')) }}"
      unique_id: sonos_all

And the full definition for completeness:

  media_player:
    - platform: universal
      name: sonos_all
      children:
        - media_player.wohnzimmer
        - media_player.esszimmer
      commands:
        volume_up:
          service: media_player.volume_up
          data:
            entity_id:
            - media_player.wohnzimmer
            - media_player.esszimmer
        volume_down:
          service: media_player.volume_down
          data:
            entity_id:
            - media_player.wohnzimmer
            - media_player.esszimmer
        volume_mute:
          service: media_player.volume_mute
          data_template:
            entity_id:
            - media_player.wohnzimmer
            - media_player.esszimmer
            is_volume_muted: '{{ is_volume_muted }}'
        volume_set:
          service: media_player.volume_set
          data_template:
            entity_id:
            - media_player.wohnzimmer
            - media_player.esszimmer
            volume_level: '{{ volume_level }}'
        media_play:
          service: media_player.media_play
          data_template:
            entity_id:
             - media_player.wohnzimmer
             - media_player.esszimmer
            media_content_type: '{{ media_content_type }}'
            media_content_id: '{{ media_content_id }}'
      attributes:
         is_volume_muted: > 
           "{{ (state_attr('media_player.wohnzimmer','is_volume_muted') 
            and state_attr('media_player.esszimmer','is_volume_muted')) }}"
      unique_id: sonos_all

It’s really a minor issue, but it keeps bugging me :slight_smile: - any hints would be appreciated :slight_smile:

      attributes:
         is_volume_muted: > 
           "{{ (state_attr('media_player.wohnzimmer','is_volume_muted') 
            and state_attr('media_player.esszimmer','is_volume_muted')) }}"
      unique_id: sonos_all

Remove the double-quotes surrounding the template:

      attributes:
         is_volume_muted: > 
           {{ (state_attr('media_player.wohnzimmer','is_volume_muted') 
             and state_attr('media_player.esszimmer','is_volume_muted')) }}
      unique_id: sonos_all

Wow, thank you for the quick reply!

I’ve tested without the double quotes as per your suggestion, unfortunately this doesn’t change the behavior.

The mute function works (i.e., both sonos players are muted) but the mute status of the universal player stays the same and because of that, it won’t let me unmute the players again. I can unmute them individually, though.

Here’s my current definition (slightly updated to remove the double quotes as mentioned and I learned there are two services: media_play and play_media)

media_player:
  - platform: universal
    name: sonos_all
    children:
      - media_player.wohnzimmer
      - media_player.esszimmer
    commands:
      volume_up:
        service: media_player.volume_up
        data:
          entity_id:
          - media_player.wohnzimmer
          - media_player.esszimmer
      volume_down:
        service: media_player.volume_down
        data:
          entity_id:
          - media_player.wohnzimmer
          - media_player.esszimmer
      volume_mute:
        service: media_player.volume_mute
        data_template:
          entity_id:
          - media_player.wohnzimmer
          - media_player.esszimmer
          is_volume_muted: '{{ is_volume_muted }}'
      volume_set:
        service: media_player.volume_set
        data_template:
          entity_id:
          - media_player.wohnzimmer
          - media_player.esszimmer
          volume_level: '{{ volume_level }}'
      play_media:
          service: media_player.play_media
          data_template:
            entity_id:
             - media_player.wohnzimmer
             - media_player.esszimmer
            media_content_type: '{{ media_content_type }}'
            media_content_id: '{{ media_content_id }}'
      media_play:
          service: media_player.media_play
          data:
            entity_id:
             - media_player.wohnzimmer
             - media_player.esszimmer
      media_pause:
        service: media_player.media_pause
        data:
          entity_id:
           - media_player.wohnzimmer
           - media_player.esszimmer
      media_next:
        service: media_player.media_next_track
        data:
          entity_id:
           - media_player.wohnzimmer
           - media_player.esszimmer
      media_previous:
        service: media_player.media_previous_track
        data:
          entity_id:
           - media_player.wohnzimmer
           - media_player.esszimmer
    attributes:
       is_volume_muted: > 
         {{ (state_attr('media_player.wohnzimmer','is_volume_muted') 
          and state_attr('media_player.esszimmer','is_volume_muted')) }}
    unique_id: sonos_all
    device_class: speaker

It may not change the behavior of Universal Media Player but it corrects the template. You only need to wrap the template in quotes if it is on the same line as the YAML option. If you use > then it means the template begins on the next line and it shouldn’t be wrapped in quotes.

In the example you posted for Universal Media Player, the indentation of the last three options is incorrect. The last six lines require indentation by an additional two spaces EDIT Sorry, my mistake; the last 6 lines are fine as-is.

Thank you again, didn’t know about the double quotes - learned something new!

Indentation should actually be correct, since it’s on the same level as the base definiton itself… I think.
Changing indentation generated an error message.

But the basic problem of the mute state not being updated still remains - any suggestions how I could look deeper into what is happening when the state changes, e.g., is there maybe a log level I could increase somewhere to see more details?

I had been attempting (unsuccessfully) to use a template for an attribute.
In desperation, I opened up the code for UMP, and see that it’s hard-coded to expect either an ‘entity_id’, or ‘entity_id | attribute’ (the vertical bar is literal, not a pipe) so providing the result of a template wouldn’t make sense to it unless the output looks like one of the above.
Next attempt I’ll make is to define a template sensor to compute the needed state, then provide that sensor’s entity_id to the attribute line in UMP’s config.
However, I’ve already seen a post where someone tried this and it wasn’t updating itself properly. So I’ve limited hope for that approach.
It’d be nice if the atrribute parser in UMP was accepting of templated definitions.