Git Product home page Git Product logo

homebridge-plex-sensors's Introduction

Homebridge Sensors for Plex

This plugin for Homebridge adds sensor(s) to HomeKit that are triggered by Plex playbacks. You can use these sensors to trigger HomeKit scenes when Plex starts and stops playback.

Example image of a Homebridge Sensor for Plex

Automatically dim the lights when you start watching TV, or turn them off completely for a movie. With advanced HomeKit automations you can even trigger different scenes depending on the time of day.

Plex Sensors uses Plex's webhooks feature to get notified by your Plex server immediately when playback starts and stops, without needing to constantly poll your server.

Note: Because webhooks require Plex Pass for the Plex Media Server account, this plugin also effectively requires Plex Pass.

Installation

You can install this homebridge plugin with npm:

sudo npm install -g homebridge-plex-sensors

Go to the Homebridge page to read more about installing and configuring Homebridge.

Setting up the Webhook

For this plugin to receive playback events, you need to add a webhook to your Plex account. You can do this by visiting:

https://app.plex.tv/desktop#!/account/webhooks

On that page, click ADD WEBHOOK and then enter the IP of your homebridge server with the port used by this plugin (by default 22987 but this can be changed in the config file). So for example enter http://192.168.1.100:22987/ if you kept the default port, and your IP address is 192.168.1.100.

Note: to work with Plex servers outside your local network you'll need to expose the address used to the outside world via port forwarding etc.

Configuration

Plex Sensors supports various configuration options to suit your needs, and runs as a homebridge platform so it can add multiple sensors for different types of playback.

Your config for the platform should include a sensors object that can contain any number of sensors with different configurations (each sensor can filter events, eg. only movie events on the living room player). Those sensor objects can include the following variables:

Variable Description
name This will be the name of this sensor, it must be included and unique.
types (Optional) This is an array of types for which playback can trigger the sensor. (Valid types include movie, episode, track, photo)
players (Optional) This is an array of player names or UUIDs for players that will trigger the sensor. (To find out your player name you can check the Now Playing section of Plex Web while that player is playing, or enable the logSeenPlayersAndUsers setting described below which will also log UUID values as an alternative to names)
users (Optional) This is an array of user names for users that will trigger the sensor. (To find out your user name you can check the Now Playing section of Plex Web while that user is playing)
genres (Optional) This is an array of genre strings. If set, movie playbacks will only trigger the sensor if the movie's genre matches one or more of the genres in this array.
ignorePauseResume (Optional - default: false) If set to true the sensor will remain "triggered" while playback is paused. By default paused players will untrigger the sensor.
customFilters (Optional / Advanced) Custom filters allow you to filter for specific properties on the JSON events that the above use cases don't cover. For example you could make a sensor only triggered by playing a specific TV Show or movie. See Plex's article on Webhooks for more details of what is passed in webhook events.
delayOff (Optional - default: 0) Setting this to a value above 0 will delay the occupancy sensor being untriggered when playback is stopped. This timeout is measured in milliseconds.

Additionally, you can set the following settings globally, outside of the sensors object:

Variable Description
logSeenPlayersAndUsers (Optional - default: false) Setting this to true will log every player device name and username that the plugin sees starting a playback from the webhook, potentially useful for figuring out device names.

debug | (Optional - default: false) Setting this to true will log every webhook and how it is handled by the plugin's logic. You should probably leave this false, but you might find it useful for looking at the entire contents of a webhook payload.

Example Configs

Example config with one sensor triggered by any Plex playback by your account or from your server:

{
"platforms": [
  {
    "platform": "homebridge-plex-sensors.Plex",
    "sensors": [
      {
        "name": "Plex Playing"
      }
    ]
  }
]
}

Example config with a sensor triggered by TV show playbacks, and a sensor triggered by movie playbacks (both filtered to a specific user and player):

{
"platforms": [
  {
    "platform": "homebridge-plex-sensors.Plex",
    "sensors": [
      {
        "name": "Movie Playing",
        "types": ["movie"],
        "players": ["Living Room"],
        "users": ["MyUserName"]
      },
      {
        "name": "TV Playing",
        "types": ["episode"],
        "players": ["Living Room"],
        "users": ["MyUserName"]
      }
    ]
  }
]
}

Example config with a horror movie genre-specific sensor:

