Skip to content

Commit

Permalink
Add support for custom commands and panic alarms.
Browse files Browse the repository at this point in the history
Fixes #80 and #81
  • Loading branch information
dustindclark committed Nov 21, 2021
1 parent ff54ced commit 2c5568e
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 20 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ Example configuration is below. See [config.schema.json](./blob/master/config.s
"pin": "---panel pin for disarming---",
"suppressZoneAccessories": false,
"suppressClockReset": false,
"ambulancePanic": {
"enabled": true,
"name": "Ambulance Panic"
},
"firePanic": {
"enabled": true,
"name": "Fire Panic"
},
"policePanic": {
"enabled": true,
"name": "Police Panic"
},
"partitions": [
{
"name": "Alarm"
Expand Down Expand Up @@ -56,11 +68,14 @@ Example configuration is below. See [config.schema.json](./blob/master/config.s
"partition": 1
}
],
"userPrograms": [
"customCommands": [
{
"name": "Basement Smoke",
"type": "smoke",
"partition": 1
"name": "Chime Toggle - Partition 1",
"command": "0711*4"
},
{
"name": "System Test",
"command": "071*600004"
}
]
}
Expand Down Expand Up @@ -100,8 +115,8 @@ Ex:
...
```

### User Programs
If you don't know what they are, you don't need them. Skip this property.
### Custom Commands
See documentation in "docs" folder for crafting a custom command. Examples above are real DSC commands.

<br />
*Note*: Only DSC panels have been tested thus far. If you'd like to provide a Honeywell device for testing, I'd be glad to add support for this device and ship it back to you.
Expand Down
73 changes: 73 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,57 @@
"description": "Plugin will update the date/time of your alarm system hourly unless selected",
"default": true
},
"policePanic" :{
"type": "object",
"properties": {
"enabled": {
"title": "Enable Police Panic",
"type": "boolean",
"description": "Creates a switch for police panic button",
"default": false
},
"name": {
"title": "Police Panic Switch Name",
"type": "string",
"description": "Name for police panic button.",
"default": "Police Panic"
}
}
},
"ambulancePanic" :{
"type": "object",
"properties": {
"enabled": {
"title": "Enable Ambulance Panic",
"type": "boolean",
"description": "Creates a switch for ambulance panic button",
"default": false
},
"name": {
"title": "Ambulance Panic Switch Name",
"type": "string",
"description": "Name for ambulance panic button.",
"default": "Ambulance Panic"
}
}
},
"firePanic" :{
"type": "object",
"properties": {
"enabled": {
"title": "Enable Fire Panic",
"type": "boolean",
"description": "Creates a switch for fire panic button",
"default": false
},
"name": {
"title": "Fire Panic Switch Name",
"type": "string",
"description": "Name for fire panic button.",
"default": "Fire Panic"
}
}
},
"partitions": {
"title": "Partitions",
"type": "array",
Expand Down Expand Up @@ -134,6 +185,28 @@
}
}
}
},
"customCommands": {
"title": "Custom Commands",
"type": "array",
"items": {
"title": "Custom Command",
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string",
"description": "Name of Custom Command",
"required": true
},
"command": {
"title": "Command",
"type": "string",
"description": "Custom Command Sequence",
"required": true
}
}
}
}
}
}
Expand Down
Binary file added docs/EnvisaLinkTPI-1-08.pdf
Binary file not shown.
69 changes: 56 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function EnvisalinkPlatform(log, config) {
this.password = config.password;
this.partitions = config.partitions ? config.partitions : [{ name: 'Alarm' }];
this.zones = config.zones ? config.zones : [];
this.userPrograms = config.userPrograms ? config.userPrograms : [];
this.customCommands = config.customCommands ? config.customCommands : [];

this.log.info("Configuring Envisalink platform, Host: " + config.host + ", port: " + config.port + ", type: " + this.deviceType);

Expand Down Expand Up @@ -88,15 +88,36 @@ function EnvisalinkPlatform(log, config) {
}
}
}
var extraZones = maxZone;
this.platformProgramAccessories = [];
for (var i = 0; i < this.userPrograms.length; i++) {
var program = this.userPrograms[i];
if (program.type === "smoke") {
var accessory = new EnvisalinkAccessory(this.log, program.type, program, program.partition, maxZone + i + 1);
this.platformProgramAccessories.push(accessory);
} else {
this.log.error("Unhandled accessory type: " + program.type);
}
for (var i = 0; i < this.customCommands.length; i++) {
var program = this.customCommands[i];
var accessory = new EnvisalinkAccessory(this.log, "custom", program, 1, ++extraZones);
this.platformProgramAccessories.push(accessory);
}

if (config.firePanic && config.firePanic.enabled) {
this.log.info("Adding fire panic switch.");
var program = config.firePanic;
program.command = "0601";
var accessory = new EnvisalinkAccessory(this.log, "custom", program, 1, ++extraZones);
this.platformProgramAccessories.push(accessory);
}

if (config.ambulancePanic && config.ambulancePanic.enabled) {
this.log.info("Adding ambulance panic switch.");
var program = config.ambulancePanic;
program.command = "0602";
var accessory = new EnvisalinkAccessory(this.log, "custom", program, 1, ++extraZones);
this.platformProgramAccessories.push(accessory);
}

if (config.policePanic && config.policePanic.enabled) {
this.log.info("Adding police panic switch.");
var program = config.policePanic;
program.command = "0603";
var accessory = new EnvisalinkAccessory(this.log, "custom", program, 1, ++extraZones);
this.platformProgramAccessories.push(accessory);
}

this.log.info("Starting node alarm proxy...");
Expand All @@ -108,14 +129,13 @@ function EnvisalinkPlatform(log, config) {
serverhost: '0.0.0.0',
serverport: config.serverport ? config.serverport : 4026,
zone: maxZone > 0 ? maxZone : null,
userPrograms: this.userPrograms.length > 0 ? this.userPrograms.length : null,
userPrograms: null,
partition: this.partitions ? this.partitions.length : 1,
proxyenable: true,
atomicEvents: true,
logging: false
};
this.log.info("Zone Config: " + this.alarmConfig.zone);
this.log.info("User Program Config: " + this.alarmConfig.userPrograms);
this.alarm = nap.initConfig(this.alarmConfig);
this.log.info("Node alarm proxy started. Listening for connections at: " + this.alarmConfig.serverhost + ":" + this.alarmConfig.serverport);
this.alarm.on('data', this.systemUpdate.bind(this));
Expand Down Expand Up @@ -248,7 +268,6 @@ EnvisalinkPlatform.prototype.zoneUpdate = function (data) {
});

} else if (accessory.accessoryType == "smoke") {

accessory.getSmokeStatus(function (nothing, resultat) {
accservice.getCharacteristic(Characteristic.SmokeDetected).setValue(resultat);
});
Expand Down Expand Up @@ -377,6 +396,14 @@ function EnvisalinkAccessory(log, accessoryType, config, partition, zone) {
.getCharacteristic(Characteristic.SmokeDetected)
.on('get', this.getSmokeStatus.bind(this));
this.services.push(service);
} else if (this.accessoryType == "custom") {
//var service = new Service.StatelessProgrammableSwitch(this.name);
var service = new Service.Switch(this.name);
this.command = config.command;
service.getCharacteristic(Characteristic.On)
.on('set', this.invokeCustomCommand.bind(this))
.on('get', this.getCustomCommandState.bind(this))
this.services.push(service);
}
}

Expand Down Expand Up @@ -429,6 +456,19 @@ EnvisalinkAccessory.prototype.setAlarmState = function (state, callback) {
this.addDelayedEvent('alarm', state, callback);
}

EnvisalinkAccessory.prototype.invokeCustomCommand = function (state, callback) {
var self = this;
this.addDelayedEvent('custom', this.command, function(state) {
self.log("In invokeCustomCommand callback. Sending false.");
callback(null, false);
self.getServices()[0].updateCharacteristic(Characteristic.On, false);
});
}

EnvisalinkAccessory.prototype.getCustomCommandState = function (callback) {
callback(null, false);
}

EnvisalinkAccessory.prototype.getContactSensorState = function (callback) {
if (this.status && this.status.send == "open") {
callback(null, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
Expand Down Expand Up @@ -474,8 +514,11 @@ EnvisalinkAccessory.prototype.processAlarmState = function (nextEvent, callback)
} else if (nextEvent.data == Characteristic.SecuritySystemCurrentState.AWAY_ARM) {
this.log("Arming alarm to Away.");
command = "030" + this.partition;
} else if (nextEvent.type == "custom") {
command = nextEvent.data;
}
if (command) {
this.log("Command is " + command);
var self = this;
nap.manualCommand(command, function (msg) {
if (msg === '024') {
Expand Down Expand Up @@ -580,7 +623,7 @@ EnvisalinkAccessory.prototype.processDelayedEvents = function () {
setTimeout(this.processDelayedEvents.bind(this), 0);
}
};
if (nextEvent.type === 'alarm') {
if (nextEvent.type === 'alarm' || nextEvent.type === 'custom') {
this.processAlarmState(nextEvent, callback.bind(this));
} else if (nextEvent.type === 'time') {
this.processTimeChange(nextEvent, callback.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-envisalink",
"version": "0.2.18",
"version": "0.3.1-beta.0",
"description": "A homebridge plugin for the EnvisaLink alarm module",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2c5568e

Please sign in to comment.