Perform an Action when Plex HTPC Plays a Movie

Hello all

I Hope you are Well.

I received my Home Assistant Green this Morning and have been tinkering for the last Few Hours setting everything up.

I have Plex Media Server and Plex HTPC Installed on a PC in the Living Room which were automatically found once the Plex Integration was Installed.

I would like for Home Assistant to perform an Action when a Movie is Played from the Movies Library, is this possible?

In the Future, a few Months, hopefully, I will be adding Phillips Hue Lights which I would like to Dim when the Playback of a Movie Starts.

All of the Movies are MKV Files.

Thanks in advance

Kevin

sure create a new automation, add a trigger > device > plex (whichever player) - starts playing

I would recommend keeping it simple as possible and use separate automations for different things, later as you learn and get more comfortable, you can make things more complex with stuff like;

you may or may not want to also choose some ‘and if’ restrictions, and/or use - actions/choose to pick between multiple behaviors depending on other criteria.

Hello

Thanks for the Reply.

I have Created a Sensor that Reads the Media Library from Plex HTPC, here:

{{state_attr(‘media_player.plex_plex_htpc_for_windows_knc_htpc’, ‘media_library_title’) }}

I then Created the Automation with the following Template Condition:

{{ states(‘sensor.plex.media_library’) == ‘Movies’ }}

For some reason, when this line is set to ‘Movies’ it will not work, however, if it is Changed to ‘Music’ then it works fine.

For now I just have it Send a Notification if it works, which it does, if it is set to ‘Music’.

Any suggestions?

Thanks in advance

Kevin

I don’t know why you would need or want a sensor, when the plex device integration provides triggers for playing and other conditions as I suggested above.

Hello

Thanks for the Reply.

I want to create the Automation for Movies Only, so, I need to know which Media Library is being used.

I could not find a way to do that without creating a Sensor.

Thanks

Kevin

Hello

Well, I have discovered something.

If I have Music Playing and then Start a Movie, without Stopping the Music, Home Assistant does not know that the Movie is Playing.

If I Stop the Music First and then Play the Movie then Home Assistant shows the information for the Movie and its Library fine.

I like to keep the Music Playing when I Start a Movie as when the Movie Stops, the Music picks up where it left off.

Any suggestions?

Thanks in advance

Kevin

Hello all

Does @jjlawren still maintain the Plex Integration?

If I Stop the Music from Playing before I Start the Movie the Automation works as expected.

However, if the Music is Playing when I Start the Movie the Automation Fails, it thinks that Music is still Playing when in fact the Movie is.

I also want to Add that when the Movie Finishes or is Stopped then the Light gets Switched On again but I have not got round to that, yet.

I really do not want to have to Stop the Music Playing whenever I want to Watch a Movie as it means I will have to Shuffle the Music again, meaning, possibly having to listen to the same Songs again and again.

Does the User who maintains the Plex Integration frequent these Boards?

Thanks in advance

Kevin

Please do not tag people who are not already part of this thread.

I suggest you read the Plex integration docs and double check if there’s something you missed. I don’t use it, but the docs state that there should be an activity sensor which shows active users & media streams which you might be able to use.
Also, have a look here - I believe you should be using movie instead of movies

Hello

Thanks for the Reply.

I just refer to a Movie as that is what it is. sorry :slight_smile:

In the Automation it is referred to as a Film.

Also, the Automation works perfectly if Music is not Playing when a Movie is Started so I know that the Automation works as intended it is just that one crinkle.

Thanks

Kevin

Hello all

I Hope you are Well.

After some more Testing Today…

I left the Automations Active, I had Disabled them as they were not working, seeminly.

I had Music Playing and then I started Playing a Movie, the Automation did not Run when the Movie Started Playing, however, approximately 10 Minutes after the Movie Started, the Automation kicked in.

The Living Room Light Turned Off and the LED Lights behind the TV Turned On.

I have no idea how to Troubleshoot this one as the Automation clearly works, however, if Music is Playing when I Start Playing a Movie there is a 10 Minute Delay before the Automation is Run.

If no Music is Playing when a Movie Starts Playing then the Automation is executed immediately upon the Movie Starting.

Thanks

Kevin