Track Plex Server Users

Question: How do I track (identify) Plex users in HA with the Plex (integration) Sensor?

  1. It appears the main sensor lists the information I’m after but it does not contain a key so I don’t know how to get to the information and how to parse it out.

  2. I can’t seem to reliably get the information I’m after from the created media clients because they seem to always change.

IE: The string looks like this with 2 users:

[User] - [Player Client]: [Show/ Artists Name] - [Season / Episode / Track Information]

ServiceXp - Plexamp: 12 Stones - Smoke and Mirrors Volume 1 - Empty Words
ServiceXpWife - Plex for Windows: Stargate SG-1 - s07e21 - Lost City (1)

ServiceXp - Plexamp: 12 Stones - 12 Stones - Broken
ServiceXpWife - Plex for Windows: Stargate SG-1 - s07e21 - Lost City (1)
unit_of_measurement: Watching
icon: mdi:plex
friendly_name: Plex (Oculus-One)

Ok, so let me ask this another way…

How do you get non-keyed data from a sensor?

example to get the to the data in the last_added_item key
{{ state_attr('sensor.plex_library_tv_recordings','last_added_item') }}

Below returns 'none'
{{ state_attr('sensor.plex_library_tv_recordings','') }}

I didn’t write this and I’ve had it as a sensor for a long time but I think it will help

Obviously change the sensor :slight_smile:

- platform: template
  sensors:
    plexuser:
      friendly_name: "Plex User"
      value_template: >
        {%- if not states('sensor.plex_piplex')=="0"-%}
        {%- if states.sensor.plex_piplex.attributes -%}
        {%- for attr in states.sensor.plex_piplex.attributes -%}
        {%- if not attr=="friendly_name" and not attr=="unit_of_measurement" and not attr=="icon"-%}{{attr}}
        {%- endif -%}
        {%- endfor -%}
        {%- endif -%}
        {%- elif states('sensor.plex_piplex')=="0"-%}
        No-one
        {%- endif -%}

1 Like

Thank You

That does get me a lot closer. Everything after the first " : " is being dropped and I can’t figure out how to escape it.

any idea’s?

    - sensor:
      - name: "Plex User"
        state: >
          {%- if not states('sensor.plex_server')=="0"-%}
          {%- if states.sensor.plex_server.attributes -%}
          {%- for attr in states.sensor.plex_server.attributes -%}
            {%- if not attr=="friendly_name" and not attr=="unit_of_measurement" and not attr=="icon"-%} 
                  User: {{attr}}{{"\r\n"}}
            {%- endif -%}
          {%- endfor -%}
            {%- endif -%}
          {%- elif states('sensor.plex_server')=="0"-%}
          No-one
          {%- endif -%}

template results

User: RJ - Plex for Windows 
User: RJ - Plexamp

Entity data

RJ - Plex for Windows: Mysteries of the Abandoned - s09e48 - Episode 48
RJ - Plexamp: 'Newsboys - Restart: Deluxe Edition - That Home'

Ok… it’s more than a year ago :smiley: but I’ve done in the developer tool, this and it works showing the user and what it’s watching:

{%- if not states('sensor.plex_server')=="0"-%}
{%- if states.sensor.plex_server.attributes -%}
{%- for attr in states.sensor.plex_server.attributes -%}
  {%- if not attr=="friendly_name" and not attr=="unit_of_measurement" and not attr=="icon"-%} 
        User: {{attr}}{{"\n"}}watching: {{ state_attr ('sensor.plex_server',attr) }}
  {%- endif -%}
{%- endfor -%}
  {%- endif -%}
{%- elif states('sensor.plex_server')=="0"-%}
No-one
{%- endif -%}

Buy maybe you got it by yourself :slight_smile:

3 Likes

Nice work!! Thank You.

I wound up spinning up 2 Tautulli instances to deal with it. :frowning:

This is beautiful. Nicely done.

1 Like