Code Monkey home page Code Monkey logo

homebridge-plex's Introduction

Plex Plugin for Homebridge

npm npm

Use the active sessions on your Plex server as a sensor in Homebridge. Enable your cozy cinema light scene when Plex starts playing and go back to your normal lighting when playback stops.

Installation

You install the plugin the same way you installed Homebridge - as a global NPM module:

sudo npm install -g homebridge-plex

If you don't have a Homebridge installation yet, head over to the project documetation for more information.

Configuration

The plugin uses the following config values:

Variable Description
accessory Must be Plex
name Whatever you want the accessory to be named in Homekit
plex_token The X-Plex-Token used to access your Plex server API. See Finding an authentication token / X-Plex-Token
host The hostname / IP address of your Plex server. Defaults to localhost, can be omitted if Homebridge runs on the same server as your Plex.
port The port of your Plex server. Defaults to 32400
filter  An array of filter rules. See filtering sessions
polling_interval Interval in seconds in which the play state is checked. Default is 3, lower values are discuraged.
debug Set this to true to receive detailed debug information about active sessions and filtering. This is not recommended for permanent installations as it fills up your log files pretty quickly.

Typical config example:

{
  "accessories": [
    {
      "accessory": "Plex",
      "name": "Plex",
      "plex_token": "...",
      "filter": [
        {
            "user": "your-plex-username",
            "player": "your-favorite-player"
        }
      ]
    }
  ]
}

Filtering Sessions

Plex will show up in your Home app as an "Occupancy Sensor". You can use this sensor in any automation you like.

Let's assume you have a home cinema with an Apple TV and the Plex app installed. You want to switch to your cinema light scene when you start watching a movie, so that all the lights dim down. Now you probably also have a smartphone or a tablet from which you occasionally stream a movie. To avoid these devices or even other users triggering the light scene in your home cinema, you can configure your sensor ignore everything other than the Apple TV.

