This script didn’t have everything I needed so I decided to make some improvements.
Since the resulting script works so well for me I thought I share it with the rest of you.
Features:
- Differentiates between photo, audio and video playback
- Differentiates between multiple plex clients
- Reports the playback of multiple clients simultaneously. No need to run multiple script instances. Just fill in the names of the clients it should listen for.
- Ability to show Play Progress
- Automatically clears the device log to prevent cluttering the database (can be turned off)
- Automatically creates and updates an status user variable for each client specified in the settings.
- Status Codes:
- -1: Plex Server Offline
- 0: Client Idle
- 1: Playing Video
- 2: Paused Video
- 3: Stopped Video
- 11: Playing Audio
- 12: Paused Audio
- 13: Stopped Audio
- 21: Showing Photo
- 22: Paused Slideshow
- Status Codes:
- Quick detection of stopped state on Video & Audio (10 seconds)
- In Domoticz create an text object or each for of the plex clients you wish monitor, write down their corresponding IDX
- Open the script in notepad and change the domoticz and plex IP/port to match your own setup.
- Enter the names of the plex clients under dom_PlexPlayers and their corresponding text object idx under dom_PlexPlayInfo_ID
- Save the script
Assign 0775 permission to the plex.py file.
Create a cronjob to attempt to run the script every 10 minutes.
Code: Select all
*/10 * * * * /home/pi/domoticz/scripts/python/plex.py
If everything went right you could soon be seeing something similar to this when you play something
If you still run into problems (permission issues) strip the PIDFile lines from the file and run the script at reboot (thanks to bob123bob)
Code: Select all
@reboot python /home/pi/domoticz/scripts/python/plex.py &
Use the user variables this script creates to trigger events.
Authentication
The script is made for Plex Server sthat are setup NOT to use authentication. If your server does use authentication try the following: under Plex Options>Server>Network you can specify which networks can access the server without authentication. You can enter specific IP addresses or whole networks (e.g 192.168.0.1) don’t forget to add the subnet as shows in the settings description.
When using Plex Home: Fill in the plexToken parameter in the script. Follow these instructions to retrieve the token.
Script:
Get the code on my github page:
https://github.com/racquemis/DomoticzSc ... ython/plex
Bugs
Please let me know if you encounter an error.