├── .gitignore ├── package.json ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plex-notifications", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": {}, 6 | "dependencies": { 7 | "express": "^4.14.0", 8 | "multer": "^1.3.0", 9 | "request": "^2.79.0" 10 | }, 11 | "devDependencies": {} 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | In order to run this app: 2 | 3 | - Install [node.js](https://nodejs.org/en/). 4 | - Clone the repository. 5 | - Install dependencies using `npm install`. 6 | - [Get a bearer token](https://home-assistant.io/components/wink/) for your Wink account. 7 | - Find the lightbulb ID by making the following request and looking for `light_bulb_id`: 8 | 9 | ``` 10 | http -b https://winkapi.quirky.com/users/me/wink_devices "Authorization:Bearer your-bearer-token" 11 | ``` 12 | 13 | - Find the player identifier for the player you want to connect it with. 14 | - Run like this: 15 | 16 | ``` 17 | BEARER=bearer-token BULB=bulb-id PLAYER=player-identifier node index.js 18 | ``` 19 | 20 | - Add the webhook to https://app.plex.tv/web/app#!/account/webhooks 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | , request = require('request') 3 | , multer = require('multer'); 4 | 5 | var app = express(); 6 | var upload = multer({ dest: '/tmp/' }); 7 | 8 | app.post('/', upload.single('thumb'), function (req, res, next) { 9 | var payload = JSON.parse(req.body.payload); 10 | console.log('Got webhook for', payload.event); 11 | 12 | // Apple TV. 13 | if (payload.Player.uuid == process.env.PLAYER && payload.Metadata.type != 'track') { 14 | var options = { 15 | method: 'PUT', 16 | json: true, 17 | url: 'https://winkapi.quirky.com/light_bulbs/' + process.env.BULB, 18 | headers: { 'Authorization': 'Bearer ' + process.env.BEARER } 19 | }; 20 | 21 | if (payload.event == 'media.play' || payload.event == 'media.resume') { 22 | // Turn light off. 23 | console.log('Turning light off.'); 24 | options.body = { desired_state: { powered: false } }; 25 | request(options); 26 | } else if (payload.event == 'media.pause' || payload.event == 'media.stop') { 27 | // Turn light on. 28 | console.log('Turning light on.'); 29 | options.body = { desired_state: { powered: true, brightness: 1.0 } }; 30 | request(options); 31 | } 32 | } 33 | 34 | res.sendStatus(200); 35 | }); 36 | 37 | app.listen(12000); 38 | --------------------------------------------------------------------------------