I love this, great job! I just set it up and it works great. Triggered when Plex played something on my phone, my Roku TV, and Roku streaming stick.
As for recommended changes, I think you should set it to run only if the state of that entity wasn’t set to paused. Right now I get notifications every time I pause/resume.
@chezpaul2
Just change the media_player entities with yours !
Don’t forget to also change the notify.mobile_app_<phone name>with your phone that has the home assistant app.
You also asked if it was working only for the guests. No, it works for every plex client you have that can connect to your plex server. So even your friend that are far away that use your plex will give a notification !
@djbrooks022
Good idea, I’ll work on it when I got time. I’ll tag you when I update this script.
@aceindy
If you were talking to me, I don’t understand what do you mean with
sensor.plex_name
unit_of_measurement: Watching
I’m not sure that a media player has a unit of mesurment ?
@aceindy updated to only pop up once when starting playing from an idle or unavalaible state. no more spamming when pausing / unpausing !
EDIT:
Pictures seams to not work with apple products (tested on iphone and apple watch). If you are an apple user, please read the notification documentation and try to help us to make it work !
This is a great little script that works really well. I changed it slightly so it shows me the user name and the Season and Episode number of a show as well.
The only issue I’m running into (but that doesn’t seem to be related to this script) is that when I start something on my Apple TV, the user name shows up as `none’. All other devices show the user name correctly so it’s likely related to the Apple TV integration.
I would appreciate knowing how to extend this to when the show is stopped. Currently I seem to be running into a problem which I believe is because various state attributes become unavailable when the
state of the media player goes to idle.
I tried to sort this with trigger.from_state.attributes.media_season or state_attr(trigger.from_state, media_season) to pick up what was being played but I still couldn’t get it to function, I think because the other variables contained in the script were still expecting to have values but couldn’t take any. Templating is not my strong point!
I believe you are right, the variables are blank because the state changed already. The closest I could get is the device name in the automation, like this. Just doesn’t show any TV show info.
alias: Notifications Plex - Stopped (Test)
description: ''
trigger:
- platform: state
from:
- playing
to: idle
entity_id:
- media_player.plex_plex_web_chrome_2
condition: []
action:
- service: notify.mobile_app_pixel_5_danny
data:
title: 'Playback on {{ device }} ended'
message: |
Show was stopped.
mode: single
variables:
device: '{{ state_attr(trigger.entity_id, ''friendly_name'') }}'
I think the reason it wasn’t working before is because I was filtering variables that didn’t exist (in the variables section) or I was using a replace filter on device in the variables section (which did exist, but for some reason it didn’t like it). Anyway, this works, I just need to create a wildcard somehow for media_player.plex* so that I don’t have to list out everything.
PS - these if statements all work fine, except for the icon_url one, which always returns false apparently. This means when a show is playing or paused, it can find the show/movie picture. However, if it’s idle/unavailable, then it does not find the picture and no picture is displayed. Can’t figure out why this is.
EDIT - I tried putting a static icon for the prevpicture part of the template but it still didn’t work.