-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.hbs
197 lines (159 loc) · 4.66 KB
/
README.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Fibaro HomeCenter2 client
[![Build Status](https://travis-ci.org/inwaar/fibaro-home-center2-client.svg?branch=master)](https://travis-ci.org/inwaar/fibaro-home-center2-client)
Javascript client for communicating with Fibaro HomeCenter2 smart home controllers.
## Requirements
- NodeJS (>=10)
- Fibaro Home Center 2
## Installation
`yarn add fibaro-home-center2-client`
or
`npm install --save fibaro-home-center2-client`
## Usage
### Get rooms:
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getRooms().subscribe((rooms) => {
console.log(rooms);
});
```
### Get all available devices:
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
console.log(devices);
});
```
### Poll devices properties' updates:
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.events().subscribe((event) => {
console.log(event);
});
```
### Control devices:
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
const light = devices.find(device => device.identifiers.includes('kitchen/lights/main-light'));
light.turnOff().subscribe(() => {
console.log('Kitchen light has turned off');
});
});
```
### Control devices based on events from other devices:
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
const fan = devices.find(device => device.identifiers.includes('bedroom/climate/fan'));
client.events().subscribe((event) => {
if (event.identifiers.includes('bedroom/climate/temperature') && event.property === 'value') {
if (event.newValue > 22) {
fan.turnOn().subscribe();
} else {
fan.turnOff().subscribe();
}
}
})
});
```
### Dump all devices' identifiers
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
const map = {};
for (const device of devices) {
for (const identifier of device.identifiers) {
map[identifier] = device.id;
}
}
for (const key of Object.keys(map).sort()) {
console.log(key + ': ' + map[key]);
}
});
```
### List all powered devices
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
devices
.filter(device => device.properties.power > 0)
.map(device => console.log(device.identifiers.join(', ') + ': ' + device.properties.power + 'w'));
});
```
Output example:
```
hall/lights/lamp: 39.4w
garage/lights/lamp: 79.1w
```
### List all devices' actions and their possible arguments
```javascript
const Fibaro = require('fibaro-home-center2-client');
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
for (const device of devices) {
console.log(device.identifiers.join(', '), device.actions);
}
});
```
Output example:
```
...
bedroom/blinds/curtains {
close: 0,
open: 0,
reconfigure: 0,
reset: 0,
sceneActivationSet: 0,
setValue: 1,
setValue2: 1,
startLevelDecrease: 0,
startLevelIncrease: 0,
stop: 0,
stopLevelChange: 0
}
bathroom/safety/flood-sensor {
abortUpdate: 1,
forceArm: 0,
meetArmConditions: 0,
reconfigure: 0,
retryUpdate: 1,
setArmed: 1,
setInterval: 1,
startUpdate: 1,
updateFirmware: 1
}
bedroom/lights/led-strip {
abortUpdate: 1,
reconfigure: 0,
reset: 0,
retryUpdate: 1,
setB: 1,
setBrightness: 1,
setColor: 1,
setFavoriteProgram: 2,
setG: 1,
setR: 1,
setValue: 1,
setW: 1,
startLevelDecrease: 0,
startLevelIncrease: 0,
startProgram: 1,
startUpdate: 1,
stopLevelChange: 0,
turnOff: 0,
turnOn: 0,
updateFirmware: 1
}
...
```
## API Reference
{{>main}}
## License
This project is licensed under the GNU GPLv3 - see the [LICENSE](LICENSE) file for details