HUE-Lightshow/lib.js
2024-04-03 18:04:39 -07:00

92 lines
1.8 KiB
JavaScript

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const baseURL = 'https://192.168.254.49/clip/v2/resource/'
const resource = 'light/c84fd63f-aa24-4203-9d92-dfa15e65bd54'
const headers = {
'Content-Type': 'application/json',
'hue-application-key': 'NpvdpFNOk3ROMGeWi2R598Jz31zyZ8Eiv5HC3S2o'
};
function setBlue(delay){
const body = `{
"color": {
"xy": {
"x":0.16,
"y":0.08
}
},
"dynamics": {
"duration": 0
}
}`
console.log("Send Blue @", delay)
sendRequest(body)
}
function setPink(delay){
const body = `{
"color": {
"xy": {
"x":0.45,
"y":0.20
}
},
"dynamics": {
"duration": 0
}
}`
console.log("Send Pink @", delay)
sendRequest(body)
}
function sendRequest(body){
try {
fetch(`${baseURL}${resource}`, {
method: 'PUT',
headers,
body
})
.then(
(res) => {
// console.log("Status:", res.status)
return res.json()
}
)
.then(
// (res) => console.log("Body:", res)
)
} catch (error) {
console.log(error)
}
}
function glow(delay){
const body = `{
"dimming": {
"brightness":100.0
},
"dynamics": {
"duration": 1000
}
}`
const body2 = `{
"dimming": {
"brightness":30.0
},
"dynamics": {
"duration": 1000
}
}`
console.log("Send Glow (up and down) @", delay)
setTimeout(sendRequest, 1000, body)
setTimeout(sendRequest, 2000, body2)
}
module.exports = { setBlue, setPink, glow }