Plex Activity Automation

I am trying to create an automation so when someone starts watching plex the sonos will come on and say who is watching and what. The tts part is fine, I just can not figure out how to get the attributes out of the plex activity sensor. This is how it is displayed. those are usernames on the left. 2 usernames one on top of the other. What I would really like is to just create in input boolean that will be on my dashboard and i can press to see who is watching what.

Anyone know how to take the values out of this sensor so I could use them with tts?

Ive been trying to figure this out for awhile with out any luck.

wow, after many tries I thought this still was not working. I rebooted and all of a sudden it told me who was watching what:) perfect, except it reads the full email address, is there a way to convert the email address into a friendly name like that? Theres only about 15 users and I could specify user-email…

Thanks!!!

- alias: "Plex Spy notification"
  trigger:
    - platform: state
      entity_id: sensor.plex_server
  action:
    - service: script.say_sonos
      data_template:
        volume: '0.5'
        where: 'living_room, media_player.office, media_player.bathroom'
        what: >
          'Plex user now watching {%- if states.sensor.plex_server.attributes -%}
            {% set space = joiner(' ') %}
            {%- for attr in states.sensor.plex_server.attributes -%}
             {%- if not attr=="friendly_name" and not attr=="unit_of_measurement"-%}
              {{space()}}{{attr}} is watching {{states.sensor.plex_server.attributes[attr]}}.
             {%- endif -%}
            {%- endfor -%}
          {%- endif -%}'
1 Like

I’ve got an an automation running for when my plex server reaches the max amount of streams, this would go with it nicely.

its working nice. I have a spot on my hadashboard also that displays current watchers.

Hello, I am trying to accomplish the same thing in hadashboard. I am able to display the # of watches but now who is watching what. If you were able to accomplish who is watching what would you be willing to share you code with me?

Thanks, Tom

@trhessel
I have something on this post that might help:

Thank you, in my sensors.yaml file is the platform for this template?

@trhessel Correct. You can also test and tweak it in the “Templates” section of homeassistant:


templates

Thanks oddly it seems to create one entry for each plex client watching on my server, like media_player.plex_plex_7d3eebd9_6e92_4930_b041_a0d19ab22486 and media_player.plex_plex_923a4wehc2owldktmm7cabxp. How do I put all this data into a single sensor that will show me what is playing even if say three clients are watching something? The sensor config you provided seems to just say idle all the time. Where in your config you are creating the sensor shield_plex_playing from media_player.shield. Would I be doing the same for each client that i listed above?

I’m only tracking in-home, so I created the sensor more about asking the question “What media was played each device and when?”

For that, I did create 4 different sensors, 1 for each of the different playback devices. That’s also why the sensor includes the username.