UNPKG

homebridge-sensor-autostart-switch

Version:

Install this plugin

47 lines (34 loc) 1.18 kB
var Service, Characteristic; var state = true; var Gpio = require('onoff').Gpio; var clos = 0; module.exports = function (homebridge) { Service = homebridge.hap.Service; Characteristic = homebridge.hap.Characteristic; homebridge.registerAccessory("homebridge-sensor-autostart-switch", "sensautoswitch", sensautoswitchAccessory); }; function sensautoswitchAccessory(log, config) { //config this.name = config["name"]; this.pin = config['pin']; this.timeopen = config["timeopen"]; //setup this.log = log; this.service = new Service.ContactSensor(this.name); this.service .getCharacteristic(Characteristic.ContactSensorState) .on('get', this.getState.bind(this)); var relay = new Gpio(this.pin, 'out'); relay.writeSync(0); clos = 1; this.service.setCharacteristic(Characteristic.ContactSensorState, clos); setTimeout(function(){ relay.writeSync(1); }, 10000 * this.timeopen); } sensautoswitchAccessory.prototype.getState = function (callback) { callback(null, state); }; sensautoswitchAccessory.prototype.getServices = function () { return [this.service]; };