{
"platforms": [
  {
    "platform": "homebridge-plex-sensors.Plex",
    "sensors": [
      {
        "name": "Horror Movie",
        "types": ["movie"],
        "genres": ["Horror"]
      }
    ]
  }
]
}

Example config with a sensor triggered only by playing the TV show Breaking Bad (also shows a custom port number being set for the webhook server):

{
"platforms": [
  {
    "platform": "homebridge-plex-sensors.Plex",
    "port": "22988",
    "sensors": [
      {
        "name": "Breaking Bad is on",
        "types": ["episode"],
        "customFilters":
        {
          "Metadata.grandparentTitle": "Breaking Bad"
        }
      }
    ]
  }
]
}

Example config with the logSeenPlayersAndUsers setting to true for helping you figure out device names:

{
"platforms": [
  {
    "platform": "homebridge-plex-sensors.Plex",
    "logSeenPlayersAndUsers": true,
    "sensors": [
      {
        "name": "Plex Playing",
      }
    ]
  }
]
}

homebridge-plex-sensors's People

Contributors

alexjsp 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  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  avatar  avatar

homebridge-plex-sensors's Issues

Multiple sensors triggered

I have the following issue: I have created a generic sensor that triggers when a TV episode is being played and also some sensors for specific TV series. When I now start one of those specific TV series, both sensors are triggered, the specific one AND the generic one.

Is there a way, or can you add an optional flag or something, that ensures that when a more specific sensor is triggered the more generic sensor is not triggered too? The problem with the way it is now is that it will make my philips hue lights change twice quickly after each other.

(I know that part of this issue can also be attributed to HomeKit as there you can’t define a hierarchy an sensors either, but having it fixed in this homebridge plugin is probably easier than getting Apple to introduce a fix).

BTW Thanks for this fantastic plugin.

sensor triggering for all players.

