Plex activity monitor using WEBHOOKS, the easy way

Try this:
https://github.com/requests/requests/issues/4246

pip install -U pyopenssl

nope didnt seem to work still the ssl error bad handshake.

Forgive my ignorance, but I thought tautulli natively uses websockets to connect to Plex, so doesn’t this just add already existing functionality to tautulli?

Edit: sorry, think I misunderstood the first post! Looks like this is using tautulli, not native Plex webhooks

I wonder if there is a way to create a custom_component in home assistant so the plex webhooks could be used directly in home assistant (as currently the webhooks don’t work natively due to the multipart nature of the Plex webhooks)

I’m actually not using tautulli anymore but created a node.js-server that updates the server. It’s almost easier and works better/faster. I’ll update this first post with instructions to use node.js.
It’s not as easy no parse de multipart json with python, that’s why we’re struggling with creating a custom component.

Cool, will be very interested to see that - I am currently trying to learn to use node-red to achieve this…

Edited steps with more information…

1 Plex Webhook arrives in node-red via http in node…

Method: POST
Accept file uploads? Yes
URL: /plex

2 Parse the plex webhook using a function node…

Function: msg.payload = JSON.parse(msg.payload.payload);
return msg;

3 Run through a change node…

Change: msg.payload.event
Search for: media.play
Replace with: playing

4 Send through a template node to filter attributes ready for home assistant…

Set property: msg.payload
Format: mustache template
Template:
{
    "state": "{{payload.event}}",
    "attributes": {
        "Player":"{{payload.Player.title}}",
        "Content":"{{payload.Metadata.type}}",
        "Name":"{{payload.Metadata.title}}",
        "Title":"{{payload.Metadata.grandparentTitle}}"
    }
}

which outputs…

state: "paused"
  attributes:
    Player: "SHIELD"
    Content: "episode"
    Name: "The Siege of Lothal"
    Title: "Star Wars Rebels"

5 Send information to home assistant using hass post node…

Endpoint: <your_hass_ip>
Entity ID: sensor.plex_sensor

Cheers,
James

Just use the rest api to update the sensor at hass? :slight_smile:

Yeah this is the bit that has flummoxed me - do I need to have a pre-existing sensor in homeassistant (and if so what sort of sensor do I need to create in home assistant)?

edit: gosh it really was as simple as sending that to the rest api, and i have a new sensor in home assistant - awesome!

Cheers,
James

Exactly :slight_smile:

1 Like

The first post is updated with a guide for using node.js, I really encourage you to use that instead of Tautulli since it faster and more reliable.

This is pretty cool :grinning:. I created something very similar using a Flask webserver hosted on Heroku. It accepts the payload from Plex using Plex’s Webhooks feature. Depending on the Plex client that triggered the webhook I send certain event’s into HomeAssistant using HA’s web api. I have a few automations triggered off of those events, mostly dimming/brightening lights if I’m watching plex in my living room after the sun has gone down.

Do you expose your node server to the outside world? The reason I ask is because one major benefit of using Plex Webhooks over Tautulli, is that the Webhooks fire regardless of which Plex server you’re watching content on. Tautulli can only see your Plex activity on the Plex server that it’s monitoring. The consistency and speed that Plex Webhooks allow for is really nice. If your node server wasn’t accessible to the outside world and you were watching content off of a friend’s Plex server that server would try to POST to the URL in your Webhook settings and it would fail. Though I suppose it doesn’t matter if you only watch content on your own Plex server and that server is on your network.

Plex On!

I’m not exposing the node.js since I only use my PMS. By the way, I’m looking into using flask instead to be able to create a custom component or using appdaemon.

@RitteT, I’m a little confused, do I need to do step #1 and #2?

In Step #2 does it matter what extension I give the file?

And here’s the most important question… I’m using HASSIO so I don’t think I can install node.js. Is the node.js script run just once to create the plex sensor in HA?. Can I run it from my ubuntu laptop?

You mentioned that you’re not using Tuatulli, what are you using instead. Is the original post still accurate on the steps needed? Thank you so much. I really hope to get this working.

Sorry but I’m just confused and this is a process I’ve been wanting to do for a year plus but just haven’t found anything reliable and this looks promising.

Use 1 OR 2. 1 is preferable as it’s a faster, more stable way.

ty. I was able to get # 1 working and I can see the benefits. Can I ask anyone for a suggestion on where / how to run this script. I assume it needs to be running 24/7

I am running unraid. this is where plex runs and several dockers.
Home Assistant runs ona RPI3 using HASSIO.

my ideas…

  1. simple ubuntu server VM on unraid to run the script
  2. nerdpack tools for unraid, but it doesn’t have “express, request or multer” installed
  3. dockerhub image on the HASSIO. not sure if this is possible
  4. install nodejs on hassio,. again, not sure if this is possible

thoughts?

Don’t know if 3&4 is possible, I would go with one.

I’m thinking I will use the Tautilli script. The main reason is I already us it so integration should be simple. I do agree script #1 is the best but until I can integrate it with HASSIO, It’s just not worth it.

If you don’t mind I need some help getting this working. Tautulli is a docker running as a docker on unraid, been workign perfectly for a year plus. I created a file plex_webhook.py in my config directory. I also made that file executable by chmod +x. In the Tautulli logs I get an error…

Tautulli Notifiers :: Script error:
File “/config/plex_webhook.py”, line 30
if playerstate == ‘Playing’
^
SyntaxError: invalid syntax

Your variable “Plex_url” is a bit confusing, but I assume it’s my plex server IP. confusing because of the variable name but in ‘’ your example is IP_to_TAUTULLI/PLEX. FYI… in my scenario, plex and Tautulli use the same IP, just different ports.

Everything else is self-explanatory.

NOTE: HA uses SSL, Ley’s encrypt. Tautulli does not use SSL. So I added an “s” for the HA url and the “hassUrl” is my HA FQDN.

Any idea on the error?

Signed up to this forum purely to say thank you for the Tautulli integration, works like a charm. :+1:t2:

You’re welcome! The node-js version is way faster and more reliable, try it out. If you need any assistance, pm me.

Ive done this as well, I have a zwave switch currently that controls the lights in my theater room and im using a isy994izw pro so all the plex integration is done through the nodejs script and plex webhook direct to that controller then also able to see the status in home assistant using the isy integration. Seems to give me the best performance so far.

@RitteT I used your tautulli integration in past and now wants to go with the new method. Is there something specific to do if you are running HA in hass.io ?? as I guess you reed then to do the install part in the docker no ?

Thanks