It is probably a stupid question but I have an automation ready to go but it needs a condition to be met.
A media player entity has as state attribute “group_members:”
Example:
condition: state
entity_id: media_player.bedroom
state:
- media_player.bedroom
attribute: group_members
I have attempted with [‘media_player.bedroom’,‘media_player.dining_room’] but the condition never met even when trying a single entity ( [‘media_player.bedroom’] like the example given).
Yeah you cant use a state condition like that because the attribute is a list containing two entities, not the single entity you are checking for. So it will never match.
Also in that condition you are checking the wrong entity. You are checking the attribute of media_player.bedroom which does not have a group_members attribute. Your group does. Whatever that is called.
To see if a media player is a member of a group you will have to use a template condition, like this:
condition: template
value_template: "{{ 'media_player.bedroom' in state_att('group.your_group_here', 'group_members') }}"
Thank you for your reply,
the group_member attribute does come up in the attribute list when media_player.bedroom is selected as entity in the condition, and the example it’s pulled by the developer tools page to check the state of the same entity.
I do create a group on necessity with the Join service, does the group end up having a name?
Because the media player group I created in the helpers doesn’t behave as I want, and it states as playing even when the two speakers are playing completely different things (on purpose).
Really sorry, I don’t want to be annoying, I just want to understand a bit more. I have been successful with many automations with home assistant and my entire house is basically under its control now, but I finally have some speakers I can use for announcement and music and I really want to integrate with the rest of the automations.
I am using two sonos speakers, and yes that is the service I use to sync playback.
I am trying with:
condition: template
value_template: "{{ 'media_player.bedroom' in state_attr('media_player.bedroom', 'media_player.bedroom', 'media_player.dining_room') }}"
but it gives:
TypeError: state_attr() takes 3 positional arguments but 4 were given
Probably because of the dining_room entity (I am adding it wrong to the template, am I?).
Tried with:
condition: template
value_template: "{{ 'media_player.bedroom' in state_attr('media_player.bedroom', 'media_player.dining_room') }}"
Result:
TypeError: argument of type 'NoneType' is not iterable
Doesn’t that mean that there is no such attribute anyway?
I am joining the two speakers with bedroom as target (but tried the other way around as well, same errors).
EDIT with solution/workaround:
I am using now a template (somehow it always gives me an error when trying templating with conditions):
{{ 'media_player.dining_room' in state_attr('media_player.bedroom',
'group_members') or 'media_player.bedroom' in state_attr('media_player.dining_room', 'group_members') }}
It give a True if bedroom is part of the dining_room group or vice-versa, otherwise is a False.
Easy from here to get a state condition to proceed with my already working auatomation!
Thank you a lot anyway because it gave me a push to experiment even more!