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.
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
npm install sectoralarm
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 is your e-mail and password used when creating an account with Sector Alarm.
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
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.
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.
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.
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 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 |
{ "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).
[ { "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" } ]
{ "status": "success", "name": "Home", "armedStatus": "disarmed" }
{ "sensorId": "123", "name": "livingRoom", "temperature": "26" }
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.
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.