├── .gitignore ├── package.json ├── README.md ├── LICENSE └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "homebridge-rcswitch", 3 | "version": "1.1.0", 4 | "license": "MIT", 5 | "keywords": [ 6 | "rcswitch", 7 | "raspberry", 8 | "433", 9 | "mhz", 10 | "gpio", 11 | "wiringPi", 12 | "pi", 13 | "siri", 14 | "homebridge", 15 | "homebridge-plugin" 16 | ], 17 | "engines": { 18 | "node": ">=0.12.0", 19 | "homebridge": ">=0.2.0" 20 | }, 21 | "dependencies": { 22 | "rcswitch": "^0.2.3" 23 | }, 24 | "devDependencies": { 25 | "xo": "^0.12.0" 26 | }, 27 | "xo": { 28 | "esnext": false, 29 | "envs" :[ 30 | "node" 31 | ] 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # homebridge-rcswitch 2 | 3 | Add support for rc switches using [rcswitch](https://github.com/marvinroger/node-rcswitch) 4 | 5 | # Installation 6 | 7 | 1. Install [WiringPi](https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/) 8 | 2. Install homebridge using: `npm install -g homebridge` 9 | 3. Install this plugin using: `npm install -g homebridge-rcswitch` 10 | 4. Update your configuration file. 11 | 12 | # Configuration 13 | 14 | You can add as many switches as you like. You will need to pass the `name`, `systemcode` and `unitcode`. 15 | This plugin assumes that you connect the 433Mhz transmitter to GPIO0, this can be changed via the `pin` propertie. 16 | 17 | ``` 18 | "accessories": [ 19 | { 20 | "accessory": "RcSwitch", 21 | "name": "Switch One", 22 | "systemcode": "11101", 23 | "unitcode": 1, 24 | "pin": 0 25 | } 26 | ] 27 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Fabrice Weinberg 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var rcswitch = require('rcswitch'); 2 | 3 | var Service; 4 | var Characteristic; 5 | 6 | module.exports = function (homebridge) { 7 | Service = homebridge.hap.Service; 8 | Characteristic = homebridge.hap.Characteristic; 9 | homebridge.registerAccessory('homebridge-rcswitch', 'RcSwitch', RadioSwitch); 10 | }; 11 | 12 | function RadioSwitch(log, config) { 13 | if (config.systemcode === undefined) { 14 | return log('Systemcode missing from configuration.'); 15 | } 16 | if (config.unitcode === undefined) { 17 | return log('Unitcode missing from configuration.'); 18 | } 19 | if (config.name === undefined) { 20 | return log('Name missing from configuration.'); 21 | } 22 | 23 | rcswitch.enableTransmit(config.pin || 0); 24 | 25 | var switchOn = rcswitch.switchOn.bind(rcswitch, config.systemcode, config.unitcode); 26 | var switchOff = rcswitch.switchOff.bind(rcswitch, config.systemcode, config.unitcode); 27 | 28 | var informationService = new Service.AccessoryInformation(); 29 | 30 | informationService 31 | .setCharacteristic(Characteristic.Name, 'Raspberry-Projekt') 32 | .setCharacteristic(Characteristic.Manufacturer, 'JadeHochschule') 33 | .setCharacteristic(Characteristic.Model, 'v0.1') 34 | .setCharacteristic(Characteristic.SerialNumber, config.systemcode + '|' + config.unitcode); 35 | 36 | var state = false; 37 | var switchService = new Service.Switch(config.name); 38 | 39 | switchService 40 | .getCharacteristic(Characteristic.On) 41 | .on('set', function (value, callback) { 42 | state = value; 43 | if (state) { 44 | switchOn(); 45 | } else { 46 | switchOff(); 47 | } 48 | callback(); 49 | }); 50 | 51 | switchService 52 | .getCharacteristic(Characteristic.On) 53 | .on('get', function (callback) { 54 | callback(null, state); 55 | }); 56 | 57 | this.services = [informationService, switchService]; 58 | } 59 | 60 | RadioSwitch.prototype = { 61 | getServices: function () { 62 | return this.services; 63 | } 64 | }; 65 | --------------------------------------------------------------------------------