homebridge-rtl 0.0.29 → 0.0.30

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/sensor.js +37 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-rtl",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "RTL_433 based sensor for Homebridge",
5
5
  "main": "sensor.js",
6
6
  "scripts": {
package/sensor.js CHANGED
@@ -55,9 +55,11 @@ function rtl433Server() {
55
55
  var readline = require('readline');
56
56
  var previousMessage;
57
57
  this.log("Spawning rtl_433");
58
+ // if you start rtl_433 outside homebride to get log: rtl_433 -v -F json -C si -M protocol > /tmp/rtl433.json
59
+ //var proc = childProcess.spawn('/usr/bin/truncate -s 0 /tmp/rtl433.json;/usr/bin/tail', ['-F','/tmp/rtl433.json'], {
58
60
  var proc = childProcess.spawn('pkill rtl_433;/usr/local/bin/rtl_433', ['-q', '-F', 'json', '-C', 'si'], {
59
61
  shell: true
60
- });
62
+ });
61
63
  readline.createInterface({
62
64
  input: proc.stdout,
63
65
  terminal: false
@@ -205,8 +207,10 @@ Rtl433Accessory.prototype = {
205
207
  break;
206
208
  case "motion":
207
209
  // {"time" : "2018-09-30 19:20:26", "model" : "Skylink HA-434TL motion sensor", "motion" : "true", "id" : "1e3e8", "raw" : "be3e8"}
208
- // debug("this--->",this);
209
- var value = (data.motion === "true");
210
+ // {"time" : "2022-03-17 21:58:46.319049", "protocol" : 68, "model" : "Kerui-Security", "id" : 840811, "cmd" : 10, "motion" : 1, "state" : "motion" }
211
+ // debug("update motion this--->",this);
212
+
213
+ var value = (data.motion === "true" || data.motion === 1 ? true : false ) ;
210
214
  if (this.sensorService.getCharacteristic(Characteristic.MotionDetected).value !== value) {
211
215
  this.sensorService.getCharacteristic(CustomCharacteristic.LastActivation)
212
216
  .updateValue(moment().unix() - this.loggingService.getInitialTime());
@@ -236,6 +240,21 @@ Rtl433Accessory.prototype = {
236
240
  }
237
241
 
238
242
  break;
243
+ case "contact":
244
+ // {"time" : "2022-03-17 23:04:08.430623", "protocol" : 68, "model" : "Kerui-Security", "id" : 297536, "cmd" : 14, "opened" : 1, "state" : "open" }
245
+ // {"time" : "2022-03-17 23:04:19.447761", "protocol" : 68, "model" : "Kerui-Security", "id" : 297536, "cmd" : 7, "opened" : 0, "state" : "close" }
246
+ // debug("update door this--->",this);
247
+ // console.log("update door this--->",this);
248
+
249
+ this.sensorService
250
+ .setCharacteristic(Characteristic.ContactSensorState, ( data.opened === 1 ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED ));
251
+
252
+ if (data.battery !== undefined || data.battery_ok != undefined) {
253
+ this.sensorService
254
+ .setCharacteristic(Characteristic.StatusLowBattery, (data.battery === "OK" || data.battery_ok === 1 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL : Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW));
255
+ }
256
+ break;
257
+
239
258
  default:
240
259
  this.log.error("No events defined for sensor type %s", this.type);
241
260
  }
@@ -326,6 +345,21 @@ Rtl433Accessory.prototype = {
326
345
  informationService
327
346
  .setCharacteristic(Characteristic.Model, "Motion Sensor");
328
347
  break;
348
+ case "contact":
349
+ // debug("get door this--->",this);
350
+ // console.log("get door this--->",this);
351
+
352
+ this.sensorService = new Service.ContactSensor(this.name);
353
+ this.sensorService.addCharacteristic(CustomCharacteristic.LastActivation);
354
+
355
+ this.timeoutCharacteristic = Characteristic.ContactSensorState;
356
+ this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
357
+
358
+ this.sensorService.log = this.log;
359
+ informationService
360
+ .setCharacteristic(Characteristic.Model, "Contact Sensor");
361
+ break;
362
+
329
363
  default:
330
364
  this.log.error("No events defined for sensor type %s", this.type);
331
365
  }