Print all the attributes and values of Plex sensor

you can try something like this:

{% set player = states('media_player.shield') %} 
{% set user = state_attr('media_player.shield', 'session_username') %}
{% set media = state_attr('media_player.shield', 'media_title') %}
{% if player in [ 'playing','paused'] %}
  {% if is_state_attr('media_player.shield', 'media_content_type', 'music') %}
    {{ user}} {{ player }} {{ state_attr('media_player.shield', 'media_artist') }} - {{media }} (From {{ state_attr('media_player.shield', 'media_album_name') }})
  {% elif is_state_attr('media_player.shield', 'media_content_type', 'tvshow') %}
    {{ user }} {{ player }} {{ state_attr('media_player.shield', 'media_series_title') }} S{{ state_attr('media_player.shield', 'media_season') }}E{{ state_attr('media_player.shield', 'media_episode') }} - {{media }} (From {{ state_attr('media_player.shield', 'media_library_name') }})
  {% elif is_state_attr('media_player.shield', 'media_content_type', 'movie') %}
    {{ user }} {{ player }} {{ media }} (From {{ state_attr('media_player.shield', 'media_library_name') }})
  {% else %}
    {{ user}} {{ player }} unknown: {{ media }}
  {% endif %}
{% else %}
  Idle
{% endif %}

which is somewhat smaller. Im sure the rest can be shortened also, but it would probably require some more work…

Let me take a step back. By default I get a sensor that displays how many viewers are watching. If I click on that sensor I can than see what they are each watching. Why is it difficult to have that information displayed as well without the need to click on it?

If you go to “Developer Tools” > “States”, anything you see there can be pulled in to a template sensor.
The trick is that homeassistant does extra magic to show what’s in the UI so you don’t always have access to the magic.

silly of me to forget, to post this:

{% if states('sensor.plex') != '0' %}
  {%- for attr in states.sensor.plex.attributes %}
    {%- if not attr in ['friendly_name', 'unit_of_measurement','custom_ui_state_card','icon','supported_features','entity_picture'] %}
                  {{attr}} is watching {{states.sensor.plex.attributes[attr]}}
     {%- endif %}
   {%- endfor %}
 {% else %} Watching Plex: {{states('sensor.plex')}}
{% endif%}

which works just fine, why don’t you have a look if this is something you can use

5 Likes

Tested that here with a single user playing and it works. @teitelbot this looks like your solution.

1 Like

Thank You. Works great. Anyway I can get it to show a pic instead of text, the way it shows up in plex?

not that easily i am afraid.
You can get the images of the individual media_players like this:

        entity_picture_template: >
         {% if states('media_player.plex_telefoon') == 'playing' %}
            {{state_attr('media_player.plex_telefoon','entity_picture')}}
         {% else %} /local/various/plex.png
         {% endif %}

but these players are created dynamically, so you would need to give it some thought how to incorporate that in to the sensor I shared above, considering that is not targeting a single media_player.

the individual player looks like this:

50