Attribute state "group_members" as state condition

Hello,

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:

group_members:
  - media_player.bedroom
volume_level: 0.12
is_volume_muted: false
media_content_id: x-sonos-spotify:spotify****
media_content_type: music
media_duration: 222
media_position: 0
media_position_updated_at: '2022-08-25T09:11:54.261657+00:00'
media_title: Cochise
media_artist: Audioslave
media_album_name: Audioslave
shuffle: true
repeat: 'off'
queue_position: 4
queue_size: 80
entity_picture: >-
  /api/media_player_proxy/media_player.bedroom?token=*******
friendly_name: Bedroom
supported_features: 981567

When I am grouping it with another player it would change to:

group_members:
  - media_player.bedroom
  - media_player.dining_room

I am now trying to have a condition for it:

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

Please help a helpless stranger!

Welcome to the forum.

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 don’t know. I’ve never used that service. Is it a service associated with a particular integration?

I don’t see it listed in the available group services at the bottom of the group documentation page: https://www.home-assistant.io/integrations/group

EDIT: Found this, is it what you are using? https://www.home-assistant.io/integrations/media_player/#service-media_playerjoin

If so, replace group.your_group_here with the entity id of the master media player in the template I posted above.

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!

1 Like