perbrage / sectoralarm

Sector Alarm Node.js Library
MIT License
23 stars 8 forks source link
alarm node nodejs sector sector-alarm swedish

Sector Alarm Node.js Library

Information

A node.js library to communicate with your Sector Alarm sites. Library supports checking the current status, the history and also acting upon the alarm and its connected devices.

Supported features

Supported in the following countries

Country Site Verified
Sweden http://www.sectoralarm.se Yes
Norway http://www.sectoralarm.no Yes
Finland http://www.sectoralarm.fi Yes
Spain http://www.sectoralarm.es No
Ireland http://www.phonewatch.ie Yes

If you use this library in a country listed above as not verified, please drop me a note. You can visit Sector Alarm Group http://www.sectoralarm.com

Installation

npm install sectoralarm

Account and other configuration identifiers

Connecting and acting upon your alarm requires you to have an account with Sector Alarm. Your e-mail and account password, together with a SiteId is required to connect. SiteId is required to identify which site you want to connect to and fetch information from or act upon. This is a feature that allows for users with multiple homes to connect to different homes/sites.

Account information

Account information is your e-mail and password used when creating an account with Sector Alarm.

SiteId

To find out your siteId, browse to https://mypagesapi.sectoralarm.net. Login using your accounts e-mail and password. After you have been authenticated, you can have a look at the URL in your browser. At the end of the URL you will find your SiteId. Example .../#!/systems/01234567

Code

The code is your alarm panel code. You can add/edit codes in Sector Alarms app for different users. The code used will identify who armed/disarmed your site. You can also apply a setting that codes are not required on your account for arming the site. In that case a code is not needed when arming.

Device identifiers

To find out the identifiers of your devices, locks, smartplugs and such, use the different methods to aquire the information, for example .locks(), .temperatures(), .info() etc.

BREAKING CHANGES IN v2.0.0+

In version v2.0.0, some minor changes to how to use the library has been changed, which would be considered breaking changes to previous versions. In v2.0.0+ status has been split into two methods, info and status. Some of the response messages has also changed slightly. Should you upgrade to v2.0.0 and beyond, please make sure your solution still works. See new changelog at the bottom for additions and changes. Thank you.

Usage example

const sectoralarm = require('sectoralarm');

const email = '<Your account email>',
      password = '<Your account password>',
      siteId = '<Your Panel/Site ID>',
      code = '<Code to use for arming/disarming>',
      lockId = '<The ID of one of your locks>',
      sensorId = '<The ID of one of your sensors>';

var settings = sectoralarm.createSettings();

settings.jsonOutput = false;
settings.numberOfRetries = 4;
settings.retryDelayInMs = 4500;

sectoralarm.connect(email,password,siteId, settings)
    .then(async (site) => {
        await site.info()
            .then(console.log);

        await site.status()
            .then(console.log);

        await site.history()
            .then(console.log);

        await site.temperatures()
            .then(console.log);

        await site.temperatures(sensorId)
            .then(console.log);

        await site.locks()
            .then(console.log);

        await site.locks(lockId)
            .then(console.log);

        await site.partialArm(code)
            .then(console.log);

        await site.disarm(code)
            .then(console.log);

        await site.arm(code)
            .then(console.log);

        await site.annexArm(code)
            .then(console.log);

        await site.annexDisarm(code)
            .then(console.log);

        await site.lock(lockId, code)
            .then(console.log);

        await site.unlock(lockId, code)
            .then(console.log);

    })
    .catch(error => {
        console.log(error.message);
        console.log(error.code);
    });

sectoralarm.connect(email,password,siteId)
    .then(site => {
        return site.status();
    })
    .then(console.log)
    .catch(error => {
        console.log(error.message);
        console.log(error.code);
    })

Error messages

Error code Description
ERR_INVALID_CREDENTIALS Invalid email and/or password.
ERR_INVALID_SESSION Session has timed out, use login() on the site object
ERR_PARSING_ERROR Could not parse the response, this library will need updates
ERR_COMMUNICATION_ERROR Could not communicate properly with sector alarm, this library will need updates
ERR_INVALID_CODE Invalid code used for arming/disarming
ERR_INVALID_VERSION Sector alarm has changed the version on their API. Restart application or use 'login' on site object

Output

Example output from calling status

{ "siteId": "38728342",
  "name": "Home",
  "armedStatus": "disarmed",
  "partialArmingAvailable": true,
  "annexArmingAvailable": false,
  "annexArmedStatus": "unknown",
  "lastInteractionBy": "Code",
  "lastInteractionTime": "2018-11-30 06:20:35",
  "locksAvailable":false,
  "locks":[]}

NOTE: armedStatus can either be armed, partialArmed or disarmed and user can either be the user name, be empty or state Code (if a code was used to arm/disarm).

Example output from calling history

[ { "time": "2018-01-23 07:48:19", "action": "armed", "user": "Code" },
  { "time": "2018-01-22 16:45:52", "action": "disarmed", "user": "Code" },
  { "time": "2018-01-22 07:46:23", "action": "armed", "user": "Code" },
  { "time": "2018-01-20 15:14:18", "action": "disarmed", "user": "Code" },
  { "time": "2018-01-19 15:51:05", "action": "armed", "user": "" },
  { "time": "2018-01-19 15:50:46", "action": "disarmed", "user": "Code" },
  { "time": "2018-01-19 15:50:11", "action": "partialArmed", "user": "" },
  { "time": "2018-01-19 15:49:30", "action": "disarmed", "user": "Code" },
  { "time": "2018-01-13 11:45:57", "action": "armed", "user": "Code" },
  { "time": "2018-01-13 11:44:53", "action": "disarmed", "user": "Code" } ]

Example output from calling arm, partialArm, disarm, annexArm or annexDisarm

{ "status": "success", "name": "Home", "armedStatus": "disarmed" }

Example output from calling temperatures

{ "sensorId": "123", "name": "livingRoom", "temperature": "26" }

Contributions

Thank you for those of you who have contributed to this project, put time and effort into adding features through pull requests or in other ways helped out during development.

Looking for help

I am currently looking for someone with cameras and smartplugs connected to a sector alarm site that want to help out with testing and/or development. Check the issue page and reply there.

Changelog

v2.1.2 - 2022-02-10

v2.1.1 - 2022-01-24

v2.1.0 - 2022-01-24

v2.0.6 - 2020-01-09

v2.0.5 - 2019-08-09

v2.0.3 - 2019-06-17

v2.0.2 - 2019-04-12

v2.0.1 - 2019-04-11

v2.0.0 - 2018-12-15

v1.5.0 - 2018-11-29

v1.4.0 - 2018-10-28

v1.3.0 - 2018-10-06

v1.2.0 - 2018-04-29

v1.1.2 - 2018-04-03