-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcycle_rgbw_colors.js
66 lines (58 loc) · 2 KB
/
cycle_rgbw_colors.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
/**
* @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 control a Shelly RGBW2 / ShellyDuo RGBW with a single button from
* a Shelly Plus device. Every time the button from the Plus device is pushed it jumps to the next step
* defined in the sequence array.
*/
// CONFIG START
// IP address or hostname from RGBW device
let REMOTE = {
ip: '192.168.178.70',
};
// button sequence
// The demo sequence is: on and blue with max brightness, then red, green, yellow, purple, off
let sequence = [
'?turn=on&gain=100&blue=255&red=0&green=0', // blue
'?turn=on&gain=100&blue=0&red=255&green=0', // red
'?turn=on&gain=100&blue=0&red=0&green=255', // green
'?turn=on&gain=100&blue=0&red=255&green=255', // yellow
'?turn=on&gain=100&blue=225&red=185&green=76', // purple
'?turn=off' // off
];
// CONFIG END
// no need to change anything below this line..
let position = 0;
// add an evenHandler for button type input and single push events
Shelly.addEventHandler(
function (event, user_data) {
//print(JSON.stringify(event));
if (typeof event.info.event !== 'undefined') {
if (event.info.event === 'single_push') {
setRGBW(REMOTE.ip, position);
position++;
if (sequence.length === position) {
position = 0;
}
} else {
return true;
}
} else {
return true;
}
},
);
// send RBGW command
function setRGBW(ip, position) {
Shelly.call(
"http.get", {
url: 'http://' + ip + '/light/0' + sequence[position]
},
function (response, error_code, error_message, ud) {
print(sequence[position]);
},
null
);
};