Created
December 15, 2018 15:33
-
-
Save eduardoboucas/684a7196c7af0e7983fd3f45b11528ae to your computer and use it in GitHub Desktop.
Turn off all Philips Hue lights after a set timeout
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
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