-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbowLights.js
45 lines (43 loc) · 2.14 KB
/
rainbowLights.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
let snek = require('snekfetch');
const config = require(`./config.json`);
var sleep = require('sleep-promise');
console.log(`Checking Config...`);
if (config.loginKey != null && config.loginKey.length > 0 && config.bridgeIP != null && config.bridgeIP.length > 0) {
console.log("Finding Lights...")
snek.get(`http://${config.bridgeIP}/api/${config.loginKey}/lights`).then(res1 => {
if (Object.keys(res1.body)[0] != null) {
if (Object.keys(res1.body)[0] == "1") {
let lightsList = Object.keys(res1.body)
let rainbow = (hueNumb, satTemp, sat) => {
console.log(`Hue: ${hueNumb}`)
lightsList.forEach(light => {
snek.put(`http://${config.bridgeIP}/api/${config.loginKey}/lights/${light}/state`).send(`{"on":true, "transitiontime": 0, "bri": 254, "hue": ${hueNumb}, "sat": 254}`).then(() => {})
})
sleep(200).then(() => {
if (hueNumb > 65535) {
console.log(`End of hue reached! Going back to 0...`)
rainbow(0, 0, 0)
} else {
if (satTemp == 1) {
rainbow(hueNumb + 300, 0, sat + 1)
} else {
rainbow(hueNumb + 300, satTemp + 1, sat)
}
}
})
}
rainbow(0, 0, 0)
} else {
console.log(`An error has occured!`)
console.log(`Error ${res1.body[0].error.type} | ${res1.body[0].error.description} | ${res1.body[0].error.address}`)
}
} else {
console.log(`An unknown error occured!`)
}
}).catch(err => {
console.log(`An error has occured!`)
console.log(err)
})
} else {
console.log("Config Invalid! Please Run node getSetupInfo.js")
}