Template Helper to get Library being accessed by Plex HTPC

Hello all

I Hope you are well.

I have only been using Home Assistant since Saturday so I am currently on a Steep Learning Curve :slight_smile:

I use Plex Server with Plex HTPC.

I wanted to know which Library the Currently Playing Media was from so I wrote a Helper Template:

{{state_attr(‘media_player.plex_plex_htpc_for_windows_knc_htpc’,‘media_library_title’)}}

When Music is being Played, the Helper shows the Library as ‘Music’ which is what I want, however I need this to work for Movies so that I can create Automations for when a Movie Starts but the Helper will not work for Movies, or TV Shows for that matter.

I then created an Automation with:

{{states(sensor.plex.media_library) == Movies}}

If I set the above line to include ‘Music’ rather than ‘Movies’ the Automation works as expected.

Any suggestions?

Thanks in advance

Kevin

If you go to Developer Tools → States and type in your sensor media_player.plex_plex_htpc_for_windows_knc_htpc you can see a list of all attributes it supports, eg

Is that the actual template you are using… because it would not work as written.

It isn’t clear what you are actually asking.
Where are you using that template, in a Trigger, Condition, or Action?
Are you asking how to have that template return true for either “Music” or “Movies”?

Post the automation configuration, properly formatted, so we can see what you are trying to do.

Hello

Thanks for the Reply.

I made some adjustments to the Sensor as I Learned more, so the Sensor is now:

{{state_attr('media_player.plex_plex_htpc_for_windows_knc_htpc','media_library_title')}}

However, in the last Day or so I have Setup an Automation that achieves what I want:

description: ""
mode: single
triggers:
  - device_id: 19e06788e8002d366b73214114703f40
    domain: media_player
    entity_id: 6b2fe06253da96b8f3a1583d1796e9f3
    type: playing
    trigger: device
conditions:
  - condition: state
    entity_id: media_player.plex_plex_htpc_for_windows_knc_htpc
    state:
      - movie
    attribute: media_content_type
actions:
  - action: notify.notify
    metadata: {}
    data:
      message: Test

While Testing I just have it Send a Notification if it Succeeds which it does.

However, I have another Issue with the Plex Integration and this Automation which I have Posted elsewhere.

Thanks

Kevin