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.
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
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)
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 spacesEDIT 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.