Hi everyone,
in my growing quest to make my home act just like a movie theater. after hours of trying I got my lights to turn on right when the credits roll. This is perfect moment to discus the movie with my girlfriend or just sit and ponder.
Sensors needed down below because I saw some people online asking this question a few years ago and nobody seems to have a way to do it.
command_line:
- sensor:
name: Plex_Media_ID
command: "curl -s 'http://<Plex_IP>:32400/status/sessions?X-Plex-Token=<Plex_Token>' | grep -o 'key=\"/library/metadata/[0-9]*' | head -n 1 | sed 's/key=\"//' | sed 's/\"$//'"
scan_interval: 10
value_template: "{{ value }}"
- sensor:
name: Plex_Credit_Chapters
command: >
curl -s GET "http://<Plex_IP>:32400{{ states('sensor.plex_media_id') }}?X-Plex-Token=<Plex_Token>&includeChapters=1&includeMarkers=1" |
grep -o '<Marker[^>]*type="credits"[^>]*>' |
head -n 1 |
sed -n 's/.*startTimeOffset="\([^"]*\).*/\1/p'
scan_interval: 10
value_template: "{{ value }}"
- sensor:
name: Plex_Position
command: curl -s 'http://<Plex_IP>:32400/status/sessions?X-Plex-Token=<Plex_Token>' | grep -o 'viewOffset="[0-9]*"' | sed 's/viewOffset="//' | sed 's/"//'
scan_interval: 10
value_template: "{{ value }}"
first sensor is needed so we can actually see what is being played on the session. If you don’t know your plex token check out this from plex’s website
This first sensor basically gets the media ID so we can grab the actual info that we need to see when the credits roll. second sensor grabs the credit marker. this is the point in the movie/show where the credits start rolling. I then tried to compare that to the play position in the original plex integration but that did not update quickly enough for me to actually use it so now we have to make an api call every 10 seconds to get the position (that’s what the last sensor is for.) then for an automation the just check if the position is above the credit marker, if so we turn on the lights.
You could probably update the last API call a lot more but I did not want to risk overloading my plex server with API calls and I didn’t mind the 10 seconds it sometimes takes to turn on the lights (my home town movie theater has about the same delay so I kind of like it).
Would also probably be smart to only update the sensors when your mediaplayer detects when it is playing plex.
could probably do it with the restful integration but I was more comfortable using curl commands