Last active
June 19, 2017 18:57
-
-
Save linuxgemini/8ab6b32c34c78a7b40142e0262a9566d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Please do note that this script will not do pulses on colours. | |
This is due to me not using H(ue) - S(aturation) - B(rightness) format | |
of Philips. | |
Written by linuxgemini, MIT License, 2017 | |
*/ | |
let huejay = require("huejay"); | |
let tmi = require("tmi.js"); | |
var lID = 2; | |
var options = { | |
options: { | |
debug: true | |
}, | |
connection: { | |
reconnect: true | |
}, | |
identity: { | |
username: "", // insert twitch username | |
password: "" // insert oauth password | |
}, | |
channels: ["#videoyun"] | |
}; | |
var client = new tmi.client(options); | |
let lClient = new huejay.Client({ | |
host: "", // insert IP here | |
port: 80, | |
username: "", // insert username here | |
timeout: 15000, | |
}) | |
function getOld(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.colorMode = "xy"; | |
var oldXY_1[lampID] = light.xy[0]; | |
var oldXY_2[lampID] = light.xy[1]; | |
}); | |
} | |
function normal(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = oldXY_1[lampID]; | |
light.xy[1] = oldXY_2[lampID]; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function onebit(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.3190; | |
light.xy[1] = 0.3168; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function onehunderedbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.3076; | |
light.xy[1] = 0.1805; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function onekbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.1663; | |
light.xy[1] = 0.4312; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function fivekbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.1636; | |
light.xy[1] = 0.2045; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function tenkbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.6920; | |
light.xy[1] = 0.3012; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function twentyfivekbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.4882; | |
light.xy[1] = 0.2392; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function fiftykbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.6098; | |
light.xy[1] = 0.3688; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function seventyfivekbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.1829; | |
light.xy[1] = 0.6874; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
function hundredkbits(lampID) { | |
lClient.lights.getById(lampID) | |
.then(light => { | |
light.xy[0] = 0.5152; | |
light.xy[1] = 0.4558; | |
return lClient.lights.save(light) | |
}) | |
.then(light => { | |
console.log(`Updated light [{$light.id}]`); | |
}) | |
.catch(error => { | |
console.error("Something went wrong\n" + error.stack); | |
}); | |
} | |
getOld(lID); | |
client.on("cheer", function (channel, userstate, message) { | |
if (userstate.bits >= 1 && userstate.bits != 100) { | |
onebit(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 100 && userstate.bits != 1000) { | |
onehunderedbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 1000 && userstate.bits != 5000) { | |
onekbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 5000 && userstate.bits != 10000) { | |
fivekbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 10000 && userstate.bits != 25000) { | |
tenkbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 25000 && userstate.bits != 50000) { | |
twentyfivekbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 50000 && userstate.bits != 75000) { | |
fiftykbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 75000 && userstate.bits != 100000) { | |
seventyfivekbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
if (userstate.bits >= 100000) { | |
hundredkbits(lID); | |
setTimeout(function(){normal();}, 2000); | |
} | |
}); | |
client.connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment