peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

Is there the opposite of activateScene? (like deactivateScene) #113

Closed Ricardo1980 closed 6 years ago

Ricardo1980 commented 6 years ago

Is there the opposite of activateScene? (like deactivateScene) Or a way to deactivate a scene that was activated using activateScene.

peter-murray commented 6 years ago

The Hue bridge has no notion of deactivate for a scene via its APIs.

You could achieve a deactivate equivalent by defining a scene with the lights that were is a scene you activated whereby the lights are off, or to do the same with a group, but not sure if that would be what you want.

Ricardo1980 commented 6 years ago

A scene has an array of lights, should I iterate all of them to deactivate them?

Apart from that, how do I consider a scene is activated? Checking the state of all its lights?

It seems toggling a scene must be done completely manually.

It seems the iOS API can activate and deactivate a scene https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX/blob/57948ddcc7bdbaac633af8dc7c3bef04b27fd2a0/QuickStartApp_OSX/HueSDK_OSX.framework/Versions/A/Headers/PHScene.h

peter-murray commented 6 years ago

The activation state that you refer to there is for marking a scenes as being saved into the lights and ready to be activated/recalled. It takes time for all the lights in the network to confirm that a scene has been saved, hence the reference in the header you referenced.

Scenes are not quite what you think they are in this context, based on your questions. In the Hue bridges/lights, a scene is basically a name to a particular state for each light that is stored in the actual lights themselves, with some pointers to that in the bridge. So when you save a scene, the lights that compose the scene are all set to the digressed state, then each light stores that state, not the bridge, the bridge only stores a name to the scene. There is a limit to the number of scenes that can be stored, and. after that limit is reached, they start to recycle and overwrite the older less used ones.

When a scene is activated, it looks up the name as to whether it exists, and then after that the lights that store a setting associated with the name of the scene, will change to the state that was stored. This is how you can get a group of lights to effectively have different colours, etc...

You cannot then "deactivate" a scene as the bridge itself has no idea what state you want the lights in, or what they were before you activated the scene.

If you want to have a equivalent of activate/deactivate, then you could create two scenes, one that does what you want, and another that then switches off the lights for example, but that is the limits of the implementation within he Philips Hue Bridge and exposed API.

Ricardo1980 commented 6 years ago

Thanks! After reading this I realised you are right https://developers.meethue.com/documentation/scenes-api "4.1.4. Notes Note that the Active field indicates that the scene was successfully created and can be used. As from 1.2.1 it is no longer used. As from 1.11 it is no longer returned from the bridge. Also note that as from 1.11 lightstates are returned when you get a specific scene (but not for getting all scenes). See 4.6. Get a Scene for an example."