-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShelly_i4_4xDimmer.js
116 lines (103 loc) · 4 KB
/
Shelly_i4_4xDimmer.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
/**
* @copyright shelly-tools contributors
* @license GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0.de.html)
* @author U.Heynen
*
* This script is intended to remote control up to 4 Shelly Dimmer / Dimmer2 and emulates the locally conencted button.
* short_press = on/off toggle,
* double_press = on with 50% brightness,
* triple_press = on with 100% brightness,
* long_press = cylclic dimming
*/
// CONFIG START
// IP address / hostname from Shelly Dimmer device
let NoButtons = 4;
let REMOTE = [
{ip: 'admin:[email protected]' }, // User:Password@IP-Address of first button Shelly Dimmer
{ip: 'admin:[email protected]' }, // User:Password@IP-Address of second button Shelly Dimmer
{ip: 'admin:[email protected]' }, // User:Password@IP-Address of third button Shelly Dimmer
{ip: 'admin:[email protected]' }, // User:Password@IP-Address of fourth button Shelly Dimmer
];
// CONFIG END
let dim =[ 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, user_data)
{
print(JSON.stringify(event));
if (typeof event.info.event !== 'undefined')
{
let i = event.info.id ;
if(i >=0 && i < NoButtons )
{
if ( event.info.event === 'btn_up') {
if(dim[i] === true )
{
dim[i] = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?dim=stop'
},
function (response, error_code, error_message, ud) { },
null
);
}
}
if (event.info.event === 'single_push' ) {
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?turn=toggle'
},
function (response, error_code, error_message, ud) { },
null
);
} else if (event.info.event === 'double_push') {
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?turn=on&brightness=50'
},
function (response, error_code, error_message, ud) { },
null
);
} else if (event.info.event === 'triple_push' ) {
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?turn=on&brightness=100'
},
function (response, error_code, error_message, ud) { },
null
);
} else if (event.info.event === 'long_push') {
dim[i] = true;
if (up[i] === true) {
up[i] = false;
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?dim=down&step=100'
},
function (response, error_code, error_message, ud) { },
null
);
} else {
up[i] = true;
Shelly.call(
"http.get", {
url: 'http://' + REMOTE[i].ip + '/light/0?dim=up&step=100'
},
function (response, error_code, error_message, ud) { },
null
);
}
print("cycle");
} else {
return true;
}
}
} else {
return true;
}
},
);