Hi,
I have setup a very basic sensor which should trigger when a single player on my ATV is used. I've tried using the player name and also the UUID, but every player in the house seems to trigger it.
{
"platform": "homebridge-plex-sensors.Plex",
"logSeenPlayersAndUsers": true,
"delayOff": 0,
"sensors": [
{
"name": "Plex Playing",
"player": "Living Room"
}
]

I've also tried removing the player definition and seeing if I could trigger it based on plex user, but again it seems to trigger on irrespective of which user tag is used. Logging from homebridge is showing the correct tags coming in.

i'm at a loss as to how to get the sensor to trigger selectively and any help would be much appreciated.

Thanks

Trigger event on media pause and resume?

Is there a way to trigger a sensor based on media pausing and resuming? I'm trying to use this to replace some python scripts I was using to accomplish the same thing, but it doesn't seem to work.

This is my config right now:

"platforms": [
	{
		"platform": "homebridge-plex-sensors.Plex",
		"sensors": [
		{
			"name": "Media Playing",
			"types": ["movie","episode"],
			"players": ["Luca's TV"],
			"customFilters":
			{
				"event": "media.play"
			}
		},
		{
			"name": "Media Paused",
			"types": ["movie","episode"],
			"players": ["Luca's TV"],
			"customFilters":
			{
				"event": "media.pause"
			}
		},
		{
			"name": "Media Resumed",
			"types": ["movie","episode"],
			"players": ["Luca's TV"],
			"customFilters":
			{
				"event": "media.resume"
			}
		},
		{
			"name": "Media Stopped",
			"types": ["movie","episode"],
			"players": ["Luca's TV"],
			"customFilters":
			{
				"event": "media.stop"
			}
		}
		]
	}	
	]

I understand now that the media stop sensor isn't quite needed, as I can just trigger a scene on the "media playing" sensor going off. However, the pause sensor doesn't seem to trigger when I pause media.

Plex sponsor for a friends sensor

I actually mostly use a friends server and wanted to ask if its possible to use those sensors without installing something on his Server?

Webhook Delay

Is it normal to see a 3-5 second delay on the webhook response? I was using another npm package that polls the server but then found this which makes a lot more sense (webhook vs polling). Before I try something else, I was just curious if the webhook delay was common since this is my first time using them for anything. I am running Homebridge on a different machine than Plex. Could that be the issue?

Sensor based on library

Hi,

I would like to know if it is possible to create a plex sensor based on which library the movie is being played from.

I cannot see an example of this case figure.

Thanks

Sensor does not show in Home app

Hello I have tried installing this app a few times as well as changing up the config file with different sensor types however it will not show in home app.

Loaded plugin: homebridge-plex-sensors
[10/26/2018, 10:30:56 PM] Registering platform 'homebridge-plex-sensors.Plex'
[10/26/2018, 10:30:56 PM] ---
[10/26/2018, 10:30:58 PM] Loaded plugin: homebridge-smartthings
[10/26/2018, 10:30:58 PM] Registering platform 'homebridge-smartthings.SmartThings'
[10/26/2018, 10:30:58 PM] ---
[10/26/2018, 10:30:58 PM] Loading 3 platforms...
[10/26/2018, 10:30:58 PM] [SmartThings] Initializing SmartThings platform...
[10/26/2018, 10:30:58 PM] [SmartThings] Fetching Smart Things devices.
[10/26/2018, 10:30:58 PM] [homebridge-plex-sensors.Plex] Initializing homebridge-plex-sensors.Plex platform...
[10/26/2018, 10:30:58 PM] [IR Blaster] Initializing BroadlinkRM platform...
[10/26/2018, 10:30:58 PM] [IR Blaster] [INFO] Automatically discovering Broadlink RM devices.
[10/26/2018, 10:30:58 PM] [IR Blaster] TV On/Off Accessory Ready
[10/26/2018, 10:30:58 PM] [IR Blaster] Initializing platform accessory 'Learn'...
[10/26/2018, 10:30:58 PM] [IR Blaster] Initializing platform accessory 'Scan Frequency'...
[10/26/2018, 10:30:58 PM] [IR Blaster] Initializing platform accessory 'TV On/Off'...
[10/26/2018, 10:30:58 PM] Loading 1 accessories...
[10/26/2018, 10:30:58 PM] [Screen Lights] Initializing MagicHome accessory...
[10/26/2018, 10:30:58 PM] [homebridge-plex-sensors.Plex] Configuring 'Movie Playing' sensor.
[10/26/2018, 10:30:58 PM] [homebridge-plex-sensors.Plex] Adding 'Theater Playing' sensor.
[10/26/2018, 10:30:58 PM] [homebridge-plex-sensors.Plex] Removing old 'Movie Playing' sensor no longer in config.
[10/26/2018, 10:30:58 PM] [homebridge-plex-sensors.Plex] Homebridge Plex Sensors listening for webhooks on: http://:22987

Here is the config

{
"platform": "homebridge-plex-sensors.Plex",
"sensors": [{
"name": "Theater Playing"
}]
},

	{
		"platform": "BroadlinkRM",

More them one sensor??

Hi, can I create more than 1 sensor. Each player has its own sensor so that I can perform different actions per room and per player?

Genre and custom filter not triggering

Hi Alex,

I'm not sure if it's an update to Plex, but I'm trying to add a sensor based on either a genre or custom filter. Both don't work, when trying any combination. Using the basic player value works fine and triggers - use case is to trigger on pre-roll, but the more advanced filters don't work. The advanced triggers (genre and custom filters) used to work, as I'd asked you originally about adding genres as a filter and used it for a while, so I think this is a recent issue.

Charlie

Accessory showing as Occupancy Sensor

Hi,

After installing the plugin, my Movie Playing sensor displays in HomeKit as an Occupancy sensor. Is this correct? Should he play/pause/etc. actions in Plex be triggering occupied/unoccupied?

Any help would be great.

Thanks for making this great plugin!

How to use the delay?

When fast forwarding and rewinding the “pause” is triggered. I have the state of plex turn on/off the lights. So when fast forwarding or rewinding flicks the lights on and off. I noticed there’s a delay option but not sure how to use it. Can you show a rough config with delay included?

I want to keep the trigger when I actually pause plex because that’s useful. So I don’t want to disable that. I’m wondering if adding a slight delay will help when ffw and rewinding.

Thank you!

About remote connections

Hi ! Great great Plugin ! Thanks a lot for your efforts !
I have a little problem... If i run the plex movie/tvShow from home, any problem, all works like a charm. The problkem is if i m seeing a show from another location... the webhook acts, and my homekit setup is ok, i ve checked the option " When I m at home", but does not matter, the Webhook acts and my wife does nt like it soo much :-)

Any ideas please ?
ios

plex sensor clears trigger even when ignore set to true

here is the relevant snippet of my 'config.json'

        {
            "platform": "homebridge-plex-sensors.Plex",
            "logSeenPlayersAndUsers": true,
            "ignorePauseResume": true,
            "sensors": [
                {
                    "name": "Media Playing"
                }
            ]
        },

when using the web client or PMP, the trigger clears even though ignorePauseResume is set to true and a video is paused

is anyone else experiencing this?

Two or more players?

I have two TV players (and of course IOS etc). I do not get notifications or updates for the second player I created in the config. I notice that there was a similar issue in one of the other plex plug-ins and wondered whether this could be the same?
"platform": "homebridge-plex-sensors.Plex",
"sensors": [
{
"name": "Plex Playing Lounge",
"players": [
"TV UE65H6400"
]
},
{
"name": "Plex Playing Bedroom",
"players": [
"Plex for LG"
]
}
]

Quick update. I added a new player, Firefox, which is on my Mac and that one works. It is just the LG TV, which I can get round I think by using the LG TV interface!

Plex Smart Lights Sensor issue

I have setup homebridge and plex to trigger my 1 smart light in my bedroom to turn on and off when playing any media on my server. This works perfectly fine. But I want to set it to only happen when using my Google TV Stick and not my other devices such as my phone or other tvs. I am quite new to all this and have had some hel on this reddit thread and has helped me a biut but still not working.

https://www.reddit.com/r/homebridge/comments/wp2vzz/help_with_plex_smart_light_control/

My current Homebridge Config looks like this:

{
    "bridge": {
        "name": "Homebridge D849",
        "username": "0E:C1:47:69:D8:49",
        "port": 51195,
        "pin": "435-38-673",
        "advertiser": "avahi"
    },
    "accessories": [],
    "platforms": [
        {
            "platform": "homebridge-plex-sensors.Plex",
            "logSeenPlayersAndUsers": true,
            "sensors": [
                {
                    "name": "Movie Playing",
                    "types": [
                        "movie"
                    ],
                    "players": [
                        "Chromecast Google TV"
                    ],
                    "users": [
                        "stephenunderwood"
                    ]
                },
                {
                    "name": "TV Playing",
                    "types": [
                        "episode"
                    ],
                    "players": [
                        "Chromecast Google TV"
                    ],
                    "users": [
                        "stephenunderwood"
                    ]
                }
            ]
        },
        {
            "name": "Plex Webhooks Platform",
            "sensors": [
                {
                    "name": "PlexPi Light Connection"
                }
            ],
            "server": {
                "port": 32401,
                "address": "192.168.0.102"
            },
            "platform": "PlexWebhooks"
        },
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        }
    ]
}

error connectie

Hi there, i het this error,

[5/1/2020, 23:48:24] [Plex] Error getting state (status code 1): Error: connect ECONNREFUSED 127.0.0.1:32400
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 32400
}
[5/1/2020, 23:48:27] [Plex] Error getting state (status code 1): Error: connect ECONNREFUSED 127.0.0.1:32400
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 32400

Can you tel me what to do ?

Plugin crashes homebridge

Homebridge crashes on play.


C:\Users\pax07\node_modules\homebridge-plex-sensors\index.js:95
    var event = JSON.parse(json);
                     ^
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Plex.httpHandler (C:\Users\pax07\node_modules\homebridge-plex-sensors\index.js:95:22)
    at IncomingMessage.request.on.on (C:\Users\pax07\node_modules\homebridge-plex-sensors\index.js:39:16)
    at IncomingMessage.emit (events.js:127:13)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:114:19)

C:\Users\pax07>

Plugin keeps adding old sensors

I've been playing around with sensors and looks like plugin is still adding every sensor I've ever added,
ones that no longer exist in config.

[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Configuring 'Plex Play' sensor.
[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Configuring 'Plex' sensor.
[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Configuring 'Plex Movie' sensor.
[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Configuring 'Plex Series' sensor.
[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Configuring 'Plex TEST' sensor.
[2018-4-8 17:33:18] [homebridge-plex-sensors.Plex] Homebridge Plex Sensors listening for webhooks on: http://<homebridge ip>:22987
		{
			"platform": "homebridge-plex-sensors.Plex",
			"sensors": 
				[
				{
					"name": "Plex",
					"types": ["movie", "episode"],
					"players": ["K2SO"]
				}			
				]
		},

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.