Error with expand(group) functionality

Hi everyone,

I have encountered a problem with expanding groups which I do not understand

I have the following automation, which I want to apply to all the media players in the group. I am using expand so that each media player is observed directly as I use some of the entity attributes in the automation. However, this doesn’t work. When I reload automations this particular automation becomes “unavailable”. It loads properly (“on”) and functions correctly when I explicitly state a list of entity IDs here, so I don’t understand why expand will not work here. Perhaps I am not quite expanding it right? Or perhaps expand does not work in the trigger? I have expand working successfully in an action part of another automation. Any help appreciated.

- id: '1431594919196'
  alias: Notifications Plex new
  mode: single
  trigger:
    - platform: state
      from:
        - "playing"
        - "paused"
      entity_id: "{{expand('group.all_plex_players')|map(attribute='entity_id')| join (', ')}}"
    - platform: state
      to:
        - "playing"
        - "paused"
      entity_id: "{{expand('group.all_plex_players')|map(attribute='entity_id')| join (', ')}}"
  variables:
    device:    "{{ state_attr(trigger.entity_id, 'friendly_name') }}"
    series:    "{{ state_attr(trigger.entity_id, 'media_series_title') }}"
    title:     "{{ state_attr(trigger.entity_id, 'media_title') }}"
    picture:   "{{ state_attr(trigger.entity_id, 'entity_picture') }}"
    username:  "{{ state_attr(trigger.entity_id, 'username') }}"
    season:    "{{ state_attr(trigger.entity_id, 'media_season') }}"
    episode:   "{{ state_attr(trigger.entity_id, 'media_episode') }}"
    devstate:  "{{ trigger.to_state.state }}"
    prevseries:     "{{trigger.from_state.attributes.media_series_title}}"
    prevtitle:      "{{trigger.from_state.attributes.media_title}}"
    prevpicture:    "{{trigger.from_state.attributes.entity_picture}}"
    prevusername:   "{{trigger.from_state.attributes.username}}"
    prevseason:     "{{trigger.from_state.attributes.media_season}}"
    prevepisode:    "{{trigger.from_state.attributes.media_episode}}"

  action:
    - service: notify.jamesgroup
      data:
        title: >
          {% if username == None %}
            {% if prevseries == "" %}
              {{prevusername}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ prevtitle }}
            {% else %}
              {{prevusername}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ prevseries }}
            {% endif %}
          {% else %}
            {% if series == None %}
              {{username}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ title }}
            {% else %}
              {{username}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ series }}
            {% endif %}
          {% endif %}

        message: >
          {% if username == None %}
            {% if prevseries == "" %}
              {{prevusername}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ prevtitle }} on {{device}}
            {% else %}
              {{prevusername}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ prevseries }} - S{{'%02d' % prevseason}}E{{'%02d' % prevepisode}} {{prevtitle}} on {{device}}
            {% endif %}
          {% else %}
            {% if series == None %}
              {{username}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ title }} on {{device}}
            {% else %}
              {{username}} {{devstate | replace('idle', 'stopped')|replace('unavailable','stopped')}} {{ series }} - S{{'%02d' % season}}E{{'%02d' % episode}} {{title}} on {{device}}
            {% endif %}
          {% endif %}
        data:
          icon_url: >
            {% if username == None %}
              {{prevpicture}}
            {% else %}
              {{picture}}
            {% endif %}
          notification_icon: "mdi:plex"
          tag: >
            {% if username == None %}
              {{prevusername}} {{device}}
            {% else %}
              {{username}} {{device}}
            {% endif %}

i reduced this down to the minimum needed to test; to rule out any conflicts with other parts of the automation. It is now as follows, but still doesn’t function:

- alias: Notifications Plex template test
#  mode: single
  trigger:
    - platform: state
      from:
        - "playing"
      entity_id: "{{expand('group.all_plex_players')|map(attribute='entity_id')| join (', ')}}"
  action:
    - service: notify.jamesgroup
      data:
        title: "test"
        message: "limited template test"

What you are attempting to do isn’t supported by a State Trigger. It does not allow templating its entity_id option.

Thank you. This makes me very sad. On the other hand, the templating of setting the group that you already helped me with means I can easily copy/paste all the entity names in to my automation whenever I notice there is one missing.