Plex Status - Video, Audio, Photo, Play Progress

Python and python framework

Moderator: leecollings

cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

This is my cron, and what ill could see its correct.

Code: Select all

#
# m h  dom mon dow   command
#*/10 * * * * sudo python /home/pi/domoticz/scripts/python/check_device_online_$
@reboot python /home/pi/domoticz/scripts/python/plex.py &
*/5 * * * *  /home/pi/domoticz/scripts/python/plex.py
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Remove the last line from the crontab. Without the PID-stuff in the script the script won't check if it is already running. with the last line you are spawning a new instance every 5 minutes. Remove that line and reboot.

besides the last line the crontab is correct.
What evidence do you have that the script is not running? Does the Text dummy device not update? Did the script create the user variable?
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

Okey, now ive checked. The text-dummy is updating as it should after remove the last line in cron.
But the variables does not update.
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

I don't know. it should work out of the box. Are the user variables actually created? The PLEX STATUS [xxxx] variables?
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

The variables updates when ill run the script manually, not when the plex is running.
jimtrout87
Posts: 16
Joined: Tuesday 12 April 2016 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by jimtrout87 »

I am having some issues with this script and cannot work out the fix. It works for a day or two after first run but then stops updating variables and leaves behind the text for now playing. The text is always shows and always play progress shows as nearly finished, but i know the script is still doing something as if i play another show\film it will update the text but not the variables.

Its set up as a cron job but i think its not being restarted as its not actaully stopped - just running with issues?. My only fix is to manually stop\start.

Can anyone help?
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

The problem you are describing is a problem in the detection of a video finishing playing. I can remember fixing this problem.
I've updated the script a couple of times, are you on the most recent listed now in the first post?

I'm looking over the code to see if i made any mistakes, i'll let you know if i locate issues.

EDIT: Removed some code that limited the amount of http requests for the user variables
Try this:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
import traceback
import sys
import datetime
import time
import os
import urllib, urllib2, hashlib,subprocess
from xml.etree import ElementTree as ET
ErrorCount = 0
#general Script settings
plex_Interval                 = 5     # Poll Interval. The Plex Server updates the session status every 10 seconds. Leave at 5 to not mis any state change.
plex_ShowPlayProgress         = True 
plex_AutoClearPlayLog         = True  # Should be enabled when showing Play Progress
plex_AutoCreateUserVariables  = True  # Automatically create a user variable for each Client listed under dom_PlexPlayers
plex_ViewOffsetTimeout        = 15    # In seconds.
plex_MaxErrorCount            = 3     # number of consecutive errors until Plex is considered Offline

#RunState values (for user variable)
plex_ServerOffline    = -1
plex_Idle             = 0
plex_Video_Playing    = 1
plex_Video_Paused     = 2
plex_Video_Stopped    = 3
plex_Video_Buffering  = 4
plex_Audio_Playing    = 11
plex_Audio_Paused     = 12
plex_Audio_Stopped    = 13
plex_Audio_Buffering  = 14

#Plex Server Settings
plexIP                 = '192.168.0.142'
plexPort               = '32400'          # (default port = 32400)
plexToken              = ''               # (Fill in when using Plex Home. To Retrieve Token: https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token)

#domoticz settings
domoticz_host          = '192.168.0.148'
domoticz_port          = '8080'
domoticz_url           = 'json.htm'

#Translation Array - It's also possible to specify custom search strings. Place them at the beginning of the array.
transl_search    = ['Playing','Stopped','Buffering','Paused','Video','Movie','Episode','Clip','Audio','Slideshow']
transl_replace    = ['','','','','','','','','',''] #place replacement string on the same index as the search string. empty strings are not processed.

#Plex Players Settings - This script handles multiple players
dom_PlexPlayers        = ['OpenELEC-PHT','Jasper-TPC'] #Players not on this list will be ignored
dom_PlexPlayInfo_ID    = ['24','30']
dom_PlexPlayState_ID   = ['','']          # Name of User Variable. Is overwrriten when plex_AutoCreateUserVariables=True

#Various Variables
plex_TimeLastUpdate    = ""
plex_LastOffsetUpdate  = []  # of loop iterations
plex_LastOffset        = []
plex_PreviousState     = []
plex_PreviousTitle     = []
plex_AlreadyIdle       = []

#building url
requestURL = 'http://'+ plexIP + ':' + plexPort + '/status/sessions/?X-Plex-Token=' + plexToken

