homebridge-garagedooropenercloud 1.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Tom Rodrigues & Andreas Hähnel
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.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # homebridge-garagedooropenercloud
2
+
3
+ [![npm](https://img.shields.io/npm/v/homebridge-garagedooropenercloud.svg)](https://www.npmjs.com/package/homebridge-garagedooropenercloud)
4
+ [![GitHub stars](https://img.shields.io/github/stars/torresyago/homebridge-garagedooropenercloud.svg)](https://github.com/torresyago/homebridge-garagedooropenercloud)
5
+
6
+ **Homebridge plugin para abrir/cerrar garaje usando Shelly Cloud API** 🚪☁️
7
+
8
+ ## Descripción
9
+
10
+ Fork mejorado de [jmaferreira/homebridge-garage-door-shelly1](https://github.com/jmaferreira/homebridge-garage-door-shelly1)
11
+
12
+ **Novedades:**
13
+ - ✅ Control remoto vía Shelly Cloud (**sin IP local**)
14
+ - ✅ Polling de estado real vía Cloud API
15
+ - ✅ Sensor de puerta integrado (reed switch)
16
+ - ✅ Compatible Homebridge Config UI X
17
+
18
+ ## 🔧 Instalación
19
+
20
+ npm install -g torresyago/homebridge-garagedooropenercloud
21
+
22
+ text
23
+
24
+ ## ⚙️ Configuración
25
+
26
+ {
27
+ "accessory": "GarageDoorOpener",
28
+ "name": "Garage Door",
29
+ "plugin": "homebridge-garagedooropenercloud",
30
+ "deviceId": "441793a44db8",
31
+ "authKey": "MTAzNDxxxxx",
32
+ "channel": "0",
33
+ "openTime": 20,
34
+ "closeTime": 20,
35
+ "polling": true,
36
+ "pollInterval": 30,
37
+ "debug": true
38
+ }
39
+
40
+ text
41
+
42
+ ### 📱 Credenciales Shelly Cloud
43
+
44
+ 1. **App Shelly** → Dispositivo → **Settings** → **Cloud** → **Device ID**
45
+ 2. **App Shelly** → **Perfil** → **Auth Key**
46
+
47
+ ## 📋 Opciones completas
48
+
49
+ | Parámetro | Descripción | Por defecto |
50
+ |-----------|-------------|-------------|
51
+ | `deviceId` | **ID dispositivo** | **Obligatorio** |
52
+ | `authKey` | **Auth Key** | **Obligatorio** |
53
+ | `channel` | Canal relay | `0` |
54
+ | `openTime` | Segundos apertura | `10` |
55
+ | `closeTime` | Segundos cierre | `10` |
56
+ | `polling` | Polling activo | `false` |
57
+ | `pollInterval` | Segundos polling | `30` |
58
+ | `debug` | Logs detallados | `false` |
59
+
60
+ ## 🔌 Cableado Shelly 1PM
61
+
62
+ Pulsador garaje:
63
+ ├── L → Fase pulsador
64
+ ├── N → Neutro
65
+ └── O → Pulsador (Relay)
66
+
67
+ Sensor reed (SW + L):
68
+ ├── SW → Terminal reed
69
+ └── L → Terminal reed
70
+
71
+ text
72
+
73
+ ## 🎯 Funcionamiento
74
+
75
+ Abrir/Cerrar → POST /relay/control?turn=on
76
+ Estado → POST /device/status → input:0.state
77
+ false → 🚪 ABIERTA
78
+ true → 🚪 CERRADA
79
+
80
+ text
81
+
82
+ ## 🏠 Estados HomeKit
83
+
84
+ | Estado HomeKit | Valor | Sensor |
85
+ |----------------|-------|--------|
86
+ | **Abierta** | `0` | `false` |
87
+ | **Cerrada** | `1` | `true` |
88
+ | **Abriendo** | `2` | Simulado |
89
+ | **Cerrando** | `3` | Simulado |
90
+
91
+ ## 👨‍💻 Autor
92
+
93
+ **torresyago** - [GitHub](https://github.com/torresyago)
94
+
95
+ **Basado en:**
96
+ - [jmaferreira/homebridge-garage-door-shelly1](https://github.com/jmaferreira/homebridge-garage-door-shelly1)
97
+ - [andreaseu/homebridge-garage-remote-http](https://github.com/andreaseu/homebridge-garage-remote-http)
98
+
99
+ ## 📄 Licencia
100
+
101
+ MIT License
@@ -0,0 +1,18 @@
1
+ {
2
+ "accessory": "GarageDoorOpener",
3
+ "name": "Garage Door",
4
+ "plugin": "homebridge-garagedooropenercloud",
5
+ "cloudBaseURL": "https://shelly-38-eu.shelly.cloud/device/relay/control",
6
+ "statusCloudURL": "https://shelly-38-eu.shelly.cloud/device/status",
7
+ "deviceId": "YOUR_DEVICE_ID",
8
+ "authKey": "YOUR_AUTH_KEY",
9
+ "channel": "0",
10
+ "statusKey": "$.data.device_status.input:0.state",
11
+ "statusValueOpen": "false",
12
+ "statusValueClosed": "true",
13
+ "openTime": 20,
14
+ "closeTime": 20,
15
+ "polling": true,
16
+ "pollInterval": 30,
17
+ "debug": true
18
+ }
@@ -0,0 +1,112 @@
1
+ {
2
+ "pluginAlias": "GarageDoorOpenerCloud",
3
+ "pluginType": "accessory",
4
+ "singular": false,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "required": true,
12
+ "description": "Name to appear in the Home app"
13
+ },
14
+ "deviceId": {
15
+ "title": "Shelly Device ID",
16
+ "type": "string",
17
+ "required": true,
18
+ "description": "Device ID from Shelly App → Settings → Cloud → Advanced"
19
+ },
20
+ "authKey": {
21
+ "title": "Shelly Auth Key",
22
+ "type": "string",
23
+ "required": true,
24
+ "description": "Auth Key from Shelly App → Profile"
25
+ },
26
+ "channel": {
27
+ "title": "Channel",
28
+ "type": "string",
29
+ "default": "0",
30
+ "description": "Relay channel (0 or 1)"
31
+ },
32
+ "cloudBaseURL": {
33
+ "title": "Cloud Control URL",
34
+ "type": "string",
35
+ "default": "https://shelly-38-eu.shelly.cloud/device/relay/control",
36
+ "description": "Shelly Cloud relay control endpoint"
37
+ },
38
+ "statusCloudURL": {
39
+ "title": "Cloud Status URL",
40
+ "type": "string",
41
+ "default": "https://shelly-38-eu.shelly.cloud/device/status",
42
+ "description": "Shelly Cloud status endpoint"
43
+ },
44
+ "statusKey": {
45
+ "title": "Status Key",
46
+ "type": "string",
47
+ "default": "$.data["input:0"].state",
48
+ "description": "JSONPath for door sensor"
49
+ },
50
+ "title": "Status Key",
51
+ "type": "string",
52
+ "default": "$..["input:0"].state
53
+ "description": "JSONPath for door sensor (input:0.state for Shelly)"
54
+ },
55
+ "statusValueOpen": {
56
+ "title": "Open Status Value",
57
+ "type": "string",
58
+ "default": "false",
59
+ "description": "Sensor value when door is OPEN"
60
+ },
61
+ "statusValueClosed": {
62
+ "title": "Closed Status Value",
63
+ "type": "string",
64
+ "default": "true",
65
+ "description": "Sensor value when door is CLOSED"
66
+ },
67
+ "openTime": {
68
+ "title": "Open Time",
69
+ "type": "integer",
70
+ "default": 10,
71
+ "description": "Seconds to simulate door opening"
72
+ },
73
+ "closeTime": {
74
+ "title": "Close Time",
75
+ "type": "integer",
76
+ "default": 10,
77
+ "description": "Seconds to simulate door closing"
78
+ },
79
+ "polling": {
80
+ "title": "Enable Polling",
81
+ "type": "boolean",
82
+ "default": true,
83
+ "description": "Poll real door state from Shelly Cloud"
84
+ },
85
+ "pollInterval": {
86
+ "title": "Poll Interval",
87
+ "type": "integer",
88
+ "default": 30,
89
+ "description": "Seconds between status polls"
90
+ },
91
+ "debug": {
92
+ "title": "Debug Mode",
93
+ "type": "boolean",
94
+ "default": false,
95
+ "description": "Show detailed logs"
96
+ },
97
+ "manufacturer": {
98
+ "title": "Manufacturer",
99
+ "type": "string",
100
+ "default": "yago",
101
+ "description": "Manufacturer name in HomeKit"
102
+ },
103
+ "model": {
104
+ "title": "Model",
105
+ "type": "string",
106
+ "default": "GarageDoorOpenerCloud",
107
+ "description": "Model name in HomeKit"
108
+ }
109
+ }
110
+ }
111
+ }
112
+
package/index.js ADDED
@@ -0,0 +1,161 @@
1
+ var Service, Characteristic;
2
+ const packageJson = require("./package.json");
3
+ const request = require("request");
4
+ const jp = require("jsonpath");
5
+
6
+ module.exports = function(homebridge) {
7
+ Service = homebridge.hap.Service;
8
+ Characteristic = homebridge.hap.Characteristic;
9
+ homebridge.registerAccessory(
10
+ "homebridge-garagedooropenercloud",
11
+ "GarageDoorOpener",
12
+ GarageDoorOpener
13
+ );
14
+ };
15
+
16
+ function GarageDoorOpener(log, config) {
17
+ this.log = log;
18
+ this.config = config;
19
+ this.name = config.name;
20
+ this.deviceId = config.deviceId;
21
+ this.authKey = config.authKey;
22
+ this.channel = config.channel || 0;
23
+ this.statusKey = config.statusKey || "$.data.device_status.relays[0].ison";
24
+ this.statusValueOpen = config.statusValueOpen !== undefined ? config.statusValueOpen : true;
25
+ this.statusValueClosed = config.statusValueClosed !== undefined ? config.statusValueClosed : false;
26
+ this.openTime = config.openTime || 20;
27
+ this.closeTime = config.closeTime || 20;
28
+ this.polling = config.polling !== false;
29
+ this.debug = config.debug !== false;
30
+
31
+ this.statusCloudURL = "https://shelly-38-eu.shelly.cloud/device/status";
32
+ this.controlCloudURL = "https://shelly-38-eu.shelly.cloud/device/relay/control";
33
+
34
+ this.service = new Service.GarageDoorOpener(this.name);
35
+ this.informationService = new Service.AccessoryInformation();
36
+
37
+ this.informationService
38
+ .setCharacteristic(Characteristic.Manufacturer, "Shelly Cloud")
39
+ .setCharacteristic(Characteristic.Model, "Garage Door Opener")
40
+ .setCharacteristic(Characteristic.SerialNumber, this.deviceId);
41
+
42
+ this.service
43
+ .getCharacteristic(Characteristic.TargetDoorState)
44
+ .on('set', this.setTargetState.bind(this));
45
+
46
+ this.service
47
+ .getCharacteristic(Characteristic.CurrentDoorState)
48
+ .on('get', this.getCurrentState.bind(this));
49
+
50
+ if (this.polling) {
51
+ setInterval(this.pollStatus.bind(this), 30000);
52
+ this.pollStatus();
53
+ }
54
+
55
+ this.log("[%s] Initializing GarageDoorOpener accessory...", this.name);
56
+ }
57
+
58
+ GarageDoorOpener.prototype = {
59
+ getServices: function() {
60
+ return [this.informationService, this.service];
61
+ },
62
+
63
+ setTargetState: function(targetState, callback) {
64
+ this.log("[%s] Target state: %s", this.name, targetState);
65
+
66
+ const toggleData = {
67
+ id: this.deviceId,
68
+ channel: this.channel,
69
+ auth_key: this.authKey,
70
+ turn: "toggle"
71
+ };
72
+
73
+ request.post({
74
+ url: this.controlCloudURL,
75
+ form: toggleData
76
+ }, (err, response, body) => {
77
+ if (err) {
78
+ this.log("[%s] Control error: %s", this.name, err.message);
79
+ callback(err);
80
+ return;
81
+ }
82
+
83
+ this.log("[%s] Toggle command sent", this.name);
84
+ callback(null);
85
+ });
86
+ },
87
+
88
+ getCurrentState: function(callback) {
89
+ this.getStatus((err, status) => {
90
+ if (err) {
91
+ this.log("[%s] Status error: %s", this.name, err.message);
92
+ callback(err);
93
+ return;
94
+ }
95
+
96
+ let currentState;
97
+ if (status === undefined || status === null || status === false) {
98
+ currentState = Characteristic.CurrentDoorState.CLOSED;
99
+ this.log("[%s] Status: %s -> HomeKit: CLOSED (1)", this.name, status || "undefined");
100
+ } else if (status === true) {
101
+ currentState = Characteristic.CurrentDoorState.OPEN;
102
+ this.log("[%s] Status: %s -> HomeKit: OPEN (0)", this.name, status);
103
+ } else {
104
+ currentState = Characteristic.CurrentDoorState.STOPPED;
105
+ this.log("[%s] Status: %s -> HomeKit: STOPPED (4)", this.name, status);
106
+ }
107
+
108
+ callback(null, currentState);
109
+ });
110
+ },
111
+
112
+ getStatus: function(callback) {
113
+ const statusData = {
114
+ channel: this.channel,
115
+ id: this.deviceId,
116
+ auth_key: this.authKey
117
+ };
118
+
119
+ request.post({
120
+ url: this.statusCloudURL,
121
+ form: statusData
122
+ }, (err, response, body) => {
123
+ if (err) {
124
+ callback(err);
125
+ return;
126
+ }
127
+
128
+ try {
129
+ const json = JSON.parse(body);
130
+ if (this.debug) {
131
+ this.log("[%s] FULL JSON: %j", this.name, json);
132
+ }
133
+
134
+ const rawStatus = json.data.device_status.relays[0]?.ison ?? false;
135
+ const status = rawStatus;
136
+ this.log("[%s] RAW RELAY: %s", this.name, status);
137
+
138
+ callback(null, status);
139
+ } catch (parseErr) {
140
+ this.log("[%s] Error parsing status JSON: %s", this.name, parseErr.message);
141
+ callback(parseErr);
142
+ }
143
+ });
144
+ },
145
+
146
+ pollStatus: function() {
147
+ if (this.debug) {
148
+ this.log("[%s] Getting status: %s channel=%s&id=%s&auth_key=...",
149
+ this.name, this.statusCloudURL, this.channel, this.deviceId);
150
+ }
151
+
152
+ this.getStatus((err, status) => {
153
+ if (!err && status !== undefined) {
154
+ const currentState = status === true ? Characteristic.CurrentDoorState.OPEN : Characteristic.CurrentDoorState.CLOSED;
155
+ this.service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(currentState);
156
+ this.service.getCharacteristic(Characteristic.TargetDoorState).updateValue(currentState === Characteristic.CurrentDoorState.OPEN ? Characteristic.TargetDoorState.OPEN : Characteristic.TargetDoorState.CLOSED);
157
+ this.log("[%s] Status: %s -> HomeKit: %s", this.name, status, currentState === Characteristic.CurrentDoorState.OPEN ? "OPEN (0)" : "CLOSED (1)");
158
+ }
159
+ });
160
+ }
161
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "homebridge-garagedooropenercloud",
3
+ "version": "1.2.0",
4
+ "description": "Homebridge plugin for garage door opener using Shelly Cloud API",
5
+ "main": "index.js",
6
+ "engines": {
7
+ "homebridge": ">=0.4.50",
8
+ "node": ">=12.13.0"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/yago/homebridge-garagedooropenercloud"
16
+ },
17
+ "keywords": [
18
+ "homebridge-plugin",
19
+ "homebridge",
20
+ "garage",
21
+ "garagedoor",
22
+ "shelly",
23
+ "shelly-cloud",
24
+ "cloud"
25
+ ],
26
+ "author": "yago",
27
+ "license": "MIT",
28
+ "bugs": {
29
+ "url": "https://github.com/yago/homebridge-garagedooropenercloud/issues"
30
+ },
31
+ "homepage": "https://github.com/yago/homebridge-garagedooropenercloud#readme",
32
+ "dependencies": {
33
+ "jsonpath": "^1.0.2",
34
+ "request": "^2.88.2"
35
+ }
36
+ }