-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathemulate_multiple_dimmers.js
102 lines (91 loc) · 3.24 KB
/
emulate_multiple_dimmers.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
/**
* @copyright shelly-tools contributors
* @license GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0.de.html)
* @authors https://github.com/shelly-tools/shelly-script-examples/graphs/contributors
*
* This script is intended to remote control a Shelly Dimmer / Dimmer2 and emulates the locally conencted button.
* short_press = on/off toggle, double_press = on with 100% brightness, long_press cylce between dimming and brightening.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.178.166', // dimmer controlled with button 0
'192.168.178.240', // dimmer controlled with button 1
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
function (event) {
if (typeof event.info.event !== 'undefined') {
let i = event.info.id;
if (typeof dimmer[i] !== 'undefined') {
if (dimstate[i] === true && event.info.event === 'btn_up') {
dimstate[i] = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=stop'
},
function (response, error_code, error_message, ud) { },
null
);
}
if (event.info.event === 'single_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?turn=toggle'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'double_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?turn=on&brightness=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i]) {
dimstate[i] = true;
up[i] = false;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=down&step=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i] === false) {
dimstate[i] = true;
up[i] = true;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=up&step=100'
},
function (rs, ec, em) { },
null
);
}
else {
return true;
}
}
} else {
return true;
}
},
);