Plex Webhook Handler

Hi Everyone.

This is my first time converting an automation I use to a blueprint, feedback welcomed on this.

This blueprint simplifies integrating Plex playback events with Home Assistant automations using webhooks, inspired by this forum thread.

Prerequisites:

Setup:

Generate a Unique Webhook ID:

Configure Plex Webhook:

  • In Plex, create a webhook pointing to your Home Assistant server:
    • Example URL: http://<home_assistant_ip>:<port>/api/webhook/{webhook_id}
    • Example: http://10.0.1.2:8123/api/webhook/e9ee051d-31cd-464a-b3c4-034992a96be0

Import the Blueprint:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Create Automation:

  • Create a new automation using the imported blueprint.
  • Enter your generated webhook ID and the Plex client name.

Determine Plex Client Name:

  • If unsure of the client name:
    • Save the automation.
    • Play media on Plex.
    • In Home Assistant, view the automation’s trace.
    • Inspect the second node (changed variable - webhook payload).
    • Find the “Player: title:” value.
    • Enter this value into the blueprint’s Plex client field (case-insensitive).

Configure Automation Actions:

  • Define actions to trigger based on Plex playback events.

Resume Handling (Optional):

  • The webhook reports a resume event when pausing then playing again.
  • The blueprint allows you to treat “resume” as “play” if desired.

Access Webhook Data:

  • Use payload.Metadata in templates to access data like cover art:
    • Example: payload.Metadata.thumb

I hope this helps someone.

8 Likes

Thanks a lot. I looked into dimming philips hue lights when plex was playing and out of the many options out there, this was the cleanest solution.

1 Like

Thank you :pray:

Have updated the blueprint, cleaned up the UI and grouped Actions for Movie, TV, Music.

Now options to set actions for Media when it is Rated, New Content Added, Server Owner Actions (Database backup complete or Database corruption detected).

Adjust the Automation to run in Single, Restart, Queued or Parallel mode. Increase/Decrease the trace count.

Struggling to get the Plex Client Name? Not a problem, as long as the webhook has been setup properly on Plex Server to send to Home Assistant. Enable the Plex Client Name? option and Home Assistant notification will be presented (when a Plex webhook is triggered) that will present the client name.

Does the webhook give surround audio details at all (e.g. 2.0, 5.1, 7.1 etc) as this would be damn useful for my current challenge (changing the AVR’s sound mode depending on the media’s surround type)

It doesn’t give any information on the audio details.

Thanks for this blueprint, super handy! However I’ve run into an annoying issue. I have two Apple Tv’s in my house and even though each Apple TV is named (in Apple TV settings), in the Plex web hook data it calls the player “Apple TV” for both units. However under the “Player” details in the webhook payload, there is a uuid that seems to be unique. Might try modifying this blueprint to read the uuid instead of player name.

great idea.

I have updated the blueprint, you can use client uuid or name (just for anyone who updates who is already using it), the uuid takes precedence over the name.

the option to retrieve the client name also gives the uuid as well now.

1 Like

I want to thank you for this blueprint! I wanted to use n8n, but could not get the Plex communicate with n8n add-on, your way is far better and easier :slight_smile:
if someone is interested, here is my example of notification if Play is started and when new media is added to the Library.

alias: Plex Webhook Handler RELEASE (v0.4.4)
description: ""
use_blueprint:
  path: thenextbutton/plex_webhook_release.yaml
  input:
    # This is your unique Home Assistant Webhook ID. You can find it in your Plex Media Server's webhook configuration.
    webhook_id: YOUR_HOME_ASSISTANT_WEBHOOK_ID_HERE # Example: 8f4e2c1a-b05d-4f67-8e90-1234567890ab
    plex_client_uuid:
      # These are the UUIDs for your Plex Libraries (e.g., Movies, TV Shows)
      # You can find a library's UUID by viewing media in that library in Plex and checking its XML.
      - YOUR_PLEX_LIBRARY_UUID_1 # Example: 9c0b1d2e-f34g-5h6i-7j8k-l9m0n1o2p3q4
      - YOUR_PLEX_LIBRARY_UUID_2 # Example: a7b8c9d0-e1f2-g3h4-i5j6-k7l8m9n0o1p2
      # These are the UUIDs for your Plex Playing Devices (e.g., Apple TV, Smart TV, Mobile Phone)
      # Find these in the Home Assistant automation trace data when the device plays media.
      - YOUR_PLEX_PLAYER_UUID_1 # Example: F5E4D3C2-B1A0-9E8D-7C6B-5A4B3C2D1E0F
      - YOUR_PLEX_PLAYER_UUID_2 # Example: p9q8r7s6t5u4v3w2x1y0z9a8b7c6d5e4
      # Add more device UUIDs as needed for any other players you want to trigger notifications.
    plex_client: [] # Leave this empty to rely solely on player UUIDs for client filtering (recommended).
    movie_resume_mimics_play: true
    movie_play_actions:
      # Replace 'notify.mobile_app_your_device_name' with your specific mobile app notification service name.
      # You can find this under Developer Tools -> Services in Home Assistant.
      - service: notify.mobile_app_main_phone # Example: notify.mobile_app_living_room_tablet
        data:
          # Message with bold movie title. Customize player_title if needed (e.g., rename "TV 2022" to "Samsung TV").
          message: "🎬 Movie '<b>{{ payload.Metadata.title }}</b>' started on {{ player_title }}!"
          title: "Plex Playback"
          data: # This 'data' block is for mobile_app specific features.
            html: true # Enable HTML rendering for the message.
            # Replace 'http://YOUR_PLEX_IP:YOUR_PLEX_PORT' with your Plex Media Server's actual IP address and Port.
            # Replace 'YOUR_PLEX_TOKEN_HERE' with your actual X-Plex-Token.
            image: "http://192.168.1.50:32400{{ payload.Metadata.thumb }}?X-Plex-Token=RANDOM_TOKEN_XYZ123ABC" # Example: http://10.0.0.200:32400
            notification_icon: "mdi:movie"
            # Replace '/your-dashboard-path' with the actual path to your desired Home Assistant dashboard (e.g., /lovelace/main, /a_custom_dashboard).
            clickAction: /media-info/plex # Example: /home/overview
    episode_play_actions:
      - service: notify.mobile_app_main_phone # Example: notify.mobile_app_bedroom_tv
        data:
          # Message with bold episode and show title. Customize player_title if needed.
          message: "🎬 Episode '<b>{{ payload.Metadata.title }}</b>' from '<b>{{ payload.Metadata.grandparentTitle }}</b>' started on {{ player_title }}!"
          title: "Plex Playback"
          data:
            html: true
            # Replace 'http://YOUR_PLEX_IP:YOUR_PLEX_PORT' and 'YOUR_PLEX_TOKEN_HERE'.
            # For TV show episodes, 'grandparentThumb' is typically the show's poster.
            image: "http://192.168.1.50:32400{{ payload.Metadata.grandparentThumb }}?X-Plex-Token=ANOTHER_RANDOM_TOKEN_DEF456GHI"
            notification_icon: "mdi:television-play"
            clickAction: /media-info/plex # Example: /automation/logs
    library_new_movie:
      - service: notify.mobile_app_main_phone # Example: notify.mobile_app_home_hub
        data:
          message: "New Movie Added: <b>{{ payload.Metadata.title }}</b> 🎬"
          title: "Plex Library Update"
          data:
            html: true
            # Replace 'http://YOUR_PLEX_IP:YOUR_PLEX_PORT' and 'YOUR_PLEX_TOKEN_HERE'.
            image: "http://192.168.1.50:32400{{ payload.Metadata.thumb }}?X-Plex-Token=YET_ANOTHER_TOKEN_JKL789MNO"
            notification_icon: "mdi:filmstrip-new"
            clickAction: /media-info/plex # Example: /lovelace/library_overview
    library_new_tv_show:
      - service: notify.mobile_app_main_phone # Example: notify.mobile_app_guest_tablet
        data:
          message: "New TV Show Episode Added: <b>{{ payload.Metadata.title }}</b> from <b>{{ payload.Metadata.grandparentTitle }}</b> 🎬"
          title: "Plex Library Update"
          data:
            html: true
            # Replace 'http://YOUR_PLEX_IP:YOUR_PLEX_PORT' and 'YOUR_PLEX_TOKEN_HERE'.
            # For new TV show episodes, 'grandparentThumb' is typically the show's poster.
            image: "http://192.168.1.50:32400{{ payload.Metadata.grandparentThumb }}?X-Plex-Token=FINAL_RANDOM_TOKEN_PQR012STU"
            notification_icon: "mdi:new-box"
            clickAction: /media-info/plex # Example: /tv-shows/new_releases
