[OBSOLETE] Plex Home Theatre Manager SmartApp

Hey guys,

im very new to smart things and have multiple apps setup. But for some reason this wont add to myapps. I followed the instructions, but im probably doing something stupid. Any help would be great.

Hi Andrew, what error are you getting?

Also if the issue is happening when pasting the code from GitHub then I would suggest changing to raw view and then selecting all, sometimes copying in the standard view selects other stuff

I just implemented this yesterday [from the OP Github DTH and SA] and can confirm that I am getting status from multiple clients, and that it is not accepting control commands with any of them. I have verified that I can open up the Plex Remote from iOS or WebUI and control those same clients, and that they show player in the provides from the devices.xml. I really want to get rid of the polling, so I will look at Plex2Smartthings for that, but from what I understand only this system allows sending control back to it which I would like to get working (If the door is opened, Pause playback for example). Below is an example of a typical client in my list where I see status changes, but it does not respond to commands.

<Device name="Apple TV" publicAddress="xxx.xxx.xxx.xxx" product="Plex for Apple TV" productVersion="1.5" platform="tvOS" platformVersion="10.1" device="Apple TV" model="5,3" vendor="" provides="client,player,pubsub-player" clientIdentifier="ID Hash Here" version="1.5" id="79758600" token="ID Hash Here" createdAt="1478218863" lastSeenAt="1481847818" screenResolution="1920x1080" screenDensity="1">
<Connection uri="http://10.10.10.110:32500"/>
</Device>

Hi I think this has been broken for a whileā€¦ I suspect Plex changes the API

Howeverā€¦ Iā€™ve been playing for the last hour, and I think the code currently connects to the server to control the deviceā€¦ but the documentation I have been looking at appears to refer to direct interaction with the deviceā€¦

Can you try the code belowā€¦ Iā€™ve bodged in the code so only a stop command will workā€¦ so you will need to manually play, then use ST to send the stop commandā€¦ if that works then I believe I can re-code the lot so control works againā€¦

https://dl.dropboxusercontent.com/u/27382557/plexmanagercontrol.txt

Let me know how you get onā€¦ also note the attached code is heavily modified from the version on git hubā€¦ but does include a switch so you can turn off polling should you wish to poll via Plex2Smartthings/PlexPlus

@ph4r

Iā€™ve just made further amendments to the code linked aboveā€¦ should hopefully all work , but let me know how you get on!

Edit: you will need to uninstall and re-installā€¦

I canā€™t test this yet, but it looks like a minor typo on the previous (wrong line commented out). I look forward to testing this late tonight or early tomorrow. I was reading into it some as well, and I think there may be a way to pass it through the server still with including the X-Plex-Client-Identifier header for the target Player and a commandID. Hopefully you will merge the client identification information into your SA so that I do not need to manually enter it all. I also need to test that at the same time.

No there were quite a few things ā€œwrongā€, it seems some devices donā€™t support comms from the server for some reasonā€¦ but give it a go and let me know if it works, no idea if Apple TV allows http control or notā€¦ if you end up with a * next to the device in the list it wonā€™t work, but not to say all without it will workā€¦

When you mean my app I assume you mean PlexPlus? If so the Plex token isnā€™t used there itā€™s used in the exe so you will need to obtain itā€¦

Edit: Iā€™ve re-read a few times and donā€™t think thatā€™s what you mean? If you could explain?

So your latest code doesnā€™t work for me and Iā€™ve been playing around with my Apple TV Client and a web browser and I have been able to pass commands that are working to control the playback states passing messages to the server.

https://server-ip:32400/player/playback/pause?X-Plex-Token=hash_here&X-Plex-Target-Client-Identifier=hash_here

I see that all the pieces are available already, it should just be a matter of putting the deviceID as an additional header in your new executeClientRequest function, but I am having a hard time figuring out how the object members work in this system. Also, my previous message was about your function named previous where you had the executeRequest active instead of the executeClientRequest.

1 Like

I was having some weird issues so I started over from the OP Code, and I got the commands working now!!

See 2 posts down for github link of latest instance.

1 Like

Ahh I see what you mean now! Good work on getting it working! Iā€™ll take a proper look later in the week, Iā€™m thinking of making a self contained DTH so commands are sent direct from the device, but not sure if a DTH can can do GET requests directly, this would provide control using PlexPlus also and no need for a separate app just for the control methodā€¦

I think there is an issue with your solution though (although nothing technically wrong with your code) as I noticed while playing yesterday, the Roku stick seems to present a different ID when being added to when reporting play state! No idea why! Not sure if itā€™s a roku issue or plex but the Plex API doesnā€™t seem very consistent in its implementation!

I added [Jakesā€™] features (sans client direct port communications) and put it here:

Ph4rā€™s Fork of PlexManager SmartApp

2 Likes

Good work saves me trying to work it all out :slight_smile:

Will give it a try laterā€¦

@ph4r

Can you un-comment the below line in your code, this is needed to identify state in some instances:

//def address = getPHTAddress(pht.deviceNetworkId);

Other than that looks good, to late to test properly, I can see in some instances that it doesnā€™t work to control some devices, but itā€™s highly possible that these do not support controlā€¦ Iā€™ll test some of the same devices using direct control and see if that worksā€¦

Also have you created a new DTH? I see you have added in the other control commands?

I have them on an in-progress DTH that I put in a new branch on my GitHub. I might have a typo somewhere, as they do not seem to work consistently, and the response is a bit slower than using the native plex app control for example. Iā€™ve been doing my testing mostly on the aTV4, but the unit I really want to use this with is a PC in another room and that one is behaving very inconsistently. I may need to go back to trying your client direct commands, but they did not work at all with the aTV4 which is why I implemented the server commands. What is the reference that you used for sending client commands, as I donā€™t see it that way in the official API Docs I was looking at?

1 Like

So your code seems to work with Plex Media Center (No longer supported by Plex) I thinkā€¦ but doesnā€™t work with the Windows 10 App that replaced itā€¦

But I donā€™t think works with Roku, which mine did, but I donā€™t think there is a single answer, some things work with one method and some with the other methodā€¦ I think generally the API is a bit of a mess, with no consistencyā€¦ including Plex owned apps not reporting full capability!!

Iā€™ve just spotted I uploaded the wrong version of my code as still has some values I was using to testā€¦ Play/pause/stop are triggering the wrong actionsā€¦ but also the playpause toggle in the original version or mine doesnā€™t appear to toggle, so need to add some code fort this too, based on current device state I would assumeā€¦

I was referencing the below documentationā€¦

Looks like a fun ā€œfree timeā€ activity for later this week or next. Iā€™ll add this a setting to the DTH, and dot append it after the command to be parsed by the SA, as each device may need different settings. Since the official Plex API suggests that Server Comms is the directive, I suggest that if no value is set, Server Commands should be assumed. I wish I could send the commands from the DTH directly instead of bouncing them to the SA to handle,

input name: "CommandTarget", type: "enum", title: "Command Target", options: ["Server", "Client"], description: "Select Command Target", required: true

I think the passing will need to be like this:

sendEvent(name: "switch", value: device.deviceNetworkId + "." + command + "." + $CommandTarget);

Sounds good mate, let me know if you make a start on this, otherwise Iā€™ll give it a go over Christmasā€¦

Whatā€™s stopping you doing it in the DTH though? Are sending get requests restricted?

Love the app so far! Thanks for making this. Couple of questions I have:

  1. Iā€™ve noticed a delay in status for playback. Seems to be about 10 seconds after I pause the movie that it changes status. Is this by design or is there to make this more instant?

  2. Regarding CoRE integration. I see that in the log of Plex HT Manager it mentions ā€œplayback typeā€ Do you know of a way I can integrate that into CoRE so that it only dims light if ā€œplayback typeā€ is movie?

Thanks again!

EDIT: I see question 1 was answered a couple of times.

The event you would need to pull is playbackType, but I donā€™t know if that is something CoRE can pick up on, probably worth asking in the CoRE queries threadā€¦

The alternative is to use PlexPlusā€¦ you can add the plex HT device in here and it already has the logic to be able to determine media type and adjust lights accordinglyā€¦ you donā€™t have to use the exe in this case you can just add the device you created in this app in to Plex Plusā€¦ however if you do use the exe then the latency can be much lower between state changes as the polling takes place external to smart thingsā€¦

Hi,

I am curious why the app is picking up all of my devices (phones, tablets) but not the Plex server on my pc.

If i choose Show all devices regardless of Capability it shows my PC. Im am reading through the thread but just curious on the logic.

Also, I am getting an unknown error when trying to save Plex Manager. It happens after i save it (if confirms then throws up an error).