├── .gitignore ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # homebridge-wakeonlan 2 | Wake on LAN plugin for homebridge: https://github.com/nfarina/homebridge 3 | 4 | # Installation 5 | 6 | 1. Install homebridge using: npm install -g homebridge 7 | 2. Install this plugin using: npm install -g homebridge-wakeonlan 8 | 3. Update your configuration file. See the sample below. 9 | 10 | # Configuration 11 | 12 | Configuration sample: 13 | 14 | ``` 15 | "accessories": [ 16 | { 17 | "accessory": "WakeOnLan", 18 | "name": "Desktop", 19 | "macAddress": "BC:5D:F4:C8:5A:5F" 20 | } 21 | ] 22 | 23 | ``` 24 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = init; 2 | 3 | var wol = require('wake_on_lan'); 4 | var Service = null; 5 | var Characteristic = null; 6 | 7 | 8 | function init(homebridge) { 9 | Service = homebridge.hap.Service; 10 | Characteristic = homebridge.hap.Characteristic; 11 | homebridge.registerAccessory('homebridge-wakeonlan', 'WakeOnLan', WakeOnLan); 12 | } 13 | 14 | function WakeOnLan(log, config) { 15 | this.log = log; 16 | this.macAddress = config.macAddress; 17 | this.name = config.name; 18 | 19 | if (!this.macAddress) throw new Error('MacAddress property must be defined'); 20 | } 21 | 22 | WakeOnLan.prototype = { 23 | 24 | setPowerState: function(powerOn, callback) { 25 | var log = this.log; 26 | 27 | log("sending magic packet..."); 28 | wol.wake(this.macAddress, function(error) { 29 | if (error) { 30 | log('packet not sent'); 31 | } else { 32 | log('packet sent successfully'); 33 | } 34 | callback(error); 35 | }); 36 | 37 | }, 38 | 39 | identify: function(callback) { 40 | this.log("Identify requested!"); 41 | callback(); // success 42 | }, 43 | 44 | getServices: function() { 45 | 46 | var informationService = new Service.AccessoryInformation(); 47 | 48 | informationService 49 | .setCharacteristic(Characteristic.Manufacturer, "WOL") 50 | .setCharacteristic(Characteristic.Model, "Wake On Lan") 51 | .setCharacteristic(Characteristic.SerialNumber, "1337"); 52 | 53 | var switchService = new Service.Switch(this.name); 54 | 55 | switchService.getCharacteristic(Characteristic.On) 56 | .on('get', function (callback) { 57 | callback(null, 0); 58 | }) 59 | .on('set', this.setPowerState.bind(this)); 60 | 61 | return [informationService, switchService]; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "homebridge-wakeonlan", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "keywords": [ 6 | "homebridge-plugin" 7 | ], 8 | "license": "ISC", 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/microadam/homebridge-wakeonlan.git" 12 | }, 13 | "engines": { 14 | "node": ">=0.12.0", 15 | "homebridge": ">=0.2.0" 16 | }, 17 | "dependencies": { 18 | "wake_on_lan": "0.0.4" 19 | } 20 | } 21 | --------------------------------------------------------------------------------