Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homebridge-delay-switch

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-delay-switch - npm Package Compare versions

Comparing version 3.1.1 to 3.2.1

93

config.schema.json

@@ -17,4 +17,4 @@ {

"delay": {
"title": "Delay Time in Milliseconds",
"description": "Amount of time in milliseconds to wait since the switch is turned ON until the switch will be turned OFF and the sensor will trigger",
"title": "Delay Time",
"description": "Delay to wait until the switch will be turned OFF. Each activation of the switch will reactivate timer (time will start to run again). 0 - timer disabled.",
"type": "integer",

@@ -24,7 +24,21 @@ "default": 5000,

},
"delayUnit": {
"title": "Delay unit",
"description": "Delay unit: miliseconds, seconds, minutes, hour, days.",
"type": "string",
"default": "miliseconds",
"required": true,
"oneOf": [
{ "title": "miliseconds", "enum": ["miliseconds"] },
{ "title": "seconds", "enum": ["seconds"] },
{ "title": "minutes", "enum": ["minutes"] },
{ "title": "hours", "enum": ["hours"] },
{ "title": "days", "enum": ["days"] }
]
},
"sensorType": {
"title": "Trigger Sensor Type",
"description": "The sensor type that will trigger when the time has ended (\"None\" for no sensor, \"Motion Sensor\" is default)",
"description": "Add an optional sensor that will be activated when the timer comes to an end.",
"type": "string",
"default": "motion",
"default": "",
"required": false,

@@ -40,3 +54,3 @@ "oneOf": [

"title": "Flip Sensor State",
"description": "Enable to flip the trigger sensor state (close/open, detected/not detected)",
"description": "Enable to flip the trigger sensor state (close/open, detected/not detected).",
"type": "boolean",

@@ -48,3 +62,3 @@ "default": false,

"title": "Turn ON when Homebridge Restarts",
"description": "When Enabled, the switch will be turned ON and start the timer when HomeBridge server restarts",
"description": "Activate switch after Homebridge restart.",
"type": "boolean",

@@ -56,3 +70,3 @@ "default": false,

"title": "Enable Debug Logs",
"description": "When checked, the plugin will produce extra logs for debugging purposes",
"description": "Produce extra logs for debugging purposes",
"type": "boolean",

@@ -63,3 +77,66 @@ "default": false,

}
},
"layout": [
{
"type": "fieldset",
"title": "Basic settings",
"description": "",
"expandable": true,
"expanded": true,
"items": [
{
"type": "flex",
"flex-flow": "row wrap",
"items": ["name"]
},
{
"type": "flex",
"flex-flow": "row wrap",
"items": ["startOnReboot"]
}
]
},
{
"type": "fieldset",
"title": "Timer",
"description": "",
"expandable": true,
"expanded": false,
"items": [
{
"type": "flex",
"flex-flow": "row wrap",
"items": ["delay", "delayUnit"]
}
]
},
{
"type": "fieldset",
"title": "Additional Sensor",
"description": "",
"expandable": true,
"expanded": false,
"items": [
{
"type": "flex",
"flex-flow": "row wrap",
"items": ["sensorType", "flipSensorState"]
}
]
},
{
"type": "fieldset",
"title": "Logs",
"description": "",
"expandable": true,
"expanded": false,
"items": [
{
"type": "flex",
"flex-flow": "row wrap",
"items": ["debug"]
}
]
}
}
]
}

86

index.js

@@ -1,3 +0,1 @@

var Service, Characteristic;

@@ -17,3 +15,5 @@

this.name = config['name'];
this.delay = config['delay'];
this.delay = config['delay'] || 0;
this.delayUnit = config['delayUnit'] || "miliseconds";
this.newDelay = config['delay'] || 0;
this.debug = config.debug || false

@@ -25,3 +25,3 @@ this.sensorType = config['sensorType'];

this.disableSensor = config['disableSensor'] || !config['sensorType'];
this.startOnReboot = config['startOnReboot'];
this.startOnReboot = config['startOnReboot'] || false;
this.timer;

@@ -61,13 +61,11 @@ this.switchOn = false;

.setCharacteristic(Characteristic.Manufacturer, "Delay Switch")
.setCharacteristic(Characteristic.Model, `Delay-${this.delay}ms`)
.setCharacteristic(Characteristic.Model, `Delay-${this.delay}-${this.delayUnit}`)
.setCharacteristic(Characteristic.SerialNumber, this.uuid);
this.switchService = new Service.Switch(this.name);
this.switchService.getCharacteristic(Characteristic.On)
.on('get', this.getOn.bind(this))
.on('set', this.setOn.bind(this));
if (this.startOnReboot)

@@ -111,8 +109,6 @@ this.switchService.setCharacteristic(Characteristic.On, true)

delaySwitch.prototype.setOn = function (value, callback) {
delaySwitch.prototype.setOn = function (on, callback) {
if (!on) {
if (value === false) {
this.log.easyDebug('Stopping the Timer');
this.switchOn = false;

@@ -122,34 +118,50 @@ clearTimeout(this.timer);

if (!this.disableSensor) this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
} else {
this.log.easyDebug('Starting the Timer');
} else if (value === true) {
this.switchOn = true;
clearTimeout(this.timer);
this.timer = setTimeout(function() {
this.log.easyDebug('Time is Up!');
this.switchService.getCharacteristic(Characteristic.On).updateValue(false);
this.switchOn = false;
if (!this.disableSensor) {
this.sensorTriggered = 1;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
this.log.easyDebug('Triggering Sensor');
setTimeout(function() {
this.sensorTriggered = 0;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
}.bind(this), 3000);
}
}.bind(this), this.delay);
if (this.delay > 0) {
switch (this.delayUnit) {
case 'miliseconds':
this.newDelay = this.delay;
break;
case 'seconds':
this.newDelay = this.delay * 1000;
break;
case 'minutes':
this.newDelay = this.delay * 60 * 1000;
break;
case 'hours':
this.newDelay = this.delay * 60 * 60 * 1000;
break;
case 'days':
this.newDelay = this.delay * 24 * 60 * 60 * 1000 ;
break;
default:
this.newDelay = this.delay;
break;
}
this.log.easyDebug('Starting the Timer');
this.timer = setTimeout(function() {
this.log.easyDebug('Time is Up!');
this.switchService.getCharacteristic(Characteristic.On).updateValue(false);
this.switchOn = false;
if (!this.disableSensor) {
this.sensorTriggered = 1;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
this.log.easyDebug('Triggering Sensor');
setTimeout(function() {
this.sensorTriggered = 0;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
}.bind(this), 3000);
}
}.bind(this), this.newDelay);
}
}
callback();
}
delaySwitch.prototype.getOn = function (callback) {
callback(null, this.switchOn);
}
{
"name": "homebridge-delay-switch",
"version": "3.1.1",
"version": "3.2.1",
"description": "Delay switches for Homebridge",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -29,6 +29,7 @@ <img src="branding/delayswitch_homebridge.png" width="500px">

"name": "DelaySwitch",
"delay": 5000,
"startOnReboot": false,
"delay": 5,
"delayUnit": "miliseconds",
"sensorType": "motion",
"flipSensorState": false,
"startOnReboot": false
"flipSensorState": false
}

@@ -43,7 +44,9 @@ ]

| `name` | Name for your accessory | ✓ | - | String |
| `delay` | Delay/Timer in milliseconds | ✓ | - | Integer |
| `sensorType` | The sensor type that will trigger when the time has ended (`null` for no sensor) | | `"motion"` | Integer |
| `startOnReboot` | When set to `true`, the switch will be turned ON and start the timer when Homebridge restarts | | `false` | Boolean |
| `delay` | Delay/Timer time. 0 - timer disabled | ✓ | 0 | Integer |
| `delayUnit` | Delay unit: miliseconds / seconds / minutes / hours / days | ✓ | "miliseconds" | String |
| `sensorType` | The sensor type that will trigger when the time has ended (`null` for no sensor) | | `null` | String |
| `flipSensorState` | Flips the trigger sensor state (close/open, detected/not detected) | | `false` | Boolean |
| `startOnReboot` | When set to `true`, the switch will be turned ON and start the timer when Homebridge restarts | | `false` | Boolean |
## Why do we need this Plugin?

@@ -63,4 +66,4 @@

1. Set the desired `delay` time in the config file (in milliseconds).
2. The plugin will create one switch and optional sensor (motion/contact/occupancy).
1. Set the desired `delay` time in the config file. 0 - timer disabled.
2. The plugin will create one switch and optional sensor (motion/contact/occupancy/leak).
3. Use this switch in any scene or automation.

@@ -71,3 +74,3 @@ 4. Set an automation to trigger when this switch is turned OFF or the sensor is triggered, using the Home app or another app such as the Eve app.

A sensor (motion/contact/occupancy) is created for each accessory in order to be able to cancel the timer and the attached automations.
A sensor (motion/contact/occupancy/leak) is created for each accessory in order to be able to cancel the timer and the attached automations.
How does it works? You can set the automation to be triggered from the attached "trigger" sensor instead of the switch OFF command and therefore you can turn OFF the switch and prevent the sensor from triggering or any attached automations from executing.

@@ -74,0 +77,0 @@ If you have no use of the sensor you can remove it by setting `"sensorType": null` to your config.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc