Template sensor based on state

Is it possible to pull attributes out of an entity based on it’s state? If the enitity ids are unknown?

I’m trying to grab any entity that begins with media_player.emby* that is playing. I would need two attributes. ‘app_name’ and media_title’

off the top of my head, you could loop through media players and compare everything right of media_player. and substring search it for emby and go from there…

something like this…

{% for state in states.media_player -%}
  {% if state.state == "playing" %}
    Title: {{ state.attributes["media_title"] }} 
    App: {{state.attributes["app_name"]}}
    Device:{{ state.name }}
  {% endif%}

{%- endfor %}