homebridge-rtl 0.0.4
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/LICENSE +21 -0
- package/MIGHTY-MULE-DRIVEWAY-ALARM-INSTRUCTIONS.md +62 -0
- package/README.md +160 -0
- package/lib/CustomCharacteristic.js +181 -0
- package/package.json +42 -0
- package/publish.sh +13 -0
- package/sample-config.json +29 -0
- package/sensor.js +437 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 rxseger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# How to add MightyMule Wireless Driveway Alarm System - FM231
|
|
2
|
+
|
|
3
|
+
Using slightly modified version of the [MightMule-FM231.conf](https://github.com/merbanan/rtl_433/blob/master/conf/MightyMule-FM231.conf) you can add this driveway alarm as a device and have it show up as a motion sensor. For more info on the fm231 and rtl_433, [see here](https://github.com/merbanan/rtl_433/issues/1407).
|
|
4
|
+
|
|
5
|
+
Note one quirk is that this package was designed for 433 motion senors that constantly communicate and this one does not so eventually it wants to show that sensor has timed out (unresponsive status in homekit) if it hasn't triggered. You can however specify the timeout in homebridge conf so I set it to 7200 minutes so it doesn't use the 2 hour default. Even if sensor shows as "unresponsive" it will still trigger immediately when the driveway alarm transmits so it really does not matter if it shows unresponsive in homekit other than aesthetics.
|
|
6
|
+
|
|
7
|
+
### Add FM231 conf to rtl_433.conf
|
|
8
|
+
Put the below modified MightMule-FM231.conf into `rtl_433.conf` and make sure that file is placed in a location that rtl_433 looks on startup. ie I used `/usr/local/etc/rtl_433/rtl_433.conf`. This will cause rtl_433 to treat it like one of the supported devices and automatically look for its transmissions on startup.
|
|
9
|
+
|
|
10
|
+
#### /usr/local/etc/rtl_433/rtl_433.conf
|
|
11
|
+
```
|
|
12
|
+
# Decoder for the Mighty Mule FM231 Driveway alarm from GTO Inc
|
|
13
|
+
# FCC Test report, including RF waveforms is here:
|
|
14
|
+
# https://fccid.io/I6HGTOFM231/Test-Report/Test-Report-1214140.pdf
|
|
15
|
+
|
|
16
|
+
# Use the Accurite and similar convention for reporting battery.
|
|
17
|
+
# The name is 'battery_ok' with values 1 (ok) and 0. (which are
|
|
18
|
+
# numerically reversed from what the FM231 reports)
|
|
19
|
+
|
|
20
|
+
# The DIP switches for setting a unique device ID are labeled 1-4
|
|
21
|
+
# from left to right, but appear in the # data stream in reverse
|
|
22
|
+
# order.
|
|
23
|
+
|
|
24
|
+
decoder {
|
|
25
|
+
name=MightyMule-FM231,
|
|
26
|
+
modulation=OOK_PWM,
|
|
27
|
+
short=650,
|
|
28
|
+
long=1200,
|
|
29
|
+
sync=3800,
|
|
30
|
+
reset=1100,
|
|
31
|
+
rows=1,
|
|
32
|
+
bits=9,
|
|
33
|
+
get=@4:{1}:battery_ok:[0:1 1:0],
|
|
34
|
+
get=@5:{4}:id,
|
|
35
|
+
get=@0:{1}:motion:[0:true 1:true],
|
|
36
|
+
unique
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The modification I made to the original mule conf was just to add `get=@0:{1}:motion:[0:true 1:true]`, because that is what homebridge-rtl built in support for motion sensor device expects and it will return `motion: true` on any triggering which is what we want.
|
|
41
|
+
|
|
42
|
+
### Homebridge conf
|
|
43
|
+
Then in homebridge, once homebridge-rtl is installed, add the following platform to your homebridge config file. `id` is the ID that results from you dip switch settings on the driveway alarm. You can get this just by running `rtl_433` if you have already setup `rtl_433.conf` and trigger the alarm. You will see the ID listed.
|
|
44
|
+
|
|
45
|
+
Restart homebridge and now homekit should have a motion sensor that will trigger when a car is detected and automatically turn off after a few min.
|
|
46
|
+
|
|
47
|
+
#### homebridg conf
|
|
48
|
+
```
|
|
49
|
+
{
|
|
50
|
+
"platform": "rtl_433",
|
|
51
|
+
"devices": [
|
|
52
|
+
{
|
|
53
|
+
"id": "8",
|
|
54
|
+
"name": "Car Motion",
|
|
55
|
+
"type": "motion",
|
|
56
|
+
"timeout": 7200
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# homebridge-rtl
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/homebridge-rtl)
|
|
4
|
+
|
|
5
|
+
Homebridge plugin to display information from 433 Mhz sensors, like the `Skylink HA-434TL motion sensor` or the `AcuRite Digital Wireless Fridge and Freezer Thermometer` temperature sensor. This plugin uses the [RTL_433](https://github.com/merbanan/rtl_433) package to listen to the sensor in-conjunction with a sdr device to receive the signals from the sensor. In my setup I use this [RTL_SDR](https://www.amazon.ca/gp/product/B00PAGS0HO/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&psc=1) to receive the radio signal from the sensor.
|
|
6
|
+
|
|
7
|
+
## Supported Sensors
|
|
8
|
+
For sensors, I'm using these
|
|
9
|
+
|
|
10
|
+
* [Fridge Temperature](https://www.amazon.ca/gp/product/B004QJVU78/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1)
|
|
11
|
+
* [Motion](https://www.amazon.ca/gp/product/B003CWGDTK/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1)
|
|
12
|
+
|
|
13
|
+
Contributor added sensors:
|
|
14
|
+
* [Mighty Mule Driveway alarm](https://www.amazon.com/Mighty-Mule-Wireless-Driveway-FM231/dp/B003765W0W) see [instructions here](MIGHTY-MULE-DRIVEWAY-ALARM-INSTRUCTIONS.md)
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
* Supported sensors include Motion, Contact, Temperature and Humidity
|
|
18
|
+
* Also shows "not responding" if the sensor stops sending data
|
|
19
|
+
* For temperature and humidity sensors, has ability to create alarms if the current value exceeds a alarm value
|
|
20
|
+
|
|
21
|
+
I have tested this on both a Mac and a RPI3
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
1. Install Homebridge using
|
|
25
|
+
`sudo npm install -g homebridge`
|
|
26
|
+
2. Install this plugin
|
|
27
|
+
`sudo npm install -g homebridge-rtl`
|
|
28
|
+
3. Install [RTL_433](https://github.com/merbanan/rtl_433) following the instructions [here](https://github.com/merbanan/rtl_433#installation-instructions)
|
|
29
|
+
4. Configure homebridge
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
* `platform`: "rtl_433"
|
|
33
|
+
* `rtl433Path`: by default this is "/usr/local/bin/"; for windows, the directory rtl433 exe is located. End this with a \.
|
|
34
|
+
* `rtl433Bin`: by default this is "rtl_433"; for windows, this is the exe.
|
|
35
|
+
* `killCommand`: by default this is "pkill"; for windows, this is taskkill /IM, however, the service may not have sufficient privileges to do this. " " for no command.
|
|
36
|
+
* `name`: "Front Porch" - Name of device for display in the Home App
|
|
37
|
+
* `id`: id number of device - To find the ID of your device, run homebridge in DEBUG mode, and it will log the message received from all rtl_433 devices. See below for examples
|
|
38
|
+
* `type`: Type of sensor device. Supported sensors are `motion`, `temperature`, `humidity`, and `contact`
|
|
39
|
+
* `alarm`: Optional, Create a fake contact sensor called name + Alarm. Value is temperature in Celsius that if exceeded will trigger contact sensor.
|
|
40
|
+
* `humidity`: Optional, For devices of type `temperature` that emits also humidity set to `true` and humidity will shows in HomeKit/Eve app in the sensor.
|
|
41
|
+
|
|
42
|
+
Example configuration:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
"platforms": [{
|
|
46
|
+
"platform": "rtl_433",
|
|
47
|
+
"devices": [
|
|
48
|
+
{
|
|
49
|
+
"id": "1e3e8",
|
|
50
|
+
"name": "Front Porch",
|
|
51
|
+
"type": "motion"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "92",
|
|
55
|
+
"name": "Outside temperature",
|
|
56
|
+
"type": "temperature"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "834551",
|
|
60
|
+
"name": "Front Door Sensor",
|
|
61
|
+
"type": "contact"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example windows configuration:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
"platforms": [{
|
|
71
|
+
"platform": "rtl_433",
|
|
72
|
+
"rtl433Path": "c:\\temp\\",
|
|
73
|
+
"rtp433Bin": "rtl_433_64bit_static.exe",
|
|
74
|
+
"killCommand": " ",
|
|
75
|
+
"devices": [
|
|
76
|
+
{
|
|
77
|
+
"id": "1e3e8",
|
|
78
|
+
"name": "Front Porch",
|
|
79
|
+
"type": "motion"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "92",
|
|
83
|
+
"name": "Outside temperature",
|
|
84
|
+
"type": "temperature"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "834551",
|
|
88
|
+
"name": "Front Door Sensor",
|
|
89
|
+
"type": "contact"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Sample log file entries from homebridge to determine sensor ID
|
|
96
|
+
|
|
97
|
+
* Motion sensor log entries
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Message {"time" : "2019-04-03 09:43:05", "model" : "Skylink HA-434TL motion sensor", "motion" : "false", "id" : "1e3e8", "raw" : "5e3e8"}
|
|
101
|
+
|
|
102
|
+
id is 1e3e8
|
|
103
|
+
|
|
104
|
+
Message {"time" : "2022-03-23 20:11:54.643434", "protocol" : 68, "model" : "Kerui-Security", "id" : 840811, "cmd" : 10, "motion" : 1, "state" : "motion" }
|
|
105
|
+
|
|
106
|
+
id is 840811
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
* Temperature sensor log entries
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
[rtl_433] FYI: Message from unknown device ID 21650
|
|
113
|
+
[rtl_433] Message {"time" : "2021-02-02 10:22:30", "model" : "Acurite 986 Sensor", "id" : 21650, "channel" : "1R", "temperature_C" : 20.556, "battery" : "OK", "status" : 0}
|
|
114
|
+
[rtl_433] FYI: Message from unknown device ID 21650
|
|
115
|
+
[rtl_433] Message {"time" : "2021-02-02 10:22:30", "model" : "Acurite 986 Sensor", "id" : 21650, "channel" : "1R", "temperature_C" : 20.556, "battery" : "OK", "status" : 0}
|
|
116
|
+
|
|
117
|
+
id is 21650
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
If the device does not transmit an ID value, will default to channel
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
Message {"time" : "2020-03-14 11:34:22", "model" : "Philips outdoor temperature sensor", "channel" : 1, "temperature_C" : 1.500, "battery" : "LOW"}
|
|
124
|
+
|
|
125
|
+
id is the channel 1
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Message {"time" : "2020-03-14 14:40:41", "model" : "Acurite tower sensor", "id" : 15424, "sensor_id" : 15424, "channel" : "A", "temperature_C" : 3.600, "humidity" : 60, "battery_low" : 0}
|
|
130
|
+
|
|
131
|
+
id is 15424
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
Message {"time" : "2022-03-23 21:28:05.748872", "protocol" : 38, "model" : "Generic-Temperature", "id" : 92, "battery_ok" : 1, "temperature_C" : 6.100 }
|
|
136
|
+
|
|
137
|
+
id is 92 the channel 1 for tiny AVIDSEN Weather station
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
Message {"time" : "2022-03-29 21:32:16.707696", "protocol" : 19, "model" : "Nexus-TH", "id" : 36, "channel" : 1, "battery_ok" : 1, "temperature_C" : 11.800, "humidity" : 77 }
|
|
142
|
+
Message {"time" : "2022-03-29 21:32:35.938421", "protocol" : 19, "model" : "Nexus-TH", "id" : 31, "channel" : 2, "battery_ok" : 1, "temperature_C" : 12.800, "humidity" : 66 }
|
|
143
|
+
Message {"time" : "2022-03-29 21:32:47.165018", "protocol" : 19, "model" : "Nexus-TH", "id" : 198, "channel" : 3, "battery_ok" : 1, "temperature_C" : 20.900, "humidity" : 45 }
|
|
144
|
+
|
|
145
|
+
id are 36, 31 and 198 (Bresser Temeo Hygro Quadro)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
* Contact Sensor log entries (Door or Window Open/Close)
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
Message {"time" : "2022-03-23 20:12:15.579712", "protocol" : 68, "model" : "Kerui-Security", "id" : 843552, "cmd" : 14, "opened" : 1, "state" : "open" }
|
|
152
|
+
Message {"time" : "2022-03-23 20:12:18.993887", "protocol" : 68, "model" : "Kerui-Security", "id" : 843552, "cmd" : 7, "opened" : 0, "state" : "close" }
|
|
153
|
+
|
|
154
|
+
id is 843552
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Credits
|
|
158
|
+
* merbanan - RTL_433 Sensor decoder
|
|
159
|
+
* simont77 - History Service
|
|
160
|
+
* matopeto - Humidity Sensor Support
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
var inherits = require('util').inherits;
|
|
2
|
+
var Service, Characteristic;
|
|
3
|
+
|
|
4
|
+
module.exports = function(homebridge) {
|
|
5
|
+
Service = homebridge.hap.Service;
|
|
6
|
+
Characteristic = homebridge.hap.Characteristic;
|
|
7
|
+
|
|
8
|
+
var CustomCharacteristic = {};
|
|
9
|
+
|
|
10
|
+
// Motion Sensor
|
|
11
|
+
// Persistence of motion indication in seconds.
|
|
12
|
+
|
|
13
|
+
CustomCharacteristic.Duration = function() {
|
|
14
|
+
Characteristic.call(this, 'Duration', CustomCharacteristic.Duration.UUID);
|
|
15
|
+
this.setProps({
|
|
16
|
+
format: Characteristic.Formats.UINT16,
|
|
17
|
+
unit: "seconds",
|
|
18
|
+
minValue: 5,
|
|
19
|
+
maxValue: 15 * 3600,
|
|
20
|
+
validValues: [
|
|
21
|
+
5, 10, 20, 30,
|
|
22
|
+
1 * 60, 2 * 60, 3 * 60, 5 * 60, 10 * 60, 20 * 60, 30 * 60,
|
|
23
|
+
1 * 3600, 2 * 3600, 3 * 3600, 5 * 3600, 10 * 3600, 12 * 3600, 15 * 3600
|
|
24
|
+
],
|
|
25
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY, Characteristic.Perms.WRITE]
|
|
26
|
+
});
|
|
27
|
+
this.value = this.getDefaultValue();
|
|
28
|
+
};
|
|
29
|
+
CustomCharacteristic.Duration.UUID = 'E863F12D-079E-48FF-8F27-9C2605A29F52';
|
|
30
|
+
inherits(CustomCharacteristic.Duration, Characteristic);
|
|
31
|
+
|
|
32
|
+
// Motion Sensor
|
|
33
|
+
// Time of last activation
|
|
34
|
+
|
|
35
|
+
CustomCharacteristic.LastActivation = function() {
|
|
36
|
+
Characteristic.call(this, 'Last Activation', CustomCharacteristic.LastActivation.UUID);
|
|
37
|
+
this.setProps({
|
|
38
|
+
format: Characteristic.Formats.UINT32,
|
|
39
|
+
unit: "seconds",
|
|
40
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
41
|
+
});
|
|
42
|
+
this.value = this.getDefaultValue();
|
|
43
|
+
};
|
|
44
|
+
CustomCharacteristic.LastActivation.UUID = 'E863F11A-079E-48FF-8F27-9C2605A29F52';
|
|
45
|
+
inherits(CustomCharacteristic.LastActivation, Characteristic);
|
|
46
|
+
|
|
47
|
+
// Motion Sensor
|
|
48
|
+
// Sensitivity of sensor
|
|
49
|
+
|
|
50
|
+
CustomCharacteristic.Sensitivity = function() {
|
|
51
|
+
Characteristic.call(this, 'Sensitivity', CustomCharacteristic.Sensitivity.UUID);
|
|
52
|
+
this.setProps({
|
|
53
|
+
format: Characteristic.Formats.UINT8,
|
|
54
|
+
unit: "seconds",
|
|
55
|
+
minValue: 0,
|
|
56
|
+
maxValue: 7,
|
|
57
|
+
validValues: [0, 4, 7],
|
|
58
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY, Characteristic.Perms.WRITE]
|
|
59
|
+
});
|
|
60
|
+
this.value = this.getDefaultValue();
|
|
61
|
+
};
|
|
62
|
+
CustomCharacteristic.Sensitivity.UUID = 'E863F120-079E-48FF-8F27-9C2605A29F52';
|
|
63
|
+
inherits(CustomCharacteristic.Sensitivity, Characteristic);
|
|
64
|
+
|
|
65
|
+
// Door
|
|
66
|
+
|
|
67
|
+
CustomCharacteristic.ResetTotal = function() {
|
|
68
|
+
Characteristic.call(this, 'Reset Total', CustomCharacteristic.ResetTotal.UUID);
|
|
69
|
+
this.setProps({
|
|
70
|
+
format: Characteristic.Formats.UINT32,
|
|
71
|
+
unit: "seconds",
|
|
72
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY, Characteristic.Perms.WRITE]
|
|
73
|
+
});
|
|
74
|
+
this.value = this.getDefaultValue();
|
|
75
|
+
};
|
|
76
|
+
CustomCharacteristic.ResetTotal.UUID = 'E863F112-079E-48FF-8F27-9C2605A29F52';
|
|
77
|
+
inherits(CustomCharacteristic.ResetTotal, Characteristic);
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
CustomCharacteristic.OpenDuration = function() {
|
|
81
|
+
Characteristic.call(this, 'Open Duration', CustomCharacteristic.OpenDuration.UUID);
|
|
82
|
+
this.setProps({
|
|
83
|
+
format: Characteristic.Formats.UINT32,
|
|
84
|
+
unit: "seconds",
|
|
85
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY, Characteristic.Perms.WRITE]
|
|
86
|
+
});
|
|
87
|
+
this.value = this.getDefaultValue();
|
|
88
|
+
};
|
|
89
|
+
CustomCharacteristic.OpenDuration.UUID = 'E863F118-079E-48FF-8F27-9C2605A29F52';
|
|
90
|
+
inherits(CustomCharacteristic.OpenDuration, Characteristic);
|
|
91
|
+
|
|
92
|
+
CustomCharacteristic.ClosedDuration = function() {
|
|
93
|
+
Characteristic.call(this, 'Closed Duration', CustomCharacteristic.ClosedDuration.UUID);
|
|
94
|
+
this.setProps({
|
|
95
|
+
format: Characteristic.Formats.UINT32,
|
|
96
|
+
unit: "seconds",
|
|
97
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY, Characteristic.Perms.WRITE]
|
|
98
|
+
});
|
|
99
|
+
this.value = this.getDefaultValue();
|
|
100
|
+
};
|
|
101
|
+
CustomCharacteristic.ClosedDuration.UUID = 'E863F119-079E-48FF-8F27-9C2605A29F52';
|
|
102
|
+
inherits(CustomCharacteristic.ClosedDuration, Characteristic);
|
|
103
|
+
|
|
104
|
+
CustomCharacteristic.TimesOpened = function() {
|
|
105
|
+
Characteristic.call(this, 'Times Opened', CustomCharacteristic.TimesOpened.UUID);
|
|
106
|
+
this.setProps({
|
|
107
|
+
format: Characteristic.Formats.UINT32,
|
|
108
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
109
|
+
});
|
|
110
|
+
this.value = this.getDefaultValue();
|
|
111
|
+
};
|
|
112
|
+
CustomCharacteristic.TimesOpened.UUID = 'E863F129-079E-48FF-8F27-9C2605A29F52';
|
|
113
|
+
inherits(CustomCharacteristic.TimesOpened, Characteristic);
|
|
114
|
+
|
|
115
|
+
CustomCharacteristic.AtmosphericPressureLevel = function() {
|
|
116
|
+
Characteristic.call(this, 'Air Pressure', CustomCharacteristic.AtmosphericPressureLevel.UUID);
|
|
117
|
+
this.setProps({
|
|
118
|
+
format: Characteristic.Formats.UINT16,
|
|
119
|
+
unit: "mbar",
|
|
120
|
+
minValue: 700,
|
|
121
|
+
maxValue: 1200,
|
|
122
|
+
minStep: 1,
|
|
123
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
124
|
+
});
|
|
125
|
+
this.value = this.getDefaultValue();
|
|
126
|
+
};
|
|
127
|
+
CustomCharacteristic.AtmosphericPressureLevel.UUID = 'E863F10F-079E-48FF-8F27-9C2605A29F52';
|
|
128
|
+
inherits(CustomCharacteristic.AtmosphericPressureLevel, Characteristic);
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// courtesy of https://github.com/robi-van-kinobi/homebridge-cubesensors
|
|
132
|
+
CustomCharacteristic.AtmosphericPressureSensor = function(displayName, subtype) {
|
|
133
|
+
Service.call(this, displayName, CustomCharacteristic.AtmosphericPressureSensor.UUID, subtype);
|
|
134
|
+
|
|
135
|
+
// Required Characteristics
|
|
136
|
+
this.addCharacteristic(CustomCharacteristic.AtmosphericPressureLevel);
|
|
137
|
+
|
|
138
|
+
// Optional Characteristics
|
|
139
|
+
this.addOptionalCharacteristic(Characteristic.StatusActive);
|
|
140
|
+
this.addOptionalCharacteristic(Characteristic.StatusFault);
|
|
141
|
+
this.addOptionalCharacteristic(Characteristic.StatusLowBattery);
|
|
142
|
+
this.addOptionalCharacteristic(Characteristic.StatusTampered);
|
|
143
|
+
this.addOptionalCharacteristic(Characteristic.Name);
|
|
144
|
+
};
|
|
145
|
+
CustomCharacteristic.AtmosphericPressureSensor.UUID = 'B77831FD-D66A-46A4-B66D-FD7EE8DFE3CE';
|
|
146
|
+
inherits(CustomCharacteristic.AtmosphericPressureSensor, Service);
|
|
147
|
+
|
|
148
|
+
CustomCharacteristic.ValvePosition = function() {
|
|
149
|
+
Characteristic.call(this, 'Valve position', 'E863F12E-079E-48FF-8F27-9C2605A29F52');
|
|
150
|
+
this.setProps({
|
|
151
|
+
format: Characteristic.Formats.UINT8,
|
|
152
|
+
unit: Characteristic.Units.PERCENTAGE,
|
|
153
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
154
|
+
});
|
|
155
|
+
this.value = this.getDefaultValue();
|
|
156
|
+
};
|
|
157
|
+
inherits(CustomCharacteristic.ValvePosition, Characteristic);
|
|
158
|
+
|
|
159
|
+
CustomCharacteristic.ProgramCommand = function() {
|
|
160
|
+
Characteristic.call(this, 'Program command', 'E863F12C-079E-48FF-8F27-9C2605A29F52');
|
|
161
|
+
this.setProps({
|
|
162
|
+
format: Characteristic.Formats.DATA,
|
|
163
|
+
perms: [Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
|
|
164
|
+
});
|
|
165
|
+
this.value = this.getDefaultValue();
|
|
166
|
+
};
|
|
167
|
+
inherits(CustomCharacteristic.ProgramCommand, Characteristic);
|
|
168
|
+
|
|
169
|
+
CustomCharacteristic.ProgramData = function() {
|
|
170
|
+
Characteristic.call(this, 'Program data', 'E863F12F-079E-48FF-8F27-9C2605A29F52');
|
|
171
|
+
this.setProps({
|
|
172
|
+
format: Characteristic.Formats.DATA,
|
|
173
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
174
|
+
});
|
|
175
|
+
this.value = this.getDefaultValue();
|
|
176
|
+
};
|
|
177
|
+
inherits(CustomCharacteristic.ProgramData, Characteristic);
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
return CustomCharacteristic;
|
|
181
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "homebridge-rtl",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "RTL_433 based sensor for Homebridge",
|
|
5
|
+
"main": "sensor.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/northernman54/homebridge-rtl.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"homebridge-plugin",
|
|
15
|
+
"rtl_433",
|
|
16
|
+
"temperature",
|
|
17
|
+
"humidity",
|
|
18
|
+
"pressure",
|
|
19
|
+
"sensor",
|
|
20
|
+
"motion"
|
|
21
|
+
],
|
|
22
|
+
"author": "northernman54",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/northernman54/homebridge-rtl/issues"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=8.0.0",
|
|
29
|
+
"homebridge": ">=0.2.0"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/northernman54/homebridge-rtl#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"debug": "^2.2.0",
|
|
34
|
+
"fakegato-history": "^0.5.6",
|
|
35
|
+
"lodash": "^4.17.20",
|
|
36
|
+
"mcuiot-logger": "0.0.12",
|
|
37
|
+
"moment": "^2.18.1"
|
|
38
|
+
},
|
|
39
|
+
"directories": {
|
|
40
|
+
"lib": "lib"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/publish.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#! /bin/sh
|
|
2
|
+
|
|
3
|
+
if npm audit; then
|
|
4
|
+
# rm *orig* *toc\.*
|
|
5
|
+
# npm run-script document
|
|
6
|
+
git add .
|
|
7
|
+
npm version patch -m "$1" --force
|
|
8
|
+
npm publish
|
|
9
|
+
git commit -m "$1"
|
|
10
|
+
git push origin master --tags
|
|
11
|
+
else
|
|
12
|
+
echo "Not publishing due to security vulnerabilites"
|
|
13
|
+
fi
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bridge": {
|
|
3
|
+
"name": "Maggie",
|
|
4
|
+
"username": "CC:22:3D:F3:CE:35",
|
|
5
|
+
"port": 51826,
|
|
6
|
+
"pin": "031-45-154"
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
"description": "HomeBridge HTTP Status Control",
|
|
10
|
+
|
|
11
|
+
"platforms": [{
|
|
12
|
+
"platform": "rtl_433",
|
|
13
|
+
"devices": [{
|
|
14
|
+
"id": "3929",
|
|
15
|
+
"name": "Freezer",
|
|
16
|
+
"type": "temperature"
|
|
17
|
+
}, {
|
|
18
|
+
"id": "1e3e8",
|
|
19
|
+
"name": "Front Porch",
|
|
20
|
+
"type": "motion"
|
|
21
|
+
}, {
|
|
22
|
+
"id": "3930",
|
|
23
|
+
"name": "Fridge",
|
|
24
|
+
"type": "temperature"
|
|
25
|
+
}]
|
|
26
|
+
}],
|
|
27
|
+
|
|
28
|
+
"accessories": []
|
|
29
|
+
}
|
package/sensor.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var debug = require('debug')('homebridge-rtl_433');
|
|
4
|
+
var Logger = require("mcuiot-logger").logger;
|
|
5
|
+
const moment = require('moment');
|
|
6
|
+
var os = require("os");
|
|
7
|
+
var _ = require('lodash');
|
|
8
|
+
var hostname = os.hostname();
|
|
9
|
+
|
|
10
|
+
let Service, Characteristic;
|
|
11
|
+
var CustomCharacteristic;
|
|
12
|
+
var FakeGatoHistoryService;
|
|
13
|
+
|
|
14
|
+
var myAccessories = [];
|
|
15
|
+
|
|
16
|
+
module.exports = (homebridge) => {
|
|
17
|
+
Service = homebridge.hap.Service;
|
|
18
|
+
Characteristic = homebridge.hap.Characteristic;
|
|
19
|
+
CustomCharacteristic = require('./lib/CustomCharacteristic.js')(homebridge);
|
|
20
|
+
FakeGatoHistoryService = require('fakegato-history')(homebridge);
|
|
21
|
+
|
|
22
|
+
homebridge.registerPlatform('homebridge-rtl', 'rtl_433', rtl433Plugin);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function rtl433Plugin(log, config, api) {
|
|
26
|
+
this.log = log;
|
|
27
|
+
this.refresh = config['refresh'] || 60; // Update every minute
|
|
28
|
+
this.options = config.options || {};
|
|
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
|
+
this.spreadsheetId = config['spreadsheetId'];
|
|
35
|
+
this.devices = config['devices'];
|
|
36
|
+
|
|
37
|
+
if (this.spreadsheetId) {
|
|
38
|
+
this.log_event_counter = 59;
|
|
39
|
+
this.logger = new Logger(this.spreadsheetId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
rtl433Plugin.prototype = {
|
|
44
|
+
accessories: function(callback) {
|
|
45
|
+
for (var i in this.devices) {
|
|
46
|
+
this.log("Adding device", i, this.devices[i].name);
|
|
47
|
+
myAccessories.push(new Rtl433Accessory(this.devices[i], this.log, i));
|
|
48
|
+
}
|
|
49
|
+
callback(myAccessories);
|
|
50
|
+
// console.log("Pre-This", this);
|
|
51
|
+
rtl433Server.call(this);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function rtl433Server() {
|
|
56
|
+
// console.log("This", this);
|
|
57
|
+
var childProcess = require('child_process');
|
|
58
|
+
var readline = require('readline');
|
|
59
|
+
var previousMessage;
|
|
60
|
+
this.log("Spawning rtl_433 " + this.killCommand + '; ' + this.rtl433Path + this.rtl433Bin);
|
|
61
|
+
// if you start rtl_433 outside homebride to get log: rtl_433 -v -F json -C si -M protocol > /tmp/rtl433.json
|
|
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
|
+
shell: true
|
|
66
|
+
});
|
|
67
|
+
readline.createInterface({
|
|
68
|
+
input: proc.stdout,
|
|
69
|
+
terminal: false
|
|
70
|
+
}).on('line', function (message) {
|
|
71
|
+
this.log("Message", message.toString());
|
|
72
|
+
debug("Message", message.toString());
|
|
73
|
+
|
|
74
|
+
if (message.toString().startsWith('{')) {
|
|
75
|
+
try {
|
|
76
|
+
var data = JSON.parse(message.toString());
|
|
77
|
+
var devices = [];
|
|
78
|
+
this.message = message;
|
|
79
|
+
if (data.id) {
|
|
80
|
+
devices = getDevices.call(this, data.id);
|
|
81
|
+
} else if (data.channel) {
|
|
82
|
+
devices = getDevices.call(this, data.channel);
|
|
83
|
+
} else {
|
|
84
|
+
this.log.error("FYI: RTL Message missing device or channel identifier.");
|
|
85
|
+
this.log("Message", this.message.toString());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!duplicateMessage(previousMessage, data)) {
|
|
89
|
+
if (devices.length > 0) {
|
|
90
|
+
previousMessage = Object.assign({}, data);
|
|
91
|
+
for (var i in devices) {
|
|
92
|
+
var device = devices[i]
|
|
93
|
+
device.updateStatus(data);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// {"time" : "2020-03-14 11:34:22", "model" : "Philips outdoor temperature sensor", "channel" : 1, "temperature_C" : 1.500, "battery" : "LOW"}
|
|
98
|
+
// {"time" : "2018-06-02 08:27:20", "model" : "Acurite 986 Sensor", "id" : 3929, "channel" : "2F", "temperature_F" : -11, "temperature_C" : -23.889, "battery" : "OK", "status" : 0}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
this.log.error("JSON Parse Error", message.toString(), err);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}.bind(this));
|
|
104
|
+
proc.on('close', function(code) {
|
|
105
|
+
this.log.error('child close code (spawn)', code);
|
|
106
|
+
setTimeout(rtl433Server.bind(this), 10 * 1000);
|
|
107
|
+
}.bind(this));
|
|
108
|
+
proc.on('disconnect', function(code) {
|
|
109
|
+
this.log.error('child disconnect code (spawn)', code);
|
|
110
|
+
}.bind(this));
|
|
111
|
+
proc.on('error', function(code) {
|
|
112
|
+
this.log.error('child error code (spawn)', code);
|
|
113
|
+
}.bind(this));
|
|
114
|
+
proc.on('exit', function(code) {
|
|
115
|
+
this.log.error('child exit code (spawn)', code);
|
|
116
|
+
}.bind(this));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function Rtl433Accessory(device, log, unit) {
|
|
120
|
+
this.id = device.id;
|
|
121
|
+
this.type = device.type;
|
|
122
|
+
this.log = log;
|
|
123
|
+
this.name = device.name;
|
|
124
|
+
this.alarm = device['alarm']
|
|
125
|
+
this.deviceTimeout = device['timeout'] || 120; // Mark as unavailable after 2 hours
|
|
126
|
+
this.humidity = device['humidity'] || false; // Add humidity data to temerature sensor
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Rtl433Accessory.prototype = {
|
|
130
|
+
updateStatus: function(data) {
|
|
131
|
+
try {
|
|
132
|
+
this.log("Updating", this.name);
|
|
133
|
+
this.lastUpdated = Date.now();
|
|
134
|
+
clearTimeout(this.timeout);
|
|
135
|
+
this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000);
|
|
136
|
+
switch (this.type) {
|
|
137
|
+
case "temperature":
|
|
138
|
+
var humidity;
|
|
139
|
+
var entry = {
|
|
140
|
+
time: moment().unix(),
|
|
141
|
+
temp: roundInt(data.temperature_C)
|
|
142
|
+
}
|
|
143
|
+
if (this.humidity && data.humidity) {
|
|
144
|
+
humidity = roundInt(data.humidity)
|
|
145
|
+
entry.humidity = humidity
|
|
146
|
+
}
|
|
147
|
+
this.loggingService.addEntry(entry);
|
|
148
|
+
|
|
149
|
+
if (this.spreadsheetId) {
|
|
150
|
+
this.log_event_counter = this.log_event_counter + 1;
|
|
151
|
+
if (this.log_event_counter > 59) {
|
|
152
|
+
this.logger.storeBME(this.name, 0, roundInt(data.temperature_C), humidity);
|
|
153
|
+
this.log_event_counter = 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this.sensorService
|
|
157
|
+
.setCharacteristic(Characteristic.CurrentTemperature, roundInt(data.temperature_C));
|
|
158
|
+
if (humidity !== undefined) {
|
|
159
|
+
this.sensorService
|
|
160
|
+
.setCharacteristic(Characteristic.CurrentRelativeHumidity, humidity)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (data.battery !== undefined || data.battery_ok != undefined) {
|
|
164
|
+
var batteryOk = data.battery === "OK" || data.battery_ok === 1
|
|
165
|
+
this.sensorService
|
|
166
|
+
.setCharacteristic(Characteristic.StatusLowBattery, batteryOk ? Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL : Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW);
|
|
167
|
+
}
|
|
168
|
+
if (this.alarm !== undefined) {
|
|
169
|
+
if (roundInt(data.temperature_C) > this.alarm) {
|
|
170
|
+
this.alarmService
|
|
171
|
+
.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
|
|
172
|
+
debug(this.name + " Temperature Alarm" + roundInt(data.temperature_C) + " > " + this.alarm);
|
|
173
|
+
} else {
|
|
174
|
+
this.alarmService
|
|
175
|
+
.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_DETECTED);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
case "humidity":
|
|
180
|
+
var entry = {
|
|
181
|
+
time: moment().unix(),
|
|
182
|
+
humidity: roundInt(data.humidity)
|
|
183
|
+
}
|
|
184
|
+
this.loggingService.addEntry(entry);
|
|
185
|
+
|
|
186
|
+
if (this.spreadsheetId) {
|
|
187
|
+
this.log_event_counter = this.log_event_counter + 1;
|
|
188
|
+
if (this.log_event_counter > 59) {
|
|
189
|
+
this.logger.storeBME(this.name, 0, (undefined), roundInt(data.humidity));
|
|
190
|
+
this.log_event_counter = 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.sensorService
|
|
195
|
+
.setCharacteristic(Characteristic.CurrentRelativeHumidity, roundInt(data.humidity))
|
|
196
|
+
|
|
197
|
+
if (data.battery !== undefined || data.battery_ok != undefined) {
|
|
198
|
+
var batteryOk = data.battery === "OK" || data.battery_ok === 1
|
|
199
|
+
this.sensorService
|
|
200
|
+
.setCharacteristic(Characteristic.StatusLowBattery, batteryOk ? Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL : Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW);
|
|
201
|
+
}
|
|
202
|
+
if (this.alarm !== undefined) {
|
|
203
|
+
if (roundInt(data.humidity) > this.alarm) {
|
|
204
|
+
this.alarmService
|
|
205
|
+
.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
|
|
206
|
+
debug(this.name + " Humidity Alarm" + roundInt(data.humidity) + " > " + this.alarm);
|
|
207
|
+
} else {
|
|
208
|
+
this.alarmService
|
|
209
|
+
.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_DETECTED);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case "motion":
|
|
214
|
+
// {"time" : "2018-09-30 19:20:26", "model" : "Skylink HA-434TL motion sensor", "motion" : "true", "id" : "1e3e8", "raw" : "be3e8"}
|
|
215
|
+
// {"time" : "2022-03-17 21:58:46.319049", "protocol" : 68, "model" : "Kerui-Security", "id" : 840811, "cmd" : 10, "motion" : 1, "state" : "motion" }
|
|
216
|
+
// debug("update motion this--->",this);
|
|
217
|
+
|
|
218
|
+
var value = (data.motion === "true" || data.motion === 1 ? true : false ) ;
|
|
219
|
+
if (this.sensorService.getCharacteristic(Characteristic.MotionDetected).value !== value) {
|
|
220
|
+
this.sensorService.getCharacteristic(CustomCharacteristic.LastActivation)
|
|
221
|
+
.updateValue(moment().unix() - this.loggingService.getInitialTime());
|
|
222
|
+
}
|
|
223
|
+
this.sensorService.getCharacteristic(Characteristic.MotionDetected)
|
|
224
|
+
.updateValue(value);
|
|
225
|
+
this.loggingService.addEntry({
|
|
226
|
+
time: moment().unix(),
|
|
227
|
+
status: value
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
if (value) {
|
|
231
|
+
clearTimeout(this.motionTimeout);
|
|
232
|
+
this.motionTimeout = setTimeout(function() {
|
|
233
|
+
var value = false;
|
|
234
|
+
if (this.sensorService.getCharacteristic(Characteristic.MotionDetected).value !== value) {
|
|
235
|
+
this.sensorService.getCharacteristic(CustomCharacteristic.LastActivation)
|
|
236
|
+
.updateValue(moment().unix() - this.loggingService.getInitialTime());
|
|
237
|
+
}
|
|
238
|
+
this.sensorService.getCharacteristic(Characteristic.MotionDetected)
|
|
239
|
+
.updateValue(value);
|
|
240
|
+
this.loggingService.addEntry({
|
|
241
|
+
time: moment().unix(),
|
|
242
|
+
status: value
|
|
243
|
+
});
|
|
244
|
+
}.bind(this), 2 * 60 * 1000);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
break;
|
|
248
|
+
case "contact":
|
|
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
|
+
// debug("update door this--->",this);
|
|
252
|
+
// console.log("update door this--->",this);
|
|
253
|
+
|
|
254
|
+
this.sensorService
|
|
255
|
+
.setCharacteristic(Characteristic.ContactSensorState, ( data.opened === 1 ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED ));
|
|
256
|
+
|
|
257
|
+
//this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000);
|
|
258
|
+
clearTimeout(this.timeout);
|
|
259
|
+
|
|
260
|
+
if (data.battery !== undefined || data.battery_ok != undefined) {
|
|
261
|
+
this.sensorService
|
|
262
|
+
.setCharacteristic(Characteristic.StatusLowBattery, (data.battery === "OK" || data.battery_ok === 1 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL : Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW));
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
default:
|
|
267
|
+
this.log.error("No events defined for sensor type %s", this.type);
|
|
268
|
+
}
|
|
269
|
+
} catch (err) {
|
|
270
|
+
this.log.error("Error", err);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
getServices: function() {
|
|
275
|
+
this.log("getServices", this.name);
|
|
276
|
+
// Information Service
|
|
277
|
+
var informationService = new Service.AccessoryInformation();
|
|
278
|
+
|
|
279
|
+
informationService
|
|
280
|
+
.setCharacteristic(Characteristic.Manufacturer, "homebridge-rtl_433")
|
|
281
|
+
.setCharacteristic(Characteristic.SerialNumber, hostname + "-" + this.name)
|
|
282
|
+
.setCharacteristic(Characteristic.FirmwareRevision, require('./package.json').version);
|
|
283
|
+
// Thermostat Service
|
|
284
|
+
|
|
285
|
+
switch (this.type) {
|
|
286
|
+
case "temperature":
|
|
287
|
+
this.sensorService = new Service.TemperatureSensor(this.name);
|
|
288
|
+
|
|
289
|
+
this.sensorService
|
|
290
|
+
.getCharacteristic(Characteristic.CurrentTemperature)
|
|
291
|
+
.setProps({
|
|
292
|
+
minValue: -100,
|
|
293
|
+
maxValue: 100
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
this.timeoutCharacteristic = Characteristic.CurrentTemperature;
|
|
297
|
+
this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
|
|
298
|
+
|
|
299
|
+
this.sensorService.log = this.log;
|
|
300
|
+
this.loggingService = new FakeGatoHistoryService("weather", this.sensorService, {
|
|
301
|
+
storage: this.storage,
|
|
302
|
+
minutes: this.refresh * 10 / 60,
|
|
303
|
+
disableRepeatLastData: true
|
|
304
|
+
});
|
|
305
|
+
if (this.alarm !== undefined) {
|
|
306
|
+
this.alarmService = new Service.ContactSensor(this.name + " Alarm");
|
|
307
|
+
informationService
|
|
308
|
+
.setCharacteristic(Characteristic.Model, "Temperature Sensor with Alarm @ " + this.alarm);
|
|
309
|
+
} else {
|
|
310
|
+
informationService
|
|
311
|
+
.setCharacteristic(Characteristic.Model, "Temperature Sensor");
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case "humidity":
|
|
315
|
+
this.sensorService = new Service.HumiditySensor(this.name);
|
|
316
|
+
|
|
317
|
+
this.sensorService
|
|
318
|
+
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
319
|
+
.setProps({
|
|
320
|
+
minValue: 0,
|
|
321
|
+
maxValue: 100
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
this.timeoutCharacteristic = Characteristic.CurrentRelativeHumidity;
|
|
325
|
+
this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
|
|
326
|
+
|
|
327
|
+
this.sensorService.log = this.log;
|
|
328
|
+
this.loggingService = new FakeGatoHistoryService("weather", this.sensorService, {
|
|
329
|
+
storage: this.storage,
|
|
330
|
+
minutes: this.refresh * 10 / 60,
|
|
331
|
+
disableRepeatLastData: true
|
|
332
|
+
});
|
|
333
|
+
if (this.alarm !== undefined) {
|
|
334
|
+
this.alarmService = new Service.ContactSensor(this.name + " Alarm");
|
|
335
|
+
informationService
|
|
336
|
+
.setCharacteristic(Characteristic.Model, "Humidity Sensor with Alarm @ " + this.alarm);
|
|
337
|
+
} else {
|
|
338
|
+
informationService
|
|
339
|
+
.setCharacteristic(Characteristic.Model, "Humidity Sensor");
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
case "motion":
|
|
343
|
+
this.sensorService = new Service.MotionSensor(this.name);
|
|
344
|
+
|
|
345
|
+
this.sensorService.addCharacteristic(CustomCharacteristic.LastActivation);
|
|
346
|
+
|
|
347
|
+
this.timeoutCharacteristic = Characteristic.MotionDetected;
|
|
348
|
+
this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
|
|
349
|
+
|
|
350
|
+
this.sensorService.log = this.log;
|
|
351
|
+
this.loggingService = new FakeGatoHistoryService("motion", this.sensorService, {
|
|
352
|
+
storage: this.storage,
|
|
353
|
+
minutes: this.refresh * 10 / 60
|
|
354
|
+
});
|
|
355
|
+
informationService
|
|
356
|
+
.setCharacteristic(Characteristic.Model, "Motion Sensor");
|
|
357
|
+
break;
|
|
358
|
+
case "contact":
|
|
359
|
+
// debug("get door this--->",this);
|
|
360
|
+
// console.log("get door this--->",this);
|
|
361
|
+
|
|
362
|
+
this.sensorService = new Service.ContactSensor(this.name);
|
|
363
|
+
this.sensorService.addCharacteristic(CustomCharacteristic.LastActivation);
|
|
364
|
+
|
|
365
|
+
//this.timeoutCharacteristic = Characteristic.ContactSensorState;
|
|
366
|
+
//this.timeout = setTimeout(deviceTimeout.bind(this), this.deviceTimeout * 60 * 1000); // 5 minutes
|
|
367
|
+
|
|
368
|
+
this.sensorService.log = this.log;
|
|
369
|
+
informationService
|
|
370
|
+
.setCharacteristic(Characteristic.Model, "Contact Sensor");
|
|
371
|
+
break;
|
|
372
|
+
|
|
373
|
+
default:
|
|
374
|
+
this.log.error("No events defined for sensor type %s", this.type);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (this.alarm !== undefined) {
|
|
378
|
+
return [informationService, this.sensorService, this.alarmService, this.loggingService];
|
|
379
|
+
} else {
|
|
380
|
+
return [informationService, this.sensorService, this.loggingService];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
function deviceTimeout() {
|
|
386
|
+
this.log("Timeout", this.name);
|
|
387
|
+
|
|
388
|
+
if (this.sensorService !== undefined && this.timeoutCharacteristic !== undefined )
|
|
389
|
+
this.sensorService
|
|
390
|
+
.getCharacteristic(this.timeoutCharacteristic).updateValue(new Error("No response"));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function roundInt(string) {
|
|
394
|
+
return Math.round(parseFloat(string) * 10) / 10;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function getDevices(unit) {
|
|
398
|
+
var devices = [];
|
|
399
|
+
for (var i in myAccessories) {
|
|
400
|
+
// == is correct test, Acurite uses a numeric value
|
|
401
|
+
if (myAccessories[i].id == unit) {
|
|
402
|
+
devices.push(myAccessories[i]);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (devices.length === 0) {
|
|
406
|
+
this.log.error("FYI: Message from unknown device ID", unit);
|
|
407
|
+
this.log("Message", this.message.toString());
|
|
408
|
+
}
|
|
409
|
+
return devices;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function seconds(dateTime) {
|
|
413
|
+
// "2018-10-01 20:52:33"
|
|
414
|
+
var hms = dateTime.split(" ");
|
|
415
|
+
// debug("TIME", hms[1]);
|
|
416
|
+
var tt = hms[1].split(":");
|
|
417
|
+
var sec = tt[0] * 3600 + tt[1] * 60 + tt[2] * 1;
|
|
418
|
+
return (sec);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function duplicateMessage(last, current) {
|
|
422
|
+
if (last) {
|
|
423
|
+
// debug("Last %s, Current %s", JSON.stringify(last), JSON.stringify(current));
|
|
424
|
+
if ((seconds(current.time) - seconds(last.time)) < 2) {
|
|
425
|
+
var tCurrent = Object.assign({}, current);
|
|
426
|
+
var tLast = Object.assign({}, last);
|
|
427
|
+
delete tCurrent.time;
|
|
428
|
+
delete tLast.time;
|
|
429
|
+
// debug("LAST %s, CURRENT %s, isEqual %s", JSON.stringify(tLast), JSON.stringify(tCurrent),_.isEqual(tLast, tCurrent));
|
|
430
|
+
if (_.isEqual(tLast, tCurrent)) {
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|