homebridge-rtl 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/sensor.js +37 -37
package/package.json
CHANGED
package/sensor.js
CHANGED
|
@@ -26,11 +26,11 @@ function rtl433Plugin(log, config, api) {
|
|
|
26
26
|
this.log = log;
|
|
27
27
|
this.refresh = config['refresh'] || 60; // Update every minute
|
|
28
28
|
this.options = config.options || {};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
this.storage = config['storage'] || "fs";
|
|
30
|
+
//8/28/2022 JDR added this for Windows.
|
|
31
|
+
this.rtl433Path = config['rtl433Path'] || "/usr/local/bin/";
|
|
32
|
+
this.rtl433Bin = config['rtl433Bin'] || "rtl_433";
|
|
33
|
+
this.killCommand = config['killCommand'] || ("pkill " + this.rtl433Bin);// for linux/mac windows: taskkill /im "rtl_433_64bit_static.exe"
|
|
34
34
|
this.spreadsheetId = config['spreadsheetId'];
|
|
35
35
|
this.devices = config['devices'];
|
|
36
36
|
|
|
@@ -41,7 +41,7 @@ function rtl433Plugin(log, config, api) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
rtl433Plugin.prototype = {
|
|
44
|
-
accessories: function(callback) {
|
|
44
|
+
accessories: function (callback) {
|
|
45
45
|
for (var i in this.devices) {
|
|
46
46
|
this.log("Adding device", i, this.devices[i].name);
|
|
47
47
|
myAccessories.push(new Rtl433Accessory(this.devices[i], this.log, i));
|
|
@@ -57,18 +57,18 @@ function rtl433Server() {
|
|
|
57
57
|
var childProcess = require('child_process');
|
|
58
58
|
var readline = require('readline');
|
|
59
59
|
var previousMessage;
|
|
60
|
-
|
|
60
|
+
this.log("Spawning rtl_433 " + this.killCommand + '; ' + this.rtl433Path + this.rtl433Bin);
|
|
61
61
|
// if you start rtl_433 outside homebride to get log: rtl_433 -v -F json -C si -M protocol > /tmp/rtl433.json
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
//var proc = childProcess.spawn('/usr/bin/truncate -s 0 /tmp/rtl433.json;/usr/bin/tail', ['-F','/tmp/rtl433.json'], {
|
|
63
|
+
////8/28/2022 JDR added this for Windows. fixed command line arguments. They weren't working for Windows, but should still work for others.
|
|
64
|
+
var proc = childProcess.spawn(this.killCommand + '; ' + this.rtl433Path + this.rtl433Bin, ['-d 0', '-F json', '-C si'], {
|
|
65
65
|
shell: true
|
|
66
|
-
|
|
66
|
+
});
|
|
67
67
|
readline.createInterface({
|
|
68
68
|
input: proc.stdout,
|
|
69
69
|
terminal: false
|
|
70
70
|
}).on('line', function (message) {
|
|
71
|
-
|
|
71
|
+
this.log("Message", message.toString());
|
|
72
72
|
debug("Message", message.toString());
|
|
73
73
|
|
|
74
74
|
if (message.toString().startsWith('{')) {
|
|
@@ -101,17 +101,17 @@ function rtl433Server() {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}.bind(this));
|
|
104
|
-
proc.on('close', function(code) {
|
|
104
|
+
proc.on('close', function (code) {
|
|
105
105
|
this.log.error('child close code (spawn)', code);
|
|
106
106
|
setTimeout(rtl433Server.bind(this), 10 * 1000);
|
|
107
107
|
}.bind(this));
|
|
108
|
-
proc.on('disconnect', function(code) {
|
|
108
|
+
proc.on('disconnect', function (code) {
|
|
109
109
|
this.log.error('child disconnect code (spawn)', code);
|
|
110
110
|
}.bind(this));
|
|
111
|
-
proc.on('error', function(code) {
|
|
111
|
+
proc.on('error', function (code) {
|
|
112
112
|
this.log.error('child error code (spawn)', code);
|
|
113
113
|
}.bind(this));
|
|
114
|
-
proc.on('exit', function(code) {
|
|
114
|
+
proc.on('exit', function (code) {
|
|
115
115
|
this.log.error('child exit code (spawn)', code);
|
|
116
116
|
}.bind(this));
|
|
117
117
|
}
|
|
@@ -127,7 +127,7 @@ function Rtl433Accessory(device, log, unit) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
Rtl433Accessory.prototype = {
|
|
130
|
-
updateStatus: function(data) {
|
|
130
|
+
updateStatus: function (data) {
|
|
131
131
|
try {
|
|
132
132
|
this.log("Updating", this.name);
|
|
133
133
|
this.lastUpdated = Date.now();
|
|
@@ -212,10 +212,10 @@ Rtl433Accessory.prototype = {
|
|
|
212
212
|
break;
|
|
213
213
|
case "motion":
|
|
214
214
|
// {"time" : "2018-09-30 19:20:26", "model" : "Skylink HA-434TL motion sensor", "motion" : "true", "id" : "1e3e8", "raw" : "be3e8"}
|
|
215
|
-
|
|
215
|
+
// {"time" : "2022-03-17 21:58:46.319049", "protocol" : 68, "model" : "Kerui-Security", "id" : 840811, "cmd" : 10, "motion" : 1, "state" : "motion" }
|
|
216
216
|
// debug("update motion this--->",this);
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
var value = (data.motion === "true" || data.motion === 1 ? true : false);
|
|
219
219
|
if (this.sensorService.getCharacteristic(Characteristic.MotionDetected).value !== value) {
|
|
220
220
|
this.sensorService.getCharacteristic(CustomCharacteristic.LastActivation)
|
|
221
221
|
.updateValue(moment().unix() - this.loggingService.getInitialTime());
|
|
@@ -229,7 +229,7 @@ Rtl433Accessory.prototype = {
|
|
|
229
229
|
|
|
230
230
|
if (value) {
|
|
231
231
|
clearTimeout(this.motionTimeout);
|
|
232
|
-
this.motionTimeout = setTimeout(function() {
|
|
232
|
+
this.motionTimeout = setTimeout(function () {
|
|
233
233
|
var value = false;
|
|
234
234
|
if (this.sensorService.getCharacteristic(Characteristic.MotionDetected).value !== value) {
|
|
235
235
|
this.sensorService.getCharacteristic(CustomCharacteristic.LastActivation)
|
|
@@ -246,22 +246,22 @@ Rtl433Accessory.prototype = {
|
|
|
246
246
|
|
|
247
247
|
break;
|
|
248
248
|
case "contact":
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
// {"time" : "2022-03-17 23:04:08.430623", "protocol" : 68, "model" : "Kerui-Security", "id" : 297536, "cmd" : 14, "opened" : 1, "state" : "open" }
|
|
250
|
+
// {"time" : "2022-03-17 23:04:19.447761", "protocol" : 68, "model" : "Kerui-Security", "id" : 297536, "cmd" : 7, "opened" : 0, "state" : "close" }
|
|
251
251
|
// debug("update door this--->",this);
|
|
252
252
|
// console.log("update door this--->",this);
|
|
253
253
|
|
|
254
254
|
this.sensorService
|
|
255
|
-
|
|
255
|
+
.setCharacteristic(Characteristic.ContactSensorState, (data.opened === 1 ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED));
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
//this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000);
|
|
258
|
+
clearTimeout(this.timeout);
|
|
259
259
|
|
|
260
260
|
if (data.battery !== undefined || data.battery_ok != undefined) {
|
|
261
261
|
this.sensorService
|
|
262
|
-
|
|
262
|
+
.setCharacteristic(Characteristic.StatusLowBattery, (data.battery === "OK" || data.battery_ok === 1 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL : Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW));
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
break;
|
|
265
265
|
|
|
266
266
|
default:
|
|
267
267
|
this.log.error("No events defined for sensor type %s", this.type);
|
|
@@ -271,7 +271,7 @@ Rtl433Accessory.prototype = {
|
|
|
271
271
|
}
|
|
272
272
|
},
|
|
273
273
|
|
|
274
|
-
getServices: function() {
|
|
274
|
+
getServices: function () {
|
|
275
275
|
this.log("getServices", this.name);
|
|
276
276
|
// Information Service
|
|
277
277
|
var informationService = new Service.AccessoryInformation();
|
|
@@ -356,17 +356,17 @@ Rtl433Accessory.prototype = {
|
|
|
356
356
|
.setCharacteristic(Characteristic.Model, "Motion Sensor");
|
|
357
357
|
break;
|
|
358
358
|
case "contact":
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
// debug("get door this--->",this);
|
|
360
|
+
// console.log("get door this--->",this);
|
|
361
361
|
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
this.sensorService = new Service.ContactSensor(this.name);
|
|
363
|
+
this.sensorService.addCharacteristic(CustomCharacteristic.LastActivation);
|
|
364
364
|
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
//this.timeoutCharacteristic = Characteristic.ContactSensorState;
|
|
366
|
+
//this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
|
|
367
367
|
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
this.sensorService.log = this.log;
|
|
369
|
+
informationService
|
|
370
370
|
.setCharacteristic(Characteristic.Model, "Contact Sensor");
|
|
371
371
|
break;
|
|
372
372
|
|
|
@@ -385,7 +385,7 @@ Rtl433Accessory.prototype = {
|
|
|
385
385
|
function deviceTimeout() {
|
|
386
386
|
this.log("Timeout", this.name);
|
|
387
387
|
|
|
388
|
-
if (this.sensorService !== undefined && this.timeoutCharacteristic !== undefined
|
|
388
|
+
if (this.sensorService !== undefined && this.timeoutCharacteristic !== undefined)
|
|
389
389
|
this.sensorService
|
|
390
390
|
.getCharacteristic(this.timeoutCharacteristic).updateValue(new Error("No response"));
|
|
391
391
|
}
|