stefanwichmann / kelvin

Kelvin - The hue bot
MIT License
353 stars 37 forks source link

Light doesn't respect manual change #123

Open haasn opened 1 month ago

haasn commented 1 month ago

When I try changing the bulb manually, either in the Hue app or with a dimmer switch, nothing happens and Kelvin immediately overrides the bulb state.

Log

Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="🤖 Kelvin development starting up... 🚀"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="⚙ Configuration /opt/kelvin/config.json loaded"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="🤖 Initializing bridge connection..."
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="⌘ Connection to bridge established"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="🌍 Working with location <REDACTED> from configuration"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="🤖 Devices found on current bridge:"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="| Name                             |  ID | On    | Dimmable | Temperature | Color | Temperature range |"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="| Hallway Main                     |   5 | false | true     | true        | false |     2200K - 6500K |"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="| Entrance                         |   6 | false | true     | true        | false |     2200K - 6500K |"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="| Bedroom Main                     |   7 | true  | true     | true        | false |     2200K - 6500K |"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Hallway Main - Activating schedule for Oct 27 2024 (Sunrise: 07:43, Sunset: 16:23)"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Hallway Main - Activating interval 22:00 - 23:59"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Entrance - Activating schedule for Oct 27 2024 (Sunrise: 07:43, Sunset: 16:23)"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Entrance - Activating interval 22:00 - 23:59"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Bedroom Main - Activating schedule for Oct 27 2024 (Sunrise: 07:43, Sunset: 16:23)"
Oct 27 23:36:44 tina kelvin[1178143]: time="2024/27/10 23:36:44" level=info msg="💡 Light Bedroom Main - Activating interval 22:00 - 23:59"
Oct 27 23:36:46 tina kelvin[1178143]: time="2024/27/10 23:36:46" level=info msg="💡 Light Bedroom Main - Light just appeared."
Oct 27 23:36:46 tina kelvin[1178143]: time="2024/27/10 23:36:46" level=info msg="💡 Light Bedroom Main - Initializing state to 1557K at 19% brightness."

If I attempt manually changing the bulb brightness now, I don't see anything in the logs. Nor do I see anything when I attempt manually changing the scene to something other than "Natural (Kelvin)", such as "Night Light".

Here is what happens if I power cycle the light now:

Oct 27 23:41:23 tina kelvin[1178143]: time="2024/27/10 23:41:23" level=info msg="💡 Light Bedroom Main - Light is no longer reachable. Clearing state..."
Oct 27 23:41:27 tina kelvin[1178143]: time="2024/27/10 23:41:27" level=info msg="💡 Light Bedroom Main - Light just appeared."
Oct 27 23:41:27 tina kelvin[1178143]: time="2024/27/10 23:41:27" level=info msg="💡 Light Bedroom Main - Initializing state to 1546K at 19% brightness

Config

{
  "version": 1,
  "bridge": {
    "ip": "<REDACTED>",
    "username": "<REDACTED>"
  },
  "location": {
    "latitude": <REDACTED>,
    "longitude": <REDACTED>
  },
  "webinterface": {
    "enabled": false,
    "port": 8080
  },
  "schedules": [
    {
      "name": "Natural",
      "associatedDeviceIDs": [
        5,
        6,
        7
      ],
      "enableWhenLightsAppear": true,
      "defaultColorTemperature": 4350,
      "defaultBrightness": 100,
      "beforeSunrise": [
        {
          "time": "0:00",
          "colorTemperature": 1300,
          "brightness": 15
        },
        {
          "time": "2:00",
          "colorTemperature": 1000,
          "brightness": 5
        },
        {
          "time": "5:00",
          "colorTemperature": 1500,
          "brightness": 10
        },
        {
          "time": "7:00",
          "colorTemperature": 6400,
          "brightness": 100
        },
        {
          "time": "10:00",
          "colorTemperature": 4350,
          "brightness": 100
        }
      ],
      "afterSunset": [
        {
          "time": "17:00",
          "colorTemperature": 2900,
          "brightness": 100
        },
        {
          "time": "20:00",
          "colorTemperature": 2250,
          "brightness": 56
        },
        {
          "time": "22:00",
          "colorTemperature": 1800,
          "brightness": 35
        },
        {
          "time": "23:59",
          "colorTemperature": 1500,
          "brightness": 15
        }
      ]
    }
  ]
}
haasn commented 1 month ago

Well, if I set it to "enableWhenLightsAppear": false,, manual changes work and "stick" (until I re-activate the Natural Kelvin scene). However, it's my understanding that in this configuration, Kelvin will not automatically take over when I power on the light.

What I want is to have a configuration where:

  1. Powering on a light automatically enables kelvin
  2. If I manually change a light, my change should stick until I power the bulb off again or manually re-activate the Kelvin scene