#Ensure equal list sizes
while len(dom_PlexPlayInfo_ID)<len(dom_PlexPlayers):
  dom_PlexPlayInfo_ID.append('-1')
while len(dom_PlexPlayState_ID)<len(dom_PlexPlayers):
  dom_PlexPlayState_ID.append('-1')
while len(plex_LastOffsetUpdate)<len(dom_PlexPlayers):
  plex_LastOffsetUpdate.append(1)
while len(plex_LastOffset)<len(dom_PlexPlayers):
  plex_LastOffset.append(1)
while len(plex_PreviousState)<len(dom_PlexPlayers):
  plex_PreviousState.append('0')
while len(plex_PreviousTitle)<len(dom_PlexPlayers):
  plex_PreviousTitle.append('0')
while len(plex_AlreadyIdle)<len(dom_PlexPlayers):
  plex_AlreadyIdle.append(False)
while len(transl_replace)<len(transl_search):
  transl_replace.append('')

# create play Status user variable for each client
if plex_AutoCreateUserVariables:
  for client in dom_PlexPlayers:
    try:
      name = "PLEX STATUS [" + client + "]"
      url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=saveuservariable&vname=" + name + "&vtype=Integer&vvalue=" + str(plex_Idle)
      url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
      urllib2.urlopen(url , timeout = 5)
      idx = dom_PlexPlayers.index(client)
      dom_PlexPlayState_ID[idx] = name
    except Exception:
      print 'Connection Error'

pidfile = sys.argv[0] + '_' + plexIP + '.pid'
if os.path.isfile( pidfile ):
  if (time.time() - os.path.getmtime(pidfile)) < (float(5) * 3):
    print datetime.datetime.now().strftime("%H:%M:%S") + "- script seems to be still running, exiting"
    print datetime.datetime.now().strftime("%H:%M:%S") + "- If this is not correct, please delete file " + pidfile
    sys.exit(0)
  else:
    print datetime.datetime.now().strftime("%H:%M:%S") + "- Seems to be an old file, ignoring."
else:
  open(pidfile, 'w').close()

  
def translate(playstring):
  returnstring = playstring
  for idx in range(0, len(transl_search)):
    if transl_replace[idx]!='':
      returnstring = returnstring.replace(transl_search[idx],transl_replace[idx])
  print returnstring;
  return returnstring; 
  
