var types = require("../lib/HAP-NodeJS/accessories/types.js"); var request = require("request"); // This seems to be the "id" of the official LiftMaster iOS app var APP_ID = "JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu" function LiftMasterAccessory(log, config) { this.log = log; this.name = config["name"]; this.username = config["username"]; this.password = config["password"]; } LiftMasterAccessory.prototype = { setState: function(state) { this.targetState = state; this.login(); }, login: function() { var that = this; // reset our logged-in state hint until we're logged in this.deviceId = null; // querystring params var query = { appId: APP_ID, username: this.username, password: this.password, culture: "en" }; // login to liftmaster request.get({ url: "https://myqexternal.myqdevice.com/api/user/validatewithculture", qs: query }, function(err, response, body) { if (!err && response.statusCode == 200) { // parse and interpret the response var json = JSON.parse(body); that.userId = json["UserId"]; that.securityToken = json["SecurityToken"]; that.log("Logged in with user ID " + that.userId); that.getDevice(); } else { that.log("Error '"+err+"' logging in: " + body); } }); }, // find your garage door ID getDevice: function() { var that = this; // querystring params var query = { appId: APP_ID, SecurityToken: this.securityToken, filterOn: "true" }; // some necessary duplicated info in the headers var headers = { MyQApplicationId: APP_ID, SecurityToken: this.securityToken }; // request details of all your devices request.get({ url: "https://myqexternal.myqdevice.com/api/v4/userdevicedetails/get", qs: query, headers: headers }, function(err, response, body) { if (!err && response.statusCode == 200) { // parse and interpret the response var json = JSON.parse(body); var devices = json["Devices"]; // look through the array of devices for an opener for (var i=0; i