diff --git a/README.md b/README.md index 9ba7cc03..7e3e6ca8 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,9 @@ The YAML and frontend configuration methods support all of the options listed be | `initial_transition` | Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️ | `1` | `float` 0-6553 | | `sleep_transition` | Duration of transition when "sleep mode" is toggled in seconds. 😴 | `1` | `float` 0-6553 | | `transition` | Duration of transition when lights change, in seconds. 🕑 | `45` | `float` 0-6553 | -| `transition_until_sleep` | When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning to these values after sunset. 🌙 | `False` | `bool` | +| `transition_until_sleep` | When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning color temperature to these values after sunset. 🌙 | `False` | `bool` | +| `adapt_brightness_until_sleep` | Only active when `transition_until_sleep` is true. | `False` | `bool` | +| `adapt_color_temp_until_sleep` | Only active when `transition_until_sleep` is true. | `True` | `bool` | | `interval` | Frequency to adapt the lights, in seconds. 🔄 | `90` | `int > 0` | | `min_brightness` | Minimum brightness percentage. 💡 | `1` | `int` 1-100 | | `max_brightness` | Maximum brightness percentage. 💡 | `100` | `int` 1-100 | diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 64620927..ab7b5772 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -154,9 +154,24 @@ CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP = ( False, ) DOCS[CONF_ADAPT_UNTIL_SLEEP] = ( + "This option ignores the current state of the sleep switch. " "When enabled, Adaptive Lighting will treat sleep settings as the minimum, " - "transitioning to these values after sunset. 🌙" + "transitioning color temperature to these values after sunset. 🌙" ) +CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, DEFAULT_ADAPT_COLOR_TEMP_UNTIL_SLEEP = ( + "adapt_color_temp_until_sleep", + True, +) +DOCS[ + CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP +] = "Only active when `transition_until_sleep` is true." +CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP = ( + "adapt_brightness_until_sleep", + False, +) +DOCS[ + CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP +] = "Only active when `transition_until_sleep` is true." CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0 DOCS[CONF_ADAPT_DELAY] = ( @@ -231,6 +246,8 @@ VALIDATION_TUPLES = [ (CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION), (CONF_TRANSITION, DEFAULT_TRANSITION, VALID_TRANSITION), (CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP, bool), + (CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP, bool), + (CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, DEFAULT_ADAPT_COLOR_TEMP_UNTIL_SLEEP, bool), (CONF_INTERVAL, DEFAULT_INTERVAL, cv.positive_int), (CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS, int_between(1, 100)), (CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS, int_between(1, 100)), diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 54af5e11..69994ece 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -25,7 +25,9 @@ "initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️", "sleep_transition": "sleep_transition: Duration of transition when \"sleep mode\" is toggled in seconds. 😴", "transition": "transition: Duration of transition when lights change, in seconds. 🕑", - "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning to these values after sunset. 🌙", + "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning color temperature to these values after sunset. 🌙", + "adapt_brightness_until_sleep": "adapt_brightness_until_sleep: Only active when `transition_until_sleep` is true.", + "adapt_color_temp_until_sleep": "adapt_color_temp_until_sleep: Only active when `transition_until_sleep` is true.", "interval": "interval: Frequency to adapt the lights, in seconds. 🔄", "min_brightness": "min_brightness: Minimum brightness percentage. 💡", "max_brightness": "max_brightness: Maximum brightness percentage. 💡", diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 98747a17..37f40188 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -97,6 +97,8 @@ from .const import ( ATTR_ADAPT_BRIGHTNESS, ATTR_ADAPT_COLOR, ATTR_TURN_ON_OFF_LISTENER, + CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, + CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, CONF_ADAPT_DELAY, CONF_ADAPT_UNTIL_SLEEP, CONF_AUTORESET_CONTROL, @@ -896,6 +898,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._sun_light_settings = SunLightSettings( name=self._name, astral_location=location, + adapt_brightness_until_sleep=data[CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP], + adapt_color_temp_until_sleep=data[CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP], adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP], max_brightness=data[CONF_MAX_BRIGHTNESS], max_color_temp=data[CONF_MAX_COLOR_TEMP], @@ -1436,6 +1440,8 @@ class SunLightSettings: name: str astral_location: astral.Location + adapt_brightness_until_sleep: bool + adapt_color_temp_until_sleep: bool adapt_until_sleep: bool max_brightness: int max_color_temp: int @@ -1576,6 +1582,9 @@ class SunLightSettings: return self.sleep_brightness if percent > 0: return self.max_brightness + if self.adapt_until_sleep and self.adapt_brightness_until_sleep and percent < 0: + delta_brightness = abs(self.min_brightness - self.sleep_brightness) + return (delta_brightness * abs(1 + percent)) + self.sleep_brightness delta_brightness = self.max_brightness - self.min_brightness percent = 1 + percent return (delta_brightness * percent) + self.min_brightness @@ -1588,7 +1597,7 @@ class SunLightSettings: return 5 * round(ct / 5) # round to nearest 5 if percent == 0 or not self.adapt_until_sleep: return self.min_color_temp - if self.adapt_until_sleep and percent < 0: + if self.adapt_until_sleep and self.adapt_color_temp_until_sleep and percent < 0: delta = abs(self.min_color_temp - self.sleep_color_temp) ct = (delta * abs(1 + percent)) + self.sleep_color_temp return 5 * round(ct / 5) # round to nearest 5 diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index 38fb7b0e..710b3321 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -26,7 +26,9 @@ "initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️", "sleep_transition": "sleep_transition: Duration of transition when \"sleep mode\" is toggled in seconds. 😴", "transition": "transition: Duration of transition when lights change, in seconds. 🕑", - "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning to these values after sunset. 🌙", + "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning color temperature to these values after sunset. 🌙", + "adapt_brightness_until_sleep": "adapt_brightness_until_sleep: Only active when `transition_until_sleep` is true.", + "adapt_color_temp_until_sleep": "adapt_color_temp_until_sleep: Only active when `transition_until_sleep` is true.", "interval": "interval: Frequency to adapt the lights, in seconds. 🔄", "min_brightness": "min_brightness: Minimum brightness percentage. 💡", "max_brightness": "max_brightness: Maximum brightness percentage. 💡",