homebridge-homeassistant-garagedoor 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 +30 -0
- package/config.json +8 -0
- package/config.schema.json +34 -0
- package/index.js +76 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Homebridge Home Assistant Garage Door
|
|
2
|
+
|
|
3
|
+
Control **Home Assistant switches** as **Garage Door accessories** in HomeKit.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
{
|
|
8
|
+
"accessory": "HomeAssistantGarageDoor",
|
|
9
|
+
"name": "Garage Door",
|
|
10
|
+
"haUrl": "http://192.168.68.239:8123",
|
|
11
|
+
"haToken": "your_long_lived_token",
|
|
12
|
+
"entityId": "switch.Puerta1"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
text
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
- ✅ Converts HA `switch` → HomeKit `GarageDoorOpener`
|
|
19
|
+
- ✅ Always starts **CLOSED** (safe default)
|
|
20
|
+
- ✅ Uses HA REST API (`switch.turn_on/off`)
|
|
21
|
+
- ✅ Full Config UI X support
|
|
22
|
+
- ✅ Works with Docker/Homebridge
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
npm install -g homebridge-homeassistant-garagedoor
|
|
26
|
+
|
|
27
|
+
text
|
|
28
|
+
|
|
29
|
+
[Full docs](https://github.com/yago/homebridge-homeassistant-garagedoor)
|
|
30
|
+
|
package/config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Home Assistant Garage Door",
|
|
3
|
+
"domain": "homebridge-homeassistant-garagedoor",
|
|
4
|
+
"exclusive": true,
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"title": "Name",
|
|
9
|
+
"required": true,
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "Garage Door"
|
|
12
|
+
},
|
|
13
|
+
"haUrl": {
|
|
14
|
+
"title": "Home Assistant URL",
|
|
15
|
+
"required": true,
|
|
16
|
+
"type": "string",
|
|
17
|
+
"placeholder": "http://192.168.68.239:8123"
|
|
18
|
+
},
|
|
19
|
+
"haToken": {
|
|
20
|
+
"title": "HA Long-Lived Token",
|
|
21
|
+
"required": true,
|
|
22
|
+
"type": "string",
|
|
23
|
+
"format": "password"
|
|
24
|
+
},
|
|
25
|
+
"entityId": {
|
|
26
|
+
"title": "HA Entity ID",
|
|
27
|
+
"required": true,
|
|
28
|
+
"type": "string",
|
|
29
|
+
"default": "switch.Puerta1",
|
|
30
|
+
"placeholder": "switch.Puerta1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var Service, Characteristic;
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
|
|
4
|
+
module.exports = function(homebridge) {
|
|
5
|
+
Service = homebridge.hap.Service;
|
|
6
|
+
Characteristic = homebridge.hap.Characteristic;
|
|
7
|
+
homebridge.registerAccessory("homebridge-homeassistant-garagedoor", "HomeAssistantGarageDoor", HomeAssistantGarageDoor);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function HomeAssistantGarageDoor(log, config) {
|
|
11
|
+
this.log = log;
|
|
12
|
+
this.name = config.name || "Garage Door";
|
|
13
|
+
this.haUrl = config.haUrl || "http://192.168.68.239:8123";
|
|
14
|
+
this.haToken = config.haToken;
|
|
15
|
+
this.entityId = config.entityId || "switch.Puerta1";
|
|
16
|
+
|
|
17
|
+
// Estado inicial SIEMPRE CERRADO
|
|
18
|
+
this.currentState = Characteristic.CurrentDoorState.CLOSED;
|
|
19
|
+
|
|
20
|
+
this.service = new Service.GarageDoorOpener(this.name);
|
|
21
|
+
this.informationService = new Service.AccessoryInformation();
|
|
22
|
+
|
|
23
|
+
this.informationService
|
|
24
|
+
.setCharacteristic(Characteristic.Manufacturer, "Home Assistant")
|
|
25
|
+
.setCharacteristic(Characteristic.Model, "Garage Door")
|
|
26
|
+
.setCharacteristic(Characteristic.SerialNumber, this.entityId);
|
|
27
|
+
|
|
28
|
+
this.service.getCharacteristic(Characteristic.TargetDoorState)
|
|
29
|
+
.on('set', this.setTargetState.bind(this));
|
|
30
|
+
|
|
31
|
+
this.service.getCharacteristic(Characteristic.CurrentDoorState)
|
|
32
|
+
.on('get', this.getCurrentState.bind(this))
|
|
33
|
+
.setValue(this.currentState);
|
|
34
|
+
|
|
35
|
+
this.service.getCharacteristic(Characteristic.TargetDoorState)
|
|
36
|
+
.setValue(Characteristic.CurrentDoorState.CLOSED);
|
|
37
|
+
|
|
38
|
+
this.log("[%s] Initialized - HA: %s (%s)", this.name, this.haUrl, this.entityId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
HomeAssistantGarageDoor.prototype = {
|
|
42
|
+
getServices: function() {
|
|
43
|
+
return [this.informationService, this.service];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
setTargetState: function(targetState, callback) {
|
|
47
|
+
this.log("[%s] Target state: %s", this.name, targetState === 0 ? "OPEN" : "CLOSED");
|
|
48
|
+
|
|
49
|
+
const service = targetState === 0 ? "switch.turn_on" : "switch.turn_off";
|
|
50
|
+
|
|
51
|
+
axios.post(`${this.haUrl}/api/services/switch/${service}`,
|
|
52
|
+
{ entity_id: this.entityId },
|
|
53
|
+
{
|
|
54
|
+
headers: {
|
|
55
|
+
'Authorization': `Bearer ${this.haToken}`,
|
|
56
|
+
'Content-Type': 'application/json'
|
|
57
|
+
},
|
|
58
|
+
timeout: 10000
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
.then(() => {
|
|
62
|
+
this.log("[%s] Command sent to HA: %s", this.name, service);
|
|
63
|
+
callback(null);
|
|
64
|
+
})
|
|
65
|
+
.catch(err => {
|
|
66
|
+
this.log("[%s] HA Error: %s", this.name, err.message);
|
|
67
|
+
callback(err);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
getCurrentState: function(callback) {
|
|
72
|
+
// SIEMPRE devuelve CERRADO (como tu plugin anterior)
|
|
73
|
+
callback(null, this.currentState);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "homebridge-homeassistant-garagedoor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Homebridge plugin for Home Assistant garage door control",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"homebridge-plugin",
|
|
11
|
+
"homebridge",
|
|
12
|
+
"homeassistant",
|
|
13
|
+
"garage",
|
|
14
|
+
"door"
|
|
15
|
+
],
|
|
16
|
+
"author": "yago",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"engines": {
|
|
19
|
+
"homebridge": ">=1.0.0",
|
|
20
|
+
"node": ">=18.0.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.6.0"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/torresyago/homebridge-homeassistant-garagedoor.git"
|
|
28
|
+
}
|
|
29
|
+
}
|