Is this not possible?

haasn commented 1 month ago

Seems to be some sort of duplicate of #70 and #62. My debug log shows the light being stuck in initialization:

DEBU[2024/28/10 00:02:11] ⚙ Configuration hasn't changed. Omitting write. 
DEBU[2024/28/10 00:02:11] 💡 Light Hallway Main - Initialization complete. Identified as Color temperature light (ModelID: 929003099101, Version: 1.93.7) 
DEBU[2024/28/10 00:02:11] 💡 Light Entrance - Initialization complete. Identified as Color temperature light (ModelID: 929003099201, Version: 1.93.7) 
DEBU[2024/28/10 00:02:11] 💡 Light Bedroom Main - Initialization complete. Identified as Color temperature light (ModelID: 929003823401, Version: 1.82.10) 
INFO[2024/28/10 00:02:11] 🤖 Devices found on current bridge:           
INFO[2024/28/10 00:02:11] | Name                             |  ID | On    | Dimmable | Temperature | Color | Temperature range | 
INFO[2024/28/10 00:02:11] | Hallway Main                     |   5 | false | true     | true        | false |     2200K - 6500K | 
INFO[2024/28/10 00:02:11] | Entrance                         |   6 | false | true     | true        | false |     2200K - 6500K | 
INFO[2024/28/10 00:02:11] | Bedroom Main                     |   7 | true  | true     | true        | false |     2200K - 6500K | 
INFO[2024/28/10 00:02:11] 💡 Light Hallway Main - Activating schedule for Oct 28 2024 (Sunrise: 07:45, Sunset: 16:21) 
INFO[2024/28/10 00:02:11] 💡 Light Hallway Main - Activating interval 00:00 - 02:00 
DEBU[2024/28/10 00:02:11] 💡 Light Hallway Main - Initialized target light state for the interval 00:00 - 02:00 to {ColorTemperature:1295 Brightness:15} 
INFO[2024/28/10 00:02:11] 💡 Light Entrance - Activating schedule for Oct 28 2024 (Sunrise: 07:45, Sunset: 16:21) 
INFO[2024/28/10 00:02:11] 💡 Light Entrance - Activating interval 00:00 - 02:00 
DEBU[2024/28/10 00:02:11] 💡 Light Entrance - Initialized target light state for the interval 00:00 - 02:00 to {ColorTemperature:1295 Brightness:15} 
INFO[2024/28/10 00:02:11] 💡 Light Bedroom Main - Activating schedule for Oct 28 2024 (Sunrise: 07:45, Sunset: 16:21) 
INFO[2024/28/10 00:02:11] 💡 Light Bedroom Main - Activating interval 00:00 - 02:00 
DEBU[2024/28/10 00:02:11] 💡 Light Bedroom Main - Initialized target light state for the interval 00:00 - 02:00 to {ColorTemperature:1295 Brightness:15} 
DEBU[2024/28/10 00:02:11] 🎨 Updating scenes...                         
DEBU[2024/28/10 00:02:11] 🎨 Updating scene "Natural (Kelvin)" for schedule "Natural"... 
DEBU[2024/28/10 00:02:12] 🎨 Successfully updated scene "Natural (Kelvin)" 
DEBU[2024/28/10 00:02:12] 🎨 Updating scene "Natural (Kelvin)" for schedule "Natural"... 
DEBU[2024/28/10 00:02:12] 🎨 Successfully updated scene "Natural (Kelvin)" 
DEBU[2024/28/10 00:02:12] 🤖 Starting cyclic update...                  
INFO[2024/28/10 00:02:13] 💡 Light Bedroom Main - Light just appeared.  
INFO[2024/28/10 00:02:13] 💡 Light Bedroom Main - Initializing state to 1295K at 15% brightness. 
DEBU[2024/28/10 00:02:13] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:13] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:13] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:13] 💡 Light Bedroom Main - Light was initialized to 1295K at 15% brightness 
DEBU[2024/28/10 00:02:13] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:14] 💡 Light Bedroom Main - Light in initialization for 1.114598061s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:14] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:14] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:14] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:14] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:14] 💡 Light Bedroom Main - Adjusting light state to 1295K at 15% brightness (Initialization) 
DEBU[2024/28/10 00:02:14] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:15] 💡 Light Bedroom Main - Light in initialization for 2.237177451s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:15] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:15] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:15] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:15] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:15] 💡 Light Bedroom Main - Adjusting light state to 1295K at 15% brightness (Initialization) 
DEBU[2024/28/10 00:02:15] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:16] 💡 Light Bedroom Main - Light in initialization for 3.361475147s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:16] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:16] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:16] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:16] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:16] 💡 Light Bedroom Main - Adjusting light state to 1295K at 15% brightness (Initialization) 
DEBU[2024/28/10 00:02:16] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:17] 💡 Light Bedroom Main - Light in initialization for 4.485705916s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:17] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:17] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:17] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:18] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:18] 💡 Light Bedroom Main - Adjusting light state to 1295K at 15% brightness (Initialization) 
DEBU[2024/28/10 00:02:18] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:19] 💡 Light Bedroom Main - Light in initialization for 5.608923746s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:19] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:19] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:19] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:19] 💡 HueLight Bedroom Main - Light was successfully updated (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 
DEBU[2024/28/10 00:02:19] 💡 Light Bedroom Main - Adjusting light state to 1295K at 15% brightness (Initialization) 
DEBU[2024/28/10 00:02:19] 🤖 Light Bedroom Main - Updated light state. Awaiting transition... 
DEBU[2024/28/10 00:02:20] 💡 Light Bedroom Main - Light in initialization for 6.823214951s (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38) 
DEBU[2024/28/10 00:02:20] 💡 HueLight Bedroom Main - Color temperature has changed! CurrentColorTemperature: 438, TargetColorTemperatur: 454 (2200K) 
DEBU[2024/28/10 00:02:20] 💡 Light Bedroom Main - Adjusted color temperature to light capability of 2200K 
DEBU[2024/28/10 00:02:20] 💡 HueLight Bedroom Main - Setting light state to 2200K and 15% brightness (TargetColorTemperature: 454, CurrentColorTemperature: 438, TargetColor: [0.506 0.415], CurrentColor: [], TargetBrightness: 38, CurrentBrightness: 38, TransitionTime: 4) 

... repeating indefinitely, regardless of what I do to the light
haasn commented 1 month ago

The issue appears to be when setting color temperature values lower than what the light "actually" supports.

If I change the CCT of the current time slot to something like 4200, it works fine:

DEBU[2024/28/10 00:20:42] 💡 Light Bedroom Main - Light in initialization for 1.151873877s (TargetColorTemperature: 238, CurrentColorTemperature: 238, TargetColor: [0.374 0.379], CurrentColor: [], TargetBrightness: 35, CurrentBrightness: 35) 
DEBU[2024/28/10 00:20:43] 💡 Light Bedroom Main - Light in initialization for 2.167553719s (TargetColorTemperature: 238, CurrentColorTemperature: 238, TargetColor: [0.374 0.379], CurrentColor: [], TargetBrightness: 35, CurrentBrightness: 35) 
DEBU[2024/28/10 00:20:44] 💡 Light Bedroom Main - Light in initialization for 3.183106289s (TargetColorTemperature: 238, CurrentColorTemperature: 238, TargetColor: [0.374 0.379], CurrentColor: [], TargetBrightness: 35, CurrentBrightness: 35) 
DEBU[2024/28/10 00:20:44] 💡 Light Bedroom Main - Ending initialization phase after 3.183176031s 

It would appear to me that this light is simply misbehaving / misreporting its actual Kelvin range. If I bump the lower kelvin numbers to 2280 (experimentally determined), initialization succeeds.

haasn commented 1 month ago

For what it's worth, I tried updating the software firmware version. It now reports:

DEBU[2024/28/10 00:30:44] 💡 Light Hallway Main - Initialization complete. Identified as Color temperature light (ModelID: 929003099101, Version: 1.122.2) 
DEBU[2024/28/10 00:30:44] 💡 Light Entrance - Initialization complete. Identified as Color temperature light (ModelID: 929003099201, Version: 1.122.2) 
DEBU[2024/28/10 00:30:44] 💡 Light Bedroom Main - Initialization complete. Identified as Color temperature light (ModelID: 929003823401, Version: 1.93.7) 

But the exact same issue persists. It seems that this is a Hue bug with the new Tento Ambient White panels.

haasn commented 1 month ago

Now everything works:

diff --git a/huelight.go b/huelight.go
index c20609a..d9be6e9 100644
--- a/huelight.go
+++ b/huelight.go
@@ -63,7 +63,9 @@ func (light *HueLight) initialize(attr hue.LightAttributes) {
        light.SupportsXYColor = containsString(lightsSupportingXYColor, attr.Type)

        // set minimum color temperature depending on type
-       if attr.Type == "Color temperature light" {
+        if attr.ModelId == "929003823401" {
+               light.MinimumColorTemperature = 2280
+       } else if attr.Type == "Color temperature light" {
                light.MinimumColorTemperature = 2200
        } else if light.SupportsXYColor {
                light.MinimumColorTemperature = 1000

I don't know what to do about this. Do I have a faulty light? Or are the new Tento panels just a pile of 💩 ?