You can configure an array of objects (we'll call that object a "filter rule"), each containing either a user or a player key or both. If any of the filter rules match an active session on your Plex server, the sensor in your Homekit will trigger and keep being triggered until you pause or stop the playback. So you can attach a scene to the "occupancy detected" event as well as the "occupancy stopped being detected" event.

If you define a filter rule only containing a user value, any device of that user will trigger the sensor. If you only define a player (e.g. my-apple-tv), then any player with that name will trigger the sensor, regardless of the user (This makes sense if multiple users use the same Apple TV).

Finding your user and player name

Just start a movie on the device you want to trigger the sensor and head over to the Plex web app. Navigate to Status -> Dashoard -> Current playback. Toggle "show details" on the top right and find the player name here:

Now Playing in the Plex web app

The player is in the upper left corner (in this example it's "TVBox") and the name is next to your profile picture in the bottom (not depicted).

homebridge-plex's People

Contributors

mpbzh avatar nitaybz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

homebridge-plex's Issues

2 Plex playes

I have 2 Apple TV, and I want to add 2 HB-Plex.
My config:

    "accessories": [
        {
            "accessory": "Plex",
            "name": "Living Room Plex",
            "host": "192.168.1.3",
            "plex_token": "123qweasdzxc",
            "filter": [
                {
                    "user": "Alex",
                    "player": "Apple TV LR"
                }
            ]
        },
        {
            "accessory": "Plex",
            "name": "Bedroom Plex",
            "host": "192.168.1.3",
            "plex_token": "123qweasdzxc",
            "filter": [
                {
                    "user": "Alex",
                    "player": "Apple TV BR"
                }
            ]
        }
    ],

The problem is if I watching Plex in Living Room both of the sensor is enabled. And if I start watching the Plex in Bedroom, both of sensors in Apple HomeKin works. How can I fix it?

Crashes when playing music

Hi, this is working for me perfectly well when I back video however when i play music the plugin crashes Homebridge with the following error.

18:25:14] [Plex Audio Sensor] There is one active session:
Feb 14 18:25:14 raspberrypi homebridge[25473]: /opt/node/lib/node_modules/homebridge-plex/index.js:83
Feb 14 18:25:14 raspberrypi homebridge[25473]: data.Video.forEach(function (e)

Thank you for developing this however is it possible to enable this to work for music as well as video. And as a feature request is it possible to add that as a filter so that it is possible in HomeKit to have two triggers, one for music and one for video. In my situation I would want to trigger different scenes based upon the content that is playing.

Many Thanks

Occupancy only updates when in Home-App

Hi, after installing the plugin the automation is only triggered when I am in in homekit app or when updating favorites in control-center.

Thanks in advance

Multiple simultaneous streams resulting in "Plex is not playing"

Hi
Today, I notice that if I have multiple current streaming from my PMS, my sensor will always report "Plex is not playing". No matter which user and device is being used.
My filter looks like this:
"user": "Noben",
"player": "Apple TV - Vardagsrum"
My hope with filters was that this sensor would only respond to my user when I see through device "Apple TV - Vardagsrum". Is this a bug or have I misunderstood how the filters work?

This is the logfile from where I first is playing from "Apple TV - Vardagsrum" and the user Noben, and everything works fine. homebridge-plex is reporting Plex is playing.
As soon as I starting a new stream from "Nobens iPhone 7" and the user [email protected], homebridge-plex is first reporting "Plex is playing" @ [2/5/2018, 10:36:15 PM], and then "Plex is not playing" two rows later (also @ [2/5/2018, 10:36:15 PM])
As soon as I stop playing stream number two, homebridge-plex correctly reports Plex is playing.

[2/5/2018, 10:36:12 PM] [Plex is playing] Getting current state...
[2/5/2018, 10:36:12 PM] [Plex is playing] There is one active session:
[2/5/2018, 10:36:12 PM] [Plex is playing] Apple TV - Vardagsrum vs Apple TV - Vardagsrum
[2/5/2018, 10:36:12 PM] [Plex is playing] Noben vs Noben
[2/5/2018, 10:36:12 PM] [Plex is playing] → Noben [Apple TV - Vardagsrum]: playing
[2/5/2018, 10:36:12 PM] [Plex is playing] Plex is playing.
[2/5/2018, 10:36:15 PM] [Plex is playing] Getting current state...
[2/5/2018, 10:36:15 PM] [Plex is playing] There are 2 active sessions:
[2/5/2018, 10:36:15 PM] [Plex is playing] Apple TV - Vardagsrum vs Apple TV - Vardagsrum
[2/5/2018, 10:36:15 PM] [Plex is playing] Noben vs Noben
[2/5/2018, 10:36:15 PM] [Plex is playing] → Noben [Apple TV - Vardagsrum]: playing
[2/5/2018, 10:36:15 PM] [Plex is playing] Plex is playing.
[2/5/2018, 10:36:15 PM] [Plex is playing] Apple TV - Vardagsrum vs Nobens iPhone 7
[2/5/2018, 10:36:15 PM] [Plex is playing] Noben vs [email protected]
[2/5/2018, 10:36:15 PM] [Plex is playing] → [email protected] [Nobens iPhone 7]: playing (ignored)
[2/5/2018, 10:36:15 PM] [Plex is playing] Plex is not playing.
[2/5/2018, 10:36:18 PM] [Plex is playing] Getting current state...
[2/5/2018, 10:36:18 PM] [Plex is playing] There are 2 active sessions:
[2/5/2018, 10:36:18 PM] [Plex is playing] Apple TV - Vardagsrum vs Apple TV - Vardagsrum
[2/5/2018, 10:36:18 PM] [Plex is playing] Noben vs Noben
[2/5/2018, 10:36:18 PM] [Plex is playing] → Noben [Apple TV - Vardagsrum]: playing
[2/5/2018, 10:36:18 PM] [Plex is playing] Plex is playing.
[2/5/2018, 10:36:18 PM] [Plex is playing] Apple TV - Vardagsrum vs Nobens iPhone 7
[2/5/2018, 10:36:18 PM] [Plex is playing] Noben vs [email protected]
[2/5/2018, 10:36:18 PM] [Plex is playing] → [email protected] [Nobens iPhone 7]: playing (ignored)
[2/5/2018, 10:36:18 PM] [Plex is playing] Plex is not playing.
[2/5/2018, 10:36:21 PM] [Plex is playing] Getting current state...
[2/5/2018, 10:36:21 PM] [Plex is playing] There is one active session:
[2/5/2018, 10:36:21 PM] [Plex is playing] Apple TV - Vardagsrum vs Apple TV - Vardagsrum
[2/5/2018, 10:36:21 PM] [Plex is playing] Noben vs Noben
[2/5/2018, 10:36:21 PM] [Plex is playing] → Noben [Apple TV - Vardagsrum]: playing
[2/5/2018, 10:36:21 PM] [Plex is playing] Plex is playing.

check online status first

Is it possible to add a status check by pinging the server first?
At the moment the whole Homebridge gets nearly locked when the server is not online.

[Plex] Error getting state (status code 401): null

Hi there,
I'm trying to get this set up but I keep getting the error "[Plex] Error getting state (status code 401): null"

I have verified the token is correct and renewed it. I have also debugged the token and it is giving me the correct media container response. I have tried manually specifying the server IP (even though it is on the localhost) and I have also tried deleting my config.json and recreating it using nano and li in an attempt to prevent formatting issues, but the issue remains.

Please help!

type of sensor

Hello, is there a way to change what type of sensor is used in homekit?
So that you could be able to switch between a presence sensor or a movement sensor?

Error getting state

Hello,
Just installed the plugin (great idea BTW) im getting following error:

[PlexTV] Getting current state...
[PlexTV] Error getting state (status code 1): TypeError: The header content contains invalid characters

My configs are as follows:

{
   "accessory": "Plex",
   "name": "PlexTV",
   "host": "192.168.0.1",
   "plex_token": "XXXXXXXXXXXX (redacted)",
   "filter": [
       {
           "user": "XXXXXXXXXXX (redacted)",
           "player": "TV UE55KU6000"
       }
   ]
}

Any ideas on were im going wrong? Thanks

not responding

did everything, user name, media player and token
but its not responding at homekit

Unable to get plex to appear in homekit

I have the plugin installed and config.json configured. My logs show plex registering but the device never appears in homekit. any ideas? belows a snip of my json and logs

[2018-1-14 21:07:32] Registering platform 'homebridge-config-ui-x.config'
[2018-1-14 21:07:32] ---
[2018-1-14 21:07:32] Loaded plugin: homebridge-plex
[2018-1-14 21:07:32] Registering accessory 'homebridge-plex.Plex'
[2018-1-14 21:07:32] ---

    }
],
"accessory": "Plex",
"name": "PlexLivingRoom",
"host": "10.5.5.2",
"port": 32400,
"plex_token": "XXXXXXXXXXXX REDACTED",
"filter": [
    {
        "player": "Living Room"
    }
],

