Simple Home Assistant Notification when Plex is Playing

by Danny
0 comment

READING TIME: 4 MINUTES

In this guide, I’ll show you how to create an automation that sends a notification whenever one of your Plex users start watching something. This automation was found in this community forum post.

This is handy for a lot of reasons. Sometimes it’s neat to just see who is actually utilizing your Plex server. Other times it might be handy to know whether or not you can reboot your Plex server depending on if it’s currently being used. I usually check Tautulli to see if it’s in use, but that requires me to log into Tautulli first. This just sends me a quick alert.

The creator of this automation noted that pictures don’t come through on Apple devices. It can probably be done by looking at the notification documentation. I use Android luckily.


Step 1: Set up Plex Integration

The first thing you’ll need to do is setup the official Plex Integration in Home Assistant. Once that is setup, go to Configuration > Integrations.

You should see a list of entities it has created:

Look for all the media_player entities:

The entities shown here are both Plex users in my home and Plex users that I have shared my library with. This notifies me whenever ANYONE starts watching something.

The logic in the script also won’t continually alert you if someone starts, pauses, and resumes playing media. It will only alert you if it goes from an idle or unavailable state to playing.


Step 2: Create Automation

Next, go to Configuration > Automations & Scenes. Create a new automation.

Click the 3 dots in the top-right corner > Edit in YAML. Then paste this code:

alias: Notifications Plex
description: ''
trigger:
  - platform: state
    from:
      - idle
      - unavailable
    to: playing
    entity_id:
      - media_player.plex_plex_for_android_mobile_pixel_5
      - media_player.plex_plex_for_roku_50_tcl_roku_tv
      - media_player.plex_plex_for_roku_65_tcl_roku_tv
      - media_player.plex_plex_for_roku_roku_streaming_stick
      - media_player.plex_plex_web_chrome
      - media_player.plex_shelly_plex_for_ios_michelles_iphone
action:
  - service: notify.mobile_app_pixel_5_danny
    data:
      title: Playing on {{ device }}
      message: |
        {% if series == None %}
          {{ title }}
        {% else %}
          {{ series }} - {{ title }}
        {% endif %}
      data:
        icon_url: '{{ picture }}'
mode: single
variables:
  device: '{{ state_attr(trigger.entity_id, ''friendly_name'') }}'
  series: '{{ state_attr(trigger.entity_id, ''media_series_title'') }}'
  title: '{{ state_attr(trigger.entity_id, ''media_title'') }}'
  picture: '{{ state_attr(trigger.entity_id, ''entity_picture'') }}'
  • Replace the blue text with your media player entity names.
  • Replace the notify service with your phone. If you don’t know how to find the notify service associated with your phone, a quick way to find it is by going to Developer Tools > Services. Type notify.mobile_app.

In the dropdown, it’ll show you a list of devices you can send notifications to.


Step 3: Test It Out

Next, simply start playing a Plex TV show or movie on one of the devices you added to the automation. If all goes well, you should get a phone notification that looks like this:

For Movies:

For TV Shows:


Alternate Notification – Display User, Season, and Episode

If you’d like to see who is watching something in the notification (as well as the season and episode number) you could create an automation like this instead. Personally I prefer this one.

alias: Notifications Plex
description: ''
trigger:
  - platform: state
    from:
      - idle
      - unavailable
    to: playing
    entity_id:
      - media_player.plex_plex_for_android_mobile_pixel_5
      - media_player.plex_plex_for_roku_50_tcl_roku_tv
      - media_player.plex_plex_for_roku_65_tcl_roku_tv
      - media_player.plex_plex_for_roku_roku_streaming_stick
      - media_player.plex_plex_web_chrome
      - media_player.plex_shelly_plex_for_ios_michelles_iphone
      - media_player.plex_plex_web_chrome_2
action:
  - service: notify.mobile_app_pixel_5_danny
    data:
      title: '{{ username}} started playback on {{ device }}'
      message: |
        {{ series }} - S{{ season }}E{{ episode }} - {{ title }}
      data:
        icon_url: '{{ picture }}'
mode: single
variables:
  device: '{{ state_attr(trigger.entity_id, ''friendly_name'') }}'
  series: '{{ state_attr(trigger.entity_id, ''media_series_title'') }}'
  title: '{{ state_attr(trigger.entity_id, ''media_title'') }}'
  picture: '{{ state_attr(trigger.entity_id, ''entity_picture'') }}'
  username: '{{ state_attr(trigger.entity_id, ''username'') }}'
  season: '{{ state_attr(trigger.entity_id, ''media_season'') }}'
  episode: '{{ state_attr(trigger.entity_id, ''media_episode'') }}'

Wrapping Up

Hopefully you found this simple Plex Watching automation useful in Home Assistant! It can probably be tweaked to show user who is watching, season, and episode number, so once I figure that out – I’ll update this post.

0 comment

You may also like

Leave a Comment