From f28e9493dfd3e282b683652f9098e6051cbacbca Mon Sep 17 00:00:00 2001 From: Ray Bennett Date: Mon, 29 Jun 2015 17:48:40 -0700 Subject: [PATCH 1/2] Adding support for arming Elk M1 security system. --- accessories/ELKM1.js | 126 +++++++++++++++++++++++++++++++++++++++++++ config-sample.json | 9 ++++ package.json | 3 +- 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 accessories/ELKM1.js diff --git a/accessories/ELKM1.js b/accessories/ELKM1.js new file mode 100644 index 0000000..7ac2ba3 --- /dev/null +++ b/accessories/ELKM1.js @@ -0,0 +1,126 @@ +var types = require("../lib/HAP-NodeJS/accessories/types.js"); +var elkington = require("elkington"); + +function ElkM1Accessory(log, config) { + this.log = log; + this.name = config["name"]; + this.zone = config["zone"]; + this.host = config["host"]; + this.port = config["port"]; + this.pin = config["pin"]; + this.arm = config["arm"]; +} + +ElkM1Accessory.prototype = { + setPowerState: function(alarmOn) { + var that = this; + + if (!alarmOn) + { + return; + } + + var elk = elkington.createConnection({ + port: that.port, + host: that.host, + }); + + switch (that.arm) + { + case 'Away': + elk.armAway({area: that.zone, code: that.pin}); + break; + case 'Stay': + elk.armStay({area: that.zone, code: that.pin}); + break; + case 'Night': + elk.armNightInstant({area: that.zone, code: that.pin}); + break; + default: + break; + } + }, + + getServices: function() { + var that = this; + return [{ + sType: types.ACCESSORY_INFORMATION_STYPE, + characteristics: [{ + cType: types.NAME_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: this.name, + supportEvents: false, + supportBonjour: false, + manfDescription: "Name of the accessory", + designedMaxLength: 255 + },{ + cType: types.MANUFACTURER_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: "Elk", + supportEvents: false, + supportBonjour: false, + manfDescription: "Manufacturer", + designedMaxLength: 255 + },{ + cType: types.MODEL_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: "M1", + supportEvents: false, + supportBonjour: false, + manfDescription: "Model", + designedMaxLength: 255 + },{ + cType: types.SERIAL_NUMBER_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: "A1S2NASF88EW", + supportEvents: false, + supportBonjour: false, + manfDescription: "SN", + designedMaxLength: 255 + },{ + cType: types.IDENTIFY_CTYPE, + onUpdate: null, + perms: ["pw"], + format: "bool", + initialValue: false, + supportEvents: false, + supportBonjour: false, + manfDescription: "Identify Accessory", + designedMaxLength: 1 + }] + },{ + sType: types.SWITCH_STYPE, + characteristics: [{ + cType: types.NAME_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: this.name, + supportEvents: false, + supportBonjour: false, + manfDescription: "Name of service", + designedMaxLength: 255 + },{ + cType: types.POWER_STATE_CTYPE, + onUpdate: function(value) { that.setPowerState(value); }, + perms: ["pw","pr","ev"], + format: "bool", + initialValue: false, + supportEvents: false, + supportBonjour: false, + manfDescription: "Alarm the Zone", + designedMaxLength: 1 + }] + }]; + } +}; + +module.exports.accessory = ElkM1Accessory; diff --git a/config-sample.json b/config-sample.json index e8e4b96..639ccb1 100644 --- a/config-sample.json +++ b/config-sample.json @@ -102,6 +102,15 @@ "off_url": "https://192.168.1.22:3030/devices/23222/off", "brightness_url": "https://192.168.1.22:3030/devices/23222/brightness/%b", "http_method": "POST" + },{ + "accessory": "ELKM1", + "name": "Security System", + "description": "Allows basic control of Elk M1 security system. You can use 1 of 3 arm modes: Away, Stay, Night. If you need to access all 3, create 3 accessories with different names.", + "zone": "1", + "host": "192.168.1.10", + "port": "2101", + "pin": "1234", + "arm": "Away" } ] } diff --git a/package.json b/package.json index c12ab9f..822badd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "carwingsjs": "0.0.x", "sonos": "0.8.x", "wemo": "0.2.x", - "wink-js": "0.0.5" + "wink-js": "0.0.5", + "elkington": "kevinohara80/elkington" } } From a3e34088b98722e132d628d12d703aedefec892e Mon Sep 17 00:00:00 2001 From: Alistair Galbraith Date: Wed, 1 Jul 2015 12:47:50 -0700 Subject: [PATCH 2/2] A MyQ account with multiple opener devices will trigger a fatal exception, after dumping out possible doors and their names Also updated config-sample.json with additional option, and comments --- accessories/LiftMaster.js | 47 ++++++++++++++++++++++++++++++++++++--- config-sample.json | 1 + 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/accessories/LiftMaster.js b/accessories/LiftMaster.js index 8d15c38..8b6b33f 100644 --- a/accessories/LiftMaster.js +++ b/accessories/LiftMaster.js @@ -83,20 +83,61 @@ LiftMasterAccessory.prototype = { // parse and interpret the response var json = JSON.parse(body); var devices = json["Devices"]; + var foundDoors = []; // look through the array of devices for an opener for (var i=0; i 1) { + that.log("WARNING: You have multiple doors on your MyQ account."); + that.log("WARNING: Specify the ID of the door you want to control using the 'requiredDeviceId' property in your config.json file."); + that.log("WARNING: You can have multiple liftmaster accessories to cover your multiple doors"); + + for (var j = 0; j < foundDoors.length; j++) { + that.log("Found Door: " + foundDoors[j]); + } + + throw "FATAL: Please specify which specific door this Liftmaster accessory should control - you have multiples on your account"; + + } + + // Did we get a device ID? if (that.deviceId) { that.log("Found an opener with ID " + that.deviceId +". Ready to send command..."); that.setTargetState(); } + else + { + that.log("Error: Couldn't find a door device, or the ID you specified isn't associated with your account"); + } } else { that.log("Error '"+err+"' getting devices: " + body); diff --git a/config-sample.json b/config-sample.json index e8e4b96..768a1d1 100644 --- a/config-sample.json +++ b/config-sample.json @@ -48,6 +48,7 @@ "accessory": "LiftMaster", "name": "Garage Door", "description": "This shim supports LiftMaster garage door openers that are already internet-connected to the 'MyQ' service.", + // "requiredDeviceId", "", "username": "your-liftmaster-username", "password" : "your-liftmaster-password" },