Getting 401 error

Hey there

I am getting a "Error getting state (status code 401): null" error. I have input a valid token, so not sure why this would be.

self.log("Error getting state (status code %s): %s", statusCode, err);

The server is not local so may be that's why.

Config looks like:

{
"accessory": "Plex",
"name": "Plex",
"plex_token": "xxxxxx",
"host": "XXX-XXX-XXX-XXX.929ed44XXXXXXXXX10de7d1017f33.plex.direct"
}

Polling interval output filling up logs?

I apologize if this is premature, and fully acknowledge that I haven't given my system enough time to prove anything to me one way or the other, but I updated to the latest commit this morning (b542c39) and noticed that with each poll there is a set of lines that get written to the homebridge.log file (which I believe is a capture of stdout?).

For my system, which is a homebridge docker container, the status is being written every 3 seconds (I know I can change this default) to /var/log/homebridge.log. I've been watching the file size grow at ~100KB/hr. Doing some rough (and probably poor) math, I'll be looking at a 15MB log file for each full week the plugin runs. Not the end of the world, but you can see how it'll add up quickly.

I'll keep checking on it over the next day or two to see if these logs rollover, and I know I could setup a cron job or something to periodically clear things out, but I wanted to bring it up for discussion. Thanks!

Port hang up

Hi,

I tried installing it, and after checking the json file and starting the homebridge program, I get this error :[Plex] Error getting state (status code 1): Error: socket hang up

What can I do to fix it ?

TypeError: Cannot read...'forEach'...

I'm getting an error previously closed/discussed:

\homebridge-plex\index.js:83
data.Video.forEach(function (e) {
^

TypeError: Cannot read property 'forEach' of undefined�

I'm not sure where it's going wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.