1 Like

Thank you for the feedback.

Glad that this has helped.

1 Like

Thank you for this blueprint - it’s great, and works very well.

I have just one question. My webhooks are working as required, but I cannot get the ‘Server Owner Actions’ to work - am I missing something?

Hi @Gotcha1980 ,

Glad you have found it useful.

What are you trying to get the Server Owner Actions to do?

If Webhooks are triggering Ok, then try Admin Playback Started.

The default code I put there as an example should be:

metadata: {}
data:
  title: "{{ payload.Account.title }} -  Playback started"
  notification_id: plex_user_playback_{{ payload.Account.title }}
  message: " {{ payload.Account.title }} has started {% if payload.Metadata.type == 'album' %} listening to the album {{ payload.Metadata.title }} by {{ payload.Metadata.parentTitle }} {% elif payload.Metadata.type == 'movie' %} to watch the movie {{ payload.Metadata.title }} {% elif payload.Metadata.type == 'episode' %} to watch the TV show {{ payload.Metadata.grandparentTitle }} {% else %} interacting with Plex Media Server {{ payload.Server.title }} {% endif %} on the device {{ payload.Player.title }}"
action: persistent_notification.create

and when you switch to another user within your plex environment and start playback you should see something along the lines of this within your home assistant notifications:

Also worth checking thetrace for the automation shows:

Database Backups are taken every 3 days by Plex and I have fortunately not seen Database Corruption being triggered.

This is excellent! I love it.
I’ve got Plex triggering lighting controls and updates on the MAX7219 display…
Now, I need to find someone to 3d print a nice enclosure for the display …

thanks OP!

1 Like

updated the blueprint to v0.4.7

corrected the server owner actions for Admin Playback trigger, it was only capturing audio playback, have fixed to media.play from playback.started and it is capturing movies, episodes and movies events. (that was a bad idea, reverted that. Apologies.)

Have also updated the default message for this event as well.

Can you add an option to not specify client(s) ?

I have an automation where I would like to show who plays what no matter what user and/or player they are coming from.

hey @riro,

Try using the Generic Playback actions, and under that the playback started option. This is triggered before the player specific actions.

I copied this code, from the Admin Playback Started example in the blueprint to the Generic section (
The Admin Playback Started shows all users minus the main Plex account). I can see notifications appearing :

metadata: {}
data:
  title: "{{ payload.Account.title }} -  Playback started"
  notification_id: plex_user_playback_{{ payload.Account.title }}
  message: >-
    {{ payload.Account.title }} has started {% if payload.Metadata.type ==
    'track' %}listening to {{ payload.Metadata.title}} by {% if
    payload.Metadata.originalTitle is defined and
    payload.Metadata.originalTitle|length > 0 %} {{
    payload.Metadata.originalTitle }} {% else %} {{
    payload.Metadata.grandparentTitle }} {% endif %} from the album {{
    payload.Metadata.parentTitle }}{% elif payload.Metadata.type == 'movie' %}to
    watch the movie {{ payload.Metadata.title }} ({{ payload.Metadata.year }})
    directed by {{ payload.Metadata.Director[0].tag }}{% elif
    payload.Metadata.type == 'episode' %}to watch the TV show {{
    payload.Metadata.grandparentTitle }} Season {{ payload.Metadata.parentIndex
    }} Episode {{ payload.Metadata.index }} ({{ payload.Metadata.title }}){%
    elif payload.Metadata.type == 'album' %}listening to the album {{
    payload.Metadata.title }} by {{ payload.Metadata.parentTitle }}{% else %}
    interacting with Plex Media Server {{ payload.Server.title }}{% endif %}{%
    if payload.Player.title|length > 0 %} on the device {{ payload.Player.title
    }}{% endif %}
action: persistent_notification.create

1 Like

Ah, that easy :slight_smile:

(btw, really annoying with the formatting of the Jinja when switching between UI and yaml editor)