while 1==1:
  try:
    #call session url
    ProcessedIDs=[]
    test = urllib2.urlopen(requestURL,timeout = 5).read()
    root = ET.XML(test)
    #Video Support
    for video in root.findall('Video'):
      # Get Attributes for each player
      player = video.find('Player').attrib['title']
      state = video.find('Player').attrib['state']
      parenttitle = video.get('grandparentTitle')
      videotitle = video.get('title')
      videotype = video.get('type')
      videoduration = video.get('duration')
      viewOffset = video.get('viewOffset')
      PlayProgress=''
      if plex_ShowPlayProgress and videoduration is not None:
        durTotalSeconds = long(long(videoduration) / 1000)
        durSeconds = int(durTotalSeconds % 60)
        durTotalSeconds /=60
        durMinutes = int(durTotalSeconds % 60)
        durTotalSeconds /=60
        durHours = int(durTotalSeconds)
        if viewOffset is not None:
          runTotalSeconds = long(long(viewOffset) / 1000)
          runSeconds = int(runTotalSeconds % 60)
          runTotalSeconds /=60
          runMinutes = int(runTotalSeconds % 60)
          runTotalSeconds /=60
          runHours = int(runTotalSeconds)
        else:
          runSeconds=0
          runMinutes=0
          runHours=0
        PlayProgress= ' (' + str(runHours) + ':' + str(runMinutes).zfill(2) + ':' + str(runSeconds).zfill(2) + '/' + str(durHours) + ':' + str(durMinutes).zfill(2) + ':' + str(durSeconds).zfill(2) + ')'
      else:
        PlayProgress=""
      PlayString = ""
      StateChange = 0
      PlayerID = dom_PlexPlayers.index(player) if player in dom_PlexPlayers else -1
      if PlayerID >= 0:  #only process players that are on the list
        plex_AlreadyIdle[PlayerID] = False
        try:
          # Check if there is progress
          if (viewOffset>plex_LastOffset[PlayerID] and state=="playing") or  (videotitle!=plex_PreviousTitle[PlayerID]):
            plex_LastOffsetUpdate[PlayerID] = 0
          elif viewOffset == plex_LastOffset[PlayerID]:
            plex_LastOffsetUpdate[PlayerID] += 1

          if plex_LastOffsetUpdate[PlayerID] >= int(plex_ViewOffsetTimeout/plex_Interval) and state == "playing":
            state = "stopped"

          if plex_PreviousState[PlayerID] == state:
            StateChange = 0
          else:
            StateChange = 1
            plex_PreviousState[PlayerID]=state

          plex_PreviousTitle[PlayerID] = videotitle
          
          if videotype == 'movie':
            PlayString = state.capitalize() + " Movie: " + videotitle + PlayProgress
          elif videotype =='episode':
            PlayString = state.capitalize() + " Episode: " + parenttitle + " - " + videotitle + PlayProgress
          elif videotype =='clip':
            PlayString = state.capitalize() + " Clip: " + parenttitle + " - " + videotitle + PlayProgress
          else:
            PlayString = state.capitalize() + "Video " + ": " + videotitle + PlayProgress
          #uploading log message to domoticz
          PlayString = urllib.quote(translate(PlayString).encode("utf-8"))
          if StateChange == 1:
            url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=addlogmessage&message=" + PlayString
            urllib2.urlopen(url , timeout = 5)

          statusValue = 0
          if state == "playing":
            statusValue = plex_Video_Playing
          elif state == "paused":
            statusValue = plex_Video_Paused
          elif state == "stopped":
            statusValue = plex_Video_Stopped
          elif state =="buffering":
            statusValue = plex_Video_Buffering

          #uploading values to domoticz
          url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=" + PlayString
          urllib2.urlopen(url , timeout = 5)
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[PlayerID] + "&vtype=integer&vvalue=" + str(statusValue))
          url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
          urllib2.urlopen(url,timeout = 5)
          
          if plex_LastOffset[PlayerID] != viewOffset or state=="stopped":
            if plex_AutoClearPlayLog:
              url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=clearlightlog&idx=" + dom_PlexPlayInfo_ID[PlayerID]
              urllib2.urlopen(url , timeout = 5)
          plex_LastOffset[PlayerID] = viewOffset
          
          ProcessedIDs.append(PlayerID)
      
        except Exception,e:
          print 'IDLE'
          print e
          print traceback.print_exc()
          #uploading values to domoticz
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=No%20Media%20Playing")
          urllib2.urlopen(url,timeout = 5)
          pass
    #Audio Support
    for audio in root.findall('Track'):
      # Get Attributes for each player
      player = audio.find('Player').attrib['title']
      state = audio.find('Player').attrib['state']
      parenttitle = "Unknown"
      parenttitle = audio.get('grandparentTitle')
      audiotitle = audio.get('title')
      audioduration = audio.get('duration')
      viewOffset = audio.get('viewOffset')
      PlayProgress=''
      if plex_ShowPlayProgress:
        durTotalSeconds = long(long(audioduration) / 1000)
        durSeconds = int(durTotalSeconds % 60)
        durTotalSeconds /=60
        durMinutes = int(durTotalSeconds % 60)
        durTotalSeconds /=60
        durHours = int(durTotalSeconds)
        if viewOffset is not None:
          runTotalSeconds = long(long(viewOffset) / 1000)
          runSeconds = int(runTotalSeconds % 60)
          runTotalSeconds /=60
          runMinutes = int(runTotalSeconds % 60)
          runTotalSeconds /=60
          runHours = int(runTotalSeconds)
        else:
          runSeconds=0
          runMinutes=0
          runHours=0
        PlayProgress= ' (' + str(runHours) + ':' + str(runMinutes).zfill(2) + ':' + str(runSeconds).zfill(2) + '/' + str(durHours) + ':' + str(durMinutes).zfill(2) + ':' + str(durSeconds).zfill(2) + ')'
      else:
        PlayProgress=""
      PlayString = ""
      StateChange = 0
      PlayerID = dom_PlexPlayers.index(player) if player in dom_PlexPlayers else -1
      if PlayerID >= 0:  #only process players that are on the list
        plex_AlreadyIdle[PlayerID] = False
        try:
          # Check if there is progress
          if (viewOffset>plex_LastOffset[PlayerID] and state=="playing") or  (audiotitle!=plex_PreviousTitle[PlayerID]):
            plex_LastOffsetUpdate[PlayerID] = 0
          elif viewOffset == plex_LastOffset[PlayerID]:
            plex_LastOffsetUpdate[PlayerID] += 1

          if plex_LastOffsetUpdate[PlayerID] >= int(plex_ViewOffsetTimeout/plex_Interval) and state == "playing":
            state = "stopped"

          if plex_PreviousState[PlayerID] == state:
            StateChange = 0
          else:
            StateChange = 1
            plex_PreviousState[PlayerID]=state

          plex_PreviousTitle[PlayerID] = audiotitle
          PlayString = state.capitalize() + " Audio: " + parenttitle + " - " + audiotitle + PlayProgress
          PlayString = urllib.quote(translate(PlayString).encode('utf-8'))
          #uploading log message to domoticz
          if StateChange == 1:
            url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=addlogmessage&message=" + PlayString
            urllib2.urlopen(url , timeout = 5)
          
          statusValue = 0
          if state == "playing":
            statusValue = plex_Audio_Playing
          elif state == "paused":
            statusValue = plex_Audio_Paused
          elif state == "stopped":
            statusValue = plex_Audio_Stopped
          elif state =="buffering":
            statusValue = plex_Audio_Buffering

          #uploading values to domoticz
          url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=" + PlayString
          urllib2.urlopen(url , timeout = 5)
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[PlayerID] + "&vtype=integer&vvalue=" + str(statusValue))
          url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
          urllib2.urlopen(url,timeout = 5)
          
          if plex_LastOffset[PlayerID] != viewOffset:
            if plex_AutoClearPlayLog:
              url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=clearlightlog&idx=" + dom_PlexPlayInfo_ID[PlayerID]
              urllib2.urlopen(url , timeout = 5)
          plex_LastOffset[PlayerID] = viewOffset
          ProcessedIDs.append(PlayerID)
      
        except Exception,e:
          print 'IDLE'
          print e
          print traceback.print_exc()
          #uploading values to domoticz
          
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=No%20Media%20Playing")
          urllib2.urlopen(url,timeout = 5)
          pass
    for photo in root.findall('Photo'):
      # Get Attributes for each player
      player = photo.find('Player').attrib['title']
      state = photo.find('Player').attrib['state']
      parenttitle = "Unknown"
      parenttitle = photo.get('parentTitle')
      phototitle = photo.get('title')
      PlayString = ""
      StateChange = 0
      PlayerID = dom_PlexPlayers.index(player) if player in dom_PlexPlayers else -1
      if PlayerID >= 0:  #only process players that are on the list
        plex_AlreadyIdle[PlayerID] = False
        try:
          if plex_PreviousState[PlayerID] == state:
            StateChange = 0
          else:
            StateChange = 1
            plex_PreviousState[PlayerID]=state
          plex_PreviousTitle[PlayerID] = phototitle
          PlayString = state.capitalize() + " Slideshow: " + parenttitle + " - " + phototitle
          PlayString = urllib.quote(translate(PlayString).encode('utf-8'))
          #uploading log message to domoticz
          if StateChange == 1:
            url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=addlogmessage&message=" + PlayString
            urllib2.urlopen(url , timeout = 5)
            #uploading values to domoticz
            url = "http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=" + PlayString
            urllib2.urlopen(url , timeout = 5)
            statusValue = 0
            if state == "playing":
              statusValue = plex_Audio_Playing
            elif state == "paused":
              statusValue = plex_Audio_Paused
            elif state == "stopped":
              statusValue = plex_Audio_Stopped
            url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[PlayerID] + "&vtype=integer&vvalue=" + str(statusValue))
            url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
            urllib2.urlopen(url,timeout = 5)

          ProcessedIDs.append(PlayerID)
      
        except Exception,e:
          print 'IDLE'

          #uploading values to domoticz
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[PlayerID] + "&nvalue=0&svalue=No%20Media%20Playing")
          urllib2.urlopen(url,timeout = 5)
          pass
    #set play status to IDLE
    for i in range(0, len(dom_PlexPlayers)):
      if i not in ProcessedIDs and plex_AlreadyIdle[i] == False:
        print 'IDLE'
        url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[i] + "&nvalue=0&svalue=No%20Media%20Playing")
        urllib2.urlopen(url,timeout = 5)
        url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[i] + "&vtype=integer&vvalue=0")
        url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
        urllib2.urlopen(url,timeout = 5)
        plex_AlreadyIdle[i] = True
    ErrorCount = 0 
  except Exception,e:
    print traceback.print_exc()
    ErrorCount+=1
    if ErrorCount == plex_MaxErrorCount:
      print 'PLEX OFFLINE'
      for i in range(0, len(dom_PlexPlayers)):
        if plex_AlreadyIdle[i] == False:
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + dom_PlexPlayInfo_ID[i] + "&nvalue=0&svalue=No%20Media%20Playing")
          urllib2.urlopen(url,timeout = 5)
          url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[i] + "&vtype=integer&vvalue=" + str(plex_ServerOffline))
          url = urllib.quote(url.encode('utf-8'), safe="%/:=&?~#+!$,;'@()*[]'")
          urllib2.urlopen(url,timeout = 5)
          plex_AlreadyIdle[i] = True
      pass
  time.sleep (plex_Interval)
  open(pidfile, 'w').close()
jimtrout87
Posts: 16
Joined: Tuesday 12 April 2016 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by jimtrout87 »

Thanks i was on the latest version, at least i think i was. I am restesting with the latest code. Hopefully it will solve me issues

Thanks again
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

I'm curious if the changes helped. have you run into the issues again?
jimtrout87
Posts: 16
Joined: Tuesday 12 April 2016 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by jimtrout87 »

hi,

I have been running the newest code since the 6th (6 days) and come across no issues so far. The dummy switch is clearing as it should and variables are being updated each time.

Thanks for your help.
Hesmink
Posts: 168
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

What is the Plex server is down?

Post by Hesmink »

Hi,

I just installed this code today.
Works fine (after I figured out that the plex client actually has to be the name of the client known to Plex), but I have one small issue.

My Plex server is on my main PC, and this pc is not always on.
This results in the status not being updated, and still shows a client playing something, that is no longer the case.
Should the tool test for connection failures to the Plex server, and report that as status?
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

It should, status variables should change to -1 when the server is offline.
But clearly it's not working as expected. I'll look into it.
Ivanhoe1
Posts: 20
Joined: Monday 19 December 2016 20:42
Target OS: Windows
Domoticz version:
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by Ivanhoe1 »

Installed code today but the variables doesnt change, only showing "0". The device should be ok, can se media playing and paused otherwise idle.
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Try use the script given in. it's a copy of the script now running on my system with user variables.
https://github.com/racquemis/DomoticzSc ... ython/plex
See if it helps.
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

Im running your script and my variables don't change. It shows the happening i.e. the movie name or the series.
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

If you run the script from a terminal window, do you get any errors?

Also try running the url that updates the user variable manually, does it work?

Code: Select all

"http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=updateuservariable&vname=" + dom_PlexPlayState_ID[PlayerID] + "&vtype=integer&vvalue=" + str(statusValue))
Fill in the blanks yourself.

Also what are your script settings?
Please try some things to diagnose the problem yourself, I can't look at all of your setups or know how you configured things.
Last edited by racquemis on Friday 27 January 2017 8:47, edited 1 time in total.
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

When ill run the script in putty, no errors and the Variables updates as it should.

Code: Select all

#general Script settings
plex_Interval                 = 4     # Poll Interval. The Plex Server updates the session status every 10 seconds. Leave at 5 to not mis any state change.
plex_ShowPlayProgress         = True 
plex_AutoClearPlayLog         = True  # Should be enabled when showing Play Progress
plex_AutoCreateUserVariables  = True  # Automatically create a user variable for each Client listed under dom_PlexPlayers
plex_ViewOffsetTimeout        = 20    # In seconds.
plex_MaxErrorCount            = 3     # number of consecutive errors until Plex is considered Offline
Im to bad whit these scripts, so what blanks? :?:
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

Okay, so the script runs fine executed from putty but not when run from a crontab, you have given the script 775 rights? (execute rights)
cattoo
Posts: 60
Joined: Sunday 20 September 2015 17:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Sweden
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by cattoo »

racquemis wrote:Okay, so the script runs fine executed from putty but not when run from a crontab, you have given the script 775 rights? (execute rights)
Ive given it 775 rights, I can see in "top" that the script is running, the IDX for flex is updating, but not the Variables.
Also, I had to strip the PID code (if it matters)
racquemis
Posts: 73
Joined: Monday 02 November 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Plex Status - Video, Audio, Photo, Play Progress

Post by racquemis »

You removed the Pid part, but have you changed the crontab to run at reboot only? If not a new instance of the script will be run every 10 minutes without closing the previous one.

Try adding back the Pid part and edit the crontab:

Code: Select all

 */10 * * * *  /home/pi/domoticz/scripts/python/plex.py > /home/pi/domoticz/scripts/python/plex.log 2>&1
This enabling logging to file, save the crontab, wait ten minutes, play something and check the file plex.log. Are there any errors?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest