Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f54258

Browse files
committedAug 27, 2023
Allow scenes with lights off
1 parent 7966152 commit 7f54258

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed
 

‎scenes.go

+26-13
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ func updateScenes() {
4242
}
4343

4444
func updateSceneForSchedule(scene *hue.Scene, lightSchedule LightSchedule) {
45+
// Scene returned by AllScenes() doesn't have LightStates populated
46+
scene, err := bridge.bridge.SceneByID(scene.Id)
47+
if err != nil {
48+
log.Warningf("🎨 %v", err)
49+
return
50+
}
51+
4552
// Updating lights
4653
var modifyScene hue.ModifyScene
4754
modifyScene.Lights = toStringArray(lightSchedule.AssociatedDeviceIDs)
4855

49-
_, err := scene.Modify(modifyScene)
56+
_, err = scene.Modify(modifyScene)
5057
if err != nil {
5158
log.Warningf("🎨 %v", err)
5259
return
@@ -68,20 +75,26 @@ func updateSceneForSchedule(scene *hue.Scene, lightSchedule LightSchedule) {
6875

6976
state := interval.calculateLightStateInInterval(time.Now())
7077

71-
var modifyState hue.ModifyLightState
72-
modifyState.On = true // turn lights on when the scene is activated
78+
for i, oldstate := range scene.LightStates {
79+
if !oldstate.On {
80+
continue;
81+
}
7382

74-
if state.ColorTemperature != -1 {
75-
modifyState.ColorTemperature = uint16(mapColorTemperature(state.ColorTemperature))
76-
modifyState.Xy = colorTemperatureToXYColor(state.ColorTemperature)
77-
}
78-
if state.Brightness != -1 {
79-
modifyState.Brightness = uint8(mapBrightness(state.Brightness))
80-
}
83+
var modifyState hue.ModifyLightState
84+
modifyState.On = true // turn lights on when the scene is activated
8185

82-
_, err = scene.ModifyLightStates(modifyState)
83-
if err != nil {
84-
log.Warningf("🎨 %v", err)
86+
if state.ColorTemperature != -1 {
87+
modifyState.ColorTemperature = uint16(mapColorTemperature(state.ColorTemperature))
88+
modifyState.Xy = colorTemperatureToXYColor(state.ColorTemperature)
89+
}
90+
if state.Brightness != -1 {
91+
modifyState.Brightness = uint8(mapBrightness(state.Brightness))
92+
}
93+
94+
_, err = scene.ModifyLightState(i, modifyState)
95+
if err != nil {
96+
log.Warningf("🎨 %v", err)
97+
}
8598
}
8699

87100
log.Debugf("🎨 Successfully updated scene \"%s\"", scene.Name)

0 commit comments

Comments
 (0)
Please sign in to comment.