Skip to content

Instantly share code, notes, and snippets.

@eduardoboucas
Created December 15, 2018 15:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save eduardoboucas/684a7196c7af0e7983fd3f45b11528ae to your computer and use it in GitHub Desktop.
Turn off all Philips Hue lights after a set timeout
const hue = require('node-hue-api')
const HueApi = hue.HueApi
const lightState = hue.lightState
const IP = '192.168.1.85'
const USERNAME = 'XXXXXX'
const TIMEOUT = 30000
const api = new HueApi(IP, USERNAME)
const offState = lightState.create().off()
const echo = message => {
console.log(`[Hue Controller] ${new Date().toISOString()}: ${message}`)
}
echo(`Turning off Hue lights in ${TIMEOUT} milliseconds`)
setTimeout(() => {
api.lights()
.then(({lights}) => {
let commands = lights.map(light => {
echo(`Turning off light: ${light.name}`)
return api.setLightState(light.id, offState).done()
})
return Promise.all(commands)
})
.done()
}, TIMEOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment