homebridge-rozcom-door 1.0.0

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/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # homebridge-rozcom-door
2
+
3
+ Homebridge plugin exposing a Rozcom Smart Intercom building entrance door as a HomeKit Lock accessory, opened via MQTT.
4
+
5
+ ## Configuration
6
+
7
+ Add to your Homebridge config.json accessories array:
8
+
9
+ accessory: RozcomDoor
10
+ name: Front Door
11
+ mqttHost: your-broker-ip
12
+ mqttPort: 1883
13
+ topic: Intercom/BUILDING_ID/startcall
14
+ payload: openDoor1:CODE
15
+
16
+ Find your broker, topic and payload values by capturing the Rozcom app's MQTT traffic (e.g. with mitmproxy in transparent mode).
@@ -0,0 +1,38 @@
1
+ {
2
+ "pluginAlias": "RozcomDoor",
3
+ "pluginType": "accessory",
4
+ "singular": false,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "default": "Front Door",
12
+ "required": true
13
+ },
14
+ "mqttHost": {
15
+ "title": "MQTT Broker Host",
16
+ "type": "string",
17
+ "default": "62.219.14.161",
18
+ "required": true
19
+ },
20
+ "mqttPort": {
21
+ "title": "MQTT Broker Port",
22
+ "type": "integer",
23
+ "default": 1883,
24
+ "required": true
25
+ },
26
+ "topic": {
27
+ "title": "MQTT Topic",
28
+ "type": "string",
29
+ "required": true
30
+ },
31
+ "payload": {
32
+ "title": "MQTT Payload",
33
+ "type": "string",
34
+ "required": true
35
+ }
36
+ }
37
+ }
38
+ }
package/index.js ADDED
@@ -0,0 +1,60 @@
1
+ const mqtt = require('mqtt');
2
+
3
+ module.exports = (api) => {
4
+ api.registerAccessory('RozcomDoor', RozcomDoorAccessory);
5
+ };
6
+
7
+ class RozcomDoorAccessory {
8
+ constructor(log, config, api) {
9
+ this.log = log;
10
+ this.name = config.name || 'Front Door';
11
+ this.mqttHost = config.mqttHost || '62.219.14.161';
12
+ this.mqttPort = config.mqttPort || 1883;
13
+ this.topic = config.topic;
14
+ this.payload = config.payload;
15
+
16
+ this.Service = api.hap.Service;
17
+ this.Characteristic = api.hap.Characteristic;
18
+
19
+ this.lockService = new this.Service.LockMechanism(this.name);
20
+
21
+ this.lockService.getCharacteristic(this.Characteristic.LockCurrentState)
22
+ .onGet(() => this.Characteristic.LockCurrentState.SECURED);
23
+
24
+ this.lockService.getCharacteristic(this.Characteristic.LockTargetState)
25
+ .onSet(this.setLockTargetState.bind(this))
26
+ .onGet(() => this.Characteristic.LockTargetState.SECURED);
27
+ }
28
+
29
+ async setLockTargetState(value) {
30
+ if (value !== this.Characteristic.LockTargetState.UNSECURED) return;
31
+
32
+ const client = mqtt.connect(`mqtt://${this.mqttHost}:${this.mqttPort}`, {
33
+ clientId: 'CocoaMQTT-' + Math.floor(Math.random() * 100000),
34
+ });
35
+
36
+ client.on('connect', () => {
37
+ this.log('Connected to MQTT broker, publishing door open command');
38
+ client.publish(this.topic, this.payload, {}, (err) => {
39
+ if (err) this.log.error('Publish failed:', err);
40
+ else this.log('Door open command sent');
41
+ client.end();
42
+ });
43
+ });
44
+
45
+ client.on('error', (err) => {
46
+ this.log.error('MQTT connection error:', err);
47
+ client.end();
48
+ });
49
+
50
+ this.lockService.updateCharacteristic(this.Characteristic.LockCurrentState, this.Characteristic.LockCurrentState.UNSECURED);
51
+ setTimeout(() => {
52
+ this.lockService.updateCharacteristic(this.Characteristic.LockCurrentState, this.Characteristic.LockCurrentState.SECURED);
53
+ this.lockService.updateCharacteristic(this.Characteristic.LockTargetState, this.Characteristic.LockTargetState.SECURED);
54
+ }, 2000);
55
+ }
56
+
57
+ getServices() {
58
+ return [this.lockService];
59
+ }
60
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "homebridge-rozcom-door",
3
+ "version": "1.0.0",
4
+ "description": "Homebridge plugin to open a Rozcom Smart Intercom building entrance door via MQTT",
5
+ "main": "index.js",
6
+ "keywords": ["homebridge-plugin", "rozcom", "intercom", "mqtt"],
7
+ "engines": {
8
+ "homebridge": ">=1.0.0",
9
+ "node": ">=14.0.0"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/orenasher/homebridge-rozcom-door.git"
14
+ },
15
+ "author": "Oren Asher",
16
+ "license": "ISC",
17
+ "dependencies": {
18
+ "mqtt": "^5.0.0"
19
+ }
20
+ }