Simple notifications when Plex is playing

So I’ll put this note here because I discovered my solution from playing around after your post.

I was having a problem where mine wasn’t showing any picture at all on HASS.Agent.
I tried the quotations & it didn’t change anything.
Then I tried https since I prefer it to use the SSL I had set up & with the

        image: https://homeassistant.local:8123{{ picture }}

it didn’t work
But when I put in my SSLed DNS it finally showed the picture properly

        image: https://www.MYuniqueSUBDOMAIN.duckdns.org:8123{{ picture }}

So anyone else having that issue there’s a solution

Question: is there any way to get it to format the Season & Episode with 2 digits?
I like this & am using it, but it just looks weird to me saying Show Name S1E4 - Episode Title instead of Show Name S01E04 - Episode Title

That may be just my preference, but I feel others might feel the same, I just have no idea how to make it return the Season & Episode values with at least 2 digits

I haven’t found a way to do so unfortunately. I agree it looks a bit weird like this.

No worries, For now I have just changed it to

      {{ series }} S0{{ season }}E0{{ episode }} - {{ title }}

It’s pretty solid for season since most have less than 10, Episodes however look a bit odd with S02E011 but personally I think that looks less off-putting. I was just curious, if it’s a limitation of the scripting then it is what it is. What language is the scripting done in?

Anyway. It’s a great automation either way.

I came across a problem that I would like to know if it’s a known issue or not. It may well be that there is no way to fix it, I would just like to bring it up in case it hadn’t been looked into.

When I get notifications that something is playing I get USERNAME started playback on DEVICE but if I get another notification from a different device, or from 3 devices at the same time, it just has a single Username on top of all the messages, I believe the last to play something, but could be the 1st, not sure. I’d much prefer to have the device & user connected to the notification. I suppose the reason for this is because the Title changes with each notification, & it just updates the previous Title to the new Title. Ideally I’d prefer to have devices grouped together, if possible.

I’m going to attempt to make different automations for each different device, hopefully that will give me what I’m looking for, but wondered if anyone else had this issue?

So having separate automations still gets them grouped into a single clump it seems.

I have moved the username to the message instead of the title, but still hoped that the separate devices would be grouped together.
Here’s what I’m using

    data:
      title: Playback started on {{ device }}
      message: |
        {% if series == None %}
          '{{ username}} started {{ title }}'
        {% else %}
          {{ username}} started {{ series }} - S0{{ season }}E0{{ episode }}
          {{ title }}
        {% endif %}

Edit: I gave up trying to get the Title to be separate instead of just the last device to start. Instead I just put all the information in the Message & just changed the Title to “Plex Playback Started” since it is lost when another message comes in

This is what I have now

    data:
      title: Plex Playback Started
      message: |
        {% if series == None %}
          {{ device }}
          {{ username}} started {{ title }}
        {% else %}
          {{ device }}
          {{ username}} started {{ series }}
          S0{{ season }}E0{{ episode }} - {{ title }}
        {% endif %}

Not sure how doable this is but i recently started using prerolls on my plex server (which work great) but this notification gets sent when the preroll plays as well. Does anyone know if there’s a way to not have the notification triggered when the video is only short?

Thanks for the ideas, I just sat down and made a plex notification based on some of the snippets from this thread. One thing I wanted to do, was to keep the media players generic, since plex will create them anytime you add or change a device. As such, this is what I ended up with.

The basic idea is, that when the number of Plex streams increases, we find the media player entity that’s playing and has the latest last changed timestamp, then use that entity for the notification.

alias: Plex automation
description: Notify on a new Plex stream
trigger:
  - platform: state
    entity_id: sensor.plex_son_of_joel
    for: "00:00:05"
condition:
  - condition: template
    value_template: "{{ trigger.from_state.state|int(0) < trigger.to_state.state|int(0) }}"
action:
  - variables:
      last_playing_mp: >-
        {{ (states.media_player  | sort(attribute='last_changed') |
        selectattr('state', 'eq', 'playing') | list | last).entity_id }}
      user: "{{ state_attr(last_playing_mp, 'username') }}"
      device: "{{ state_attr(last_playing_mp, 'friendly_name') }}"
      series: "{{ state_attr(last_playing_mp, 'media_series_title') }}"
      title: "{{ state_attr(last_playing_mp, 'media_title') }}"
      picture: "{{ state_attr(last_playing_mp, 'entity_picture') }}"
      media_album_artist: "{{ state_attr(last_playing_mp, 'media_album_artist') }}"
      media_type: "{{ state_attr(last_playing_mp, 'media_content_type') }}"
      title_string: >-
        {% if media_type == 'tvshow' %}
            {{ series }} - {{ title }}
        {% elif media_type == 'movie' %}
            {{ title }}
        {% elif media_type == 'music' %}
            {{ media_album_artist }} - {{ title }}
        {% endif %}
  - service: notify.all_android_devices
    data_template:
      title: "{{ user }} is Streaming {{ title_string }}!"
      message: "{{ user }} is Streaming {{ title_string }} on {{ device }}."
      data:
        icon_url: "{{ picture }}"
mode: single