You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to store and recall scenes. The scenes are created with the correct lamp selection on the bridge, but when I call api.activateScene using the scene id, the lamps do not respond.
Unfortunately I cannot verify the light states that are stored for each scene, only the lamp set that makes up the scene.
This is my code. It shows each scene once (because the first time the light states are set separately using setLightState instead of using the scene mechanism). After that the scenes mechanism (api.createScene, api.activateScene) should take over, but the lamps do not change according to the called scenes.
index.js:
var hue = require("node-hue-api"),
HueApi = hue.HueApi,
lightState = hue.lightState;
var displayResult = function (result) {
console.log(JSON.stringify(result, null, 2));
};
var displayError = function (err) {
console.log(JSON.stringify(err, null, 2));
};
var hostname = "xxx.xxx.xxx.xxx",
username = "someusername",
api;
api = new HueApi(hostname, username);
//load initial config from json
var sceneConfig = require('./scenes.json');
//set the lightstate for each light separately when they're not stored as a scene yet
var setStates = function (lightStates, callback) {
var todo = Object.keys(lightStates).length;
console.log(todo);
//safety function to make sure all states are set before saving to scene
var lightDone = function () {
todo--;
console.log(todo);
if (todo === 0) {
callback();
}
};
for (var lightId in lightStates) {
api.setLightState(lightId, lightStates[lightId])
.then(lightDone)
.fail(displayError)
.done();
}
};
//activate a scene from the scene config. if it has no Hue scene id yet,
//set the states separately and store them as a Hue scene
var activateScene = function (sceneName) {
var scene = sceneConfig[sceneName];
if (scene !== null) {
if (scene.id !== undefined) {
console.log('using predefined scene id ' + scene.id);
api.activateScene(scene.id)
.then('predefined scene result: ' + console.log)
.done();
} else if (scene.states !== undefined) {
setStates(scene.states, function () {
var lightIds = Object.keys(scene.states);
api.createScene(lightIds, '', function (err, result) {
if (err) throw err;
//store the created scene id in the scenes config object
scene.id = result.id;
sceneConfig[sceneName] = scene;
console.log('scene created.');
console.log(result);
});
});
}
}
};
//switch between scenes every 4 seconds
var switchBool = true;
setInterval(function () {
var sceneToActivate = switchBool ? 'gold' : 'sleep';
activateScene(sceneToActivate);
switchBool = !switchBool;
}, 4000);
It was a mistake in the refactoring on my part, the scene id was not being sent in the body of the request. Release 1.0.5 has just been published to correct this.
If you set the NODE_DEBUG environment variable to include the string hue-api then it will show you the commands being sent to the bridge on the console, which can assist you if you run into any further issues.
I'm trying to store and recall scenes. The scenes are created with the correct lamp selection on the bridge, but when I call api.activateScene using the scene id, the lamps do not respond.
Unfortunately I cannot verify the light states that are stored for each scene, only the lamp set that makes up the scene.
This is my code. It shows each scene once (because the first time the light states are set separately using setLightState instead of using the scene mechanism). After that the scenes mechanism (api.createScene, api.activateScene) should take over, but the lamps do not change according to the called scenes.
index.js:
scenes.json:
The text was updated successfully, but these errors were encountered: