-
Notifications
You must be signed in to change notification settings - Fork 1
/
led-color.js
109 lines (109 loc) · 2.89 KB
/
led-color.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
/**
* Erweitert von Thelly © Thomas Herfort für Mehrfachtaster,
* Funktioniert jetzt auch, wenn die Leuchte vorher irgendwie in den WeissModus geschalten wurde, es gibt ja ein dimmbares Weiss in allen Farben auch im ColorModus.
* Dreifachklick hinzugefügt, schaltet in Weissmodus ab Firmware 0.13
*/
let REMOTE = {
ip: '192.168.178.105',
};
let colorsequence = [
'?turn=on&red=208&green=208&blue=208', // silber
'?turn=on&red=0&green=0&blue=128', // darkblue
'?turn=on&red=0&green=0&blue=255', // blue
'?turn=on&red=128&green=0&blue=0', // darkred
'?turn=on&red=255&green=0&blue=0', // red
'?turn=on&red=0&green=128&blue=0', // darkgreen
'?turn=on&red=0&green=255&blue=0', // green
'?turn=on&red=0&green=128&blue=128', // cyan
'?turn=on&red=128&green=100&blue=0', // gold
'?turn=on&red=128&green=0&blue=128', // purple
'?turn=on&red=255&green=255&blue=255', // weiss
];
let dimsequence = [
'?gain=75', // 75%
'?gain=50', // 50%
'?gain=25', // 25%
'?gain=7', // 4% Minimum bei oben aufgelisteten DunkelFarben
'?gain=100', // 100%
];
let colorposition = 0;
let dimpos = 0;
Shelly.addEventHandler(
function (event, user_data) {
// input:0 ist Kanal 0 = Taste 1, Taste 4 also Kanal 3...(also in nächster Zeile den Button benennen)
if (event.component === "input:3") {
if (typeof event.info.event !== 'undefined') {
if (event.info.event === 'double_push') {
setRGBW(REMOTE.ip, colorposition);
colorposition++;
dimpos = 0;
if (colorsequence.length === colorposition) {
colorposition = 0;
}
} else if (event.info.event === 'single_push'){
toggleRGBW(REMOTE.ip);
} else if (event.info.event === 'triple_push'){
whitemodeRGBW(REMOTE.ip);
} else if (event.info.event === 'long_push') {
dimRGBW(REMOTE.ip, dimpos);
dimpos++;
if (dimsequence.length === dimpos) {
dimpos = 0;
};
} else {
return true;
}
} else {
return true;
}
}
},
);
function setRGBW(ip, colorposition) {
Shelly.call(
"http.get", {
url: 'http://' + ip + '/light/0' + colorsequence[colorposition]
},
function (response, error_code, error_message, ud) {
print(colorsequence[colorposition]);
},
null
);
Shelly.call(
"http.get", {
url: 'http://' + ip + '/settings?mode=color'
}
);
};
function dimRGBW(ip, dimpos) {
Shelly.call(
"http.get", {
url: 'http://' + ip + '/light/0' + dimsequence[dimpos]
},
function (response, error_code, error_message, ud) {
print(dimsequence[dimpos]);
},
null
);
);
};
function whitemodeRGBW(ip) {
Shelly.call(
"http.get", {url: 'http://' + ip + '/settings?mode=white'}
);
};
function toggleRGBW(ip) {
Shelly.call(
"http.get", {
url: 'http://' + ip + '/light/0?turn=toggle'
},
function (response, error_code, error_message, ud) {
},
null
);
Shelly.call(
"http.get", {
url: 'http://' + ip + '/settings?mode=color'
}
);
}