forked from jghaanstra/cloud.shelly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
191 lines (165 loc) · 8.32 KB
/
app.js
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
"use strict";
const Homey = require('homey');
const util = require('/lib/util.js');
class ShellyApp extends Homey.App {
onInit() {
this.log('Initializing Shelly App ...');
// GENERIC
new Homey.FlowCardAction('actionReboot')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/reboot', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
// SHELLY 1
new Homey.FlowCardAction('flipbackSwitch')
.register()
.registerRunListener((args, state) => {
if (args.switch === '1') {
return util.sendCommand('/relay/0?turn=on&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else {
return util.sendCommand('/relay/0?turn=off&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
}
})
// SHELLY 2 & SHELLY 4 PRO
new Homey.FlowCardAction('flipbackSwitch2')
.register()
.registerRunListener((args, state) => {
if (args.switch === '1') {
return util.sendCommand('/relay/'+ args.relay +'?turn=on&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else {
return util.sendCommand('/relay/'+ args.relay +'?turn=off&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
}
})
new Homey.FlowCardAction('flipbackSwitch4')
.register()
.registerRunListener((args, state) => {
if (args.switch === '1') {
return util.sendCommand('/relay/'+ args.relay +'?turn=on&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else {
return util.sendCommand('/relay/'+ args.relay +'?turn=off&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
}
})
// SHELLY RGBW2 COLOR
new Homey.FlowCardAction('flipbackSwitchRGBW2Color')
.register()
.registerRunListener((args, state) => {
if (args.switch === '1') {
return util.sendCommand('/color/0?turn=on&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else {
return util.sendCommand('/color/0?turn=off&timer='+ args.timer +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
}
})
new Homey.FlowCardAction('effectRGBW2Color')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/color/0?turn=on&effect='+ Number(args.effect) +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
// SHELLY 2(.5) ROLLER SHUTTER
new Homey.FlowCardAction('moveRollerShutter')
.register()
.registerRunListener((args, state) => {
if (args.direction == 'open') {
args.device.setStoreValue('last_action', 'up');
args.device.setCapabilityValue('windowcoverings_state','up');
} else if (args.direction == 'close') {
args.device.setStoreValue('last_action', 'down');
args.device.setCapabilityValue('windowcoverings_state','down');
}
return util.sendCommand('/roller/0?go='+ args.direction +'&duration='+ args.move_duration +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
new Homey.FlowCardAction('moveRollerShutterOffset')
.register()
.registerRunListener((args, state) => {
if (args.direction == 'open') {
args.device.setStoreValue('last_action', 'up');
args.device.setCapabilityValue('windowcoverings_state','up');
} else if (args.direction == 'close') {
args.device.setStoreValue('last_action', 'down');
args.device.setCapabilityValue('windowcoverings_state','down');
}
return util.sendCommand('/roller/0?go='+ args.direction +'&offset='+ args.offset +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
new Homey.FlowCardAction('rollerShutterIntelligentAction')
.register()
.registerRunListener((args, state) => {
if (args.device.getCapabilityValue('windowcoverings_state') !== 'idle') {
args.device.setCapabilityValue('windowcoverings_state','idle');
return util.sendCommand('/roller/0?go=stop', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else if (args.device.getStoreValue('last_action') == 'up') {
args.device.setStoreValue('last_action', 'down');
args.device.setCapabilityValue('windowcoverings_state','down');
return util.sendCommand('/roller/0?go=close', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else if (args.device.getStoreValue('last_action') == 'down') {
args.device.setStoreValue('last_action', 'up');
args.device.setCapabilityValue('windowcoverings_state','up');
return util.sendCommand('/roller/0?go=open', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
} else {
return false;
}
})
// SHELLY DIMMER
new Homey.FlowCardCondition('conditionDimmerInput1')
.register()
.registerRunListener((args, state) => {
if (args.device) {
return args.device.getCapability("onoff.input1");
} else {
return false;
}
})
new Homey.FlowCardCondition('conditionDimmerInput2')
.register()
.registerRunListener((args, state) => {
if (args.device) {
return args.device.getCapability("onoff.input2");
} else {
return false;
}
})
new Homey.FlowCardAction('actionRGBW2EnableWhiteMode')
.register()
.registerRunListener((args, state) => {
return args.device.triggerCapabilityListener("onoff.whitemode", true);
})
new Homey.FlowCardAction('actionRGBW2DisableWhiteMode')
.register()
.registerRunListener((args, state) => {
return args.device.triggerCapabilityListener("onoff.whitemode", false);
})
// SHELLY DUO
new Homey.FlowCardAction('actionDuoDimTemperature')
.register()
.registerRunListener((args, state) => {
try {
let light_temperature = 1 - Number(util.normalize(args.light_temperature, 2700, 6500));
args.device.triggerCapabilityListener("dim", args.brightness);
args.device.triggerCapabilityListener("light_temperature", light_temperature);
return Promise.resolve(true);
} catch (error) {
return Promise.reject(error);
}
})
// SHELLY GAS
new Homey.FlowCardAction('actionGasSetVolume')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/settings/?set_volume='+ args.volume +'', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
new Homey.FlowCardAction('actionGasMute')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/mute', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
new Homey.FlowCardAction('actionGasUnmute')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/unmute', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
new Homey.FlowCardAction('actionGasTest')
.register()
.registerRunListener((args, state) => {
return util.sendCommand('/self_test', args.device.getSetting('address'), args.device.getSetting('username'), args.device.getSetting('password'));
})
}
}
module.exports = ShellyApp;