0.0.4 • Published 4 years ago

myq-api-2 v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

myq-api

Interface with your MyQ devices. Works and tested with both Chamberlain and LiftMaster.


NOTE: This package is currently not working. A new update will be released after this pull request is merged in.


Installation

yarn add myq-api   or   npm install myq-api

Usage Overview

new MyQ(email, password)

Initialize credentials of the user using email and password.

ParametersRequiredTypeDetails
emailtrueStringUser email
passwordtrueStringUser password

Example code:

var { myQ, constants } = require('myq-api');
var account = new myQ('email', 'password');

account.login()

Logs into the MyQ account and generates a security token. This security token must be generated before you access the rest of this API. Note that this security token is short-term and will not work after some time.

Example code:

account.login()
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  "returnCode": 0,
  "token": "abcd1234-a1b2-ab12-a1b2-abcdef123456"
}

account.getDevices(typeIds)

Returns devices on the account. A (very incomplete) list of possible Type names are provided as constants. See Possible Values for more information.

ParameterRequiredTypeDetails
typeIdsfalseType NameEither an array of Type names or a singular Type name.

Example code:

// Optionally, pass in device types to filter them.
// If none are specified, all devices will be returned.
// [WIP]: Fix this.
account.getDevices([
  constants.allDeviceTypes.hub,
  constants.allDeviceTypes.virtualGarageDoorOpener
])
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  returnCode: 0,
  devices: [
    {
      family: 'garagedoor',
      name: 'Garage Door Opener',
      type: 'virtualgaragedooropener',
      serialNumber: '123456ABCDEF',
      online: true,
      doorState: 'closed',
      doorStateUpdated: '12/1/2019, 8:20:18 PM'
    },
    {
      family: 'gateway',
      name: 'Hub',
      type: 'hub',
      serialNumber: 'ABCDEF123456',
      online: true
    }
  ]
}

account.getDoorState(id)

Retrieves the latest state of the requested door.

ParameterRequiredTypeDetails
idtrueIntegerDoor ID

Example code:

account.getDoorState(door.serialNumber)
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  "returnCode": 0,
  "doorState": "closed" // See Possible Values
}

account.getLightState(id)

Retrieves the latest state of the requested light.

ParameterRequiredTypeDetails
idtrueIntegerLight ID

Example code:

account.getLightState(light.id)
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  "returnCode": 0,
  "lightState": "on" // See Possible Values
}

account.setDoorOpen(serialNumber, shouldOpen)

Set the requested door to open or close. Returns a confirmation once complete. Note that the door might not be opened or closed fully by the time this function returns.

ParameterRequiredTypeDetails
serialNumbertrueStringSerial number of the device
toggletrueBooleantrue or false

Example code:

account.setDoorState(door.serialNumber, true)
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  "returnCode": 0
}

account.setLightState(id, toggle)

Set the requested light to on or off. Returns a confirmation once complete.

ParameterRequiredTypeDetails
serialNumbertrueStringLight Serial Number
turnOntrueBooleanWhether the light should be on or off

Example code:

account.setLightState(light.serialNumber, 1)
  .then(function (result) {
    console.log(result);
  }).catch(function (err) {
    console.error(err);
  });

Example returned object if call is successful:

{
  "returnCode": 0
}

Possible Values

This is a (partial) list of the types of devices that MyQ supports. MyQ no longer returns on Type IDs, but rather, returns (mostly) human-readable strings. Constants for these are provided for your convenience.

Pull requests are welcome to add other device types :)

ConstantType Name
hubhub
virtualGarageDoorOpenervirtualgaragedooropener
wifiGarageDoorOpenerwifigaragedooropener
wifiGdoGatewaywifigdogateway
Type IDDescription
1Gateway
2GDO
3Light
5Gate
7VGDO Garage Door
9Commercial Door Operator (CDO)
13Camera
15WGDO Gateway AC
16WGDO Gateway DC
17WGDO Garage Door
Door ToggleDescription
falseclose door
trueopen door
doorStateDescription
1open
2closed
3stopped in the middle
4going up
5going down
9not closed
Light ToggleDescription
0turn off light
1turn on light
lightStateDescription
0off
1on

Return Codes

Each call to the API will include a return code as well as an error message if applicable. The return codes as well their correlated messages have been listed here for convenience.

Return CodeMessage
0Successful!
11Something unexpected happened. Please wait a bit and try again.
12MyQ service is currently down. Please wait a bit and try again.
13Not logged in.
14Email and/or password are incorrect.
15Invalid parameter(s) provided.
16User will be locked out due to too many tries. 1 try left.
17User is locked out due to too many tries. Please reset password and try again.

Example returned object if call is unsuccessful:

{
  returnCode: 14,
  message: "Email and/or password are incorrect."
}

Since the underlying MyQ API is volatile, there might be changes unforeseen by the current version of this software. An extra message detailing the request error that it encountered will be returned whenever possible.

{
  returnCode: 11,
  message: "Something unexpected happened. Please wait a bit and try again."
  unhandledError: // request error
}

Please create a GitHub issue when this happens.

Promises

This API depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can polyfill.

Contributing

If you would like to contribute enhancements or fixes, please do the following: 1. Fork the repository and clone it locally. 2. Make your changes. 3. Create a pull request.

Authors

License

MIT