mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-14 15:54:04 +02:00
Compare commits
20 commits
main
...
adjust_ada
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1a27d6689 |
||
|
|
5b927dbb02 |
||
|
|
78395eea65 | ||
|
|
bc39f5e977 |
||
|
|
c4b5067b05 | ||
|
|
7244a5f483 | ||
|
|
91d606586f | ||
|
|
4509c0a0f1 |
||
|
|
e46d867854 | ||
|
|
e7e266b5a1 | ||
|
|
3b61f49fb3 | ||
|
|
7f952e0658 |
||
|
|
a4d5f861ff | ||
|
|
06dd2a5c9a | ||
|
|
bca9f1bd3d | ||
|
|
840aab6158 | ||
|
|
2d74a313bb | ||
|
|
553265a1e8 |
||
|
|
b53a5aff68 | ||
|
|
4e1c769feb |
5 changed files with 67 additions and 35 deletions
|
|
@ -91,14 +91,16 @@ The YAML and frontend configuration methods support all of the options listed be
|
||||||
<!-- START_OUTPUT -->
|
<!-- START_OUTPUT -->
|
||||||
<!-- THIS CONTENT IS AUTOMATICALLY GENERATED -->
|
<!-- THIS CONTENT IS AUTOMATICALLY GENERATED -->
|
||||||
| Variable name | Description | Default | Type |
|
| Variable name | Description | Default | Type |
|
||||||
|:-------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------|:-------------------------------------|
|
|:-------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------|:-------------------------------------|
|
||||||
| `lights` | List of light entity_ids to be controlled (may be empty). 🌟 | `[]` | list of `entity_id`s |
|
| `lights` | List of light entity_ids to be controlled (may be empty). 🌟 | `[]` | list of `entity_id`s |
|
||||||
| `prefer_rgb_color` | Whether to prefer RGB color adjustment over light color temperature when possible. 🌈 | `False` | `bool` |
|
| `prefer_rgb_color` | Whether to prefer RGB color adjustment over light color temperature when possible. 🌈 | `False` | `bool` |
|
||||||
| `include_config_in_attributes` | Show all options as attributes on the switch in Home Assistant when set to `true`. 📝 | `False` | `bool` |
|
| `include_config_in_attributes` | Show all options as attributes on the switch in Home Assistant when set to `true`. 📝 | `False` | `bool` |
|
||||||
| `initial_transition` | Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️ | `1` | `float` 0-6553 |
|
| `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 |
|
| `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` | 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` | This option ignores the current state of the sleep switch. 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` |
|
| `interval` | Frequency to adapt the lights, in seconds. 🔄 | `90` | `int > 0` |
|
||||||
| `min_brightness` | Minimum brightness percentage. 💡 | `1` | `int` 1-100 |
|
| `min_brightness` | Minimum brightness percentage. 💡 | `1` | `int` 1-100 |
|
||||||
| `max_brightness` | Maximum brightness percentage. 💡 | `100` | `int` 1-100 |
|
| `max_brightness` | Maximum brightness percentage. 💡 | `100` | `int` 1-100 |
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,24 @@ CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP = (
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
DOCS[CONF_ADAPT_UNTIL_SLEEP] = (
|
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, "
|
"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
|
CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0
|
||||||
DOCS[CONF_ADAPT_DELAY] = (
|
DOCS[CONF_ADAPT_DELAY] = (
|
||||||
|
|
@ -231,6 +246,8 @@ VALIDATION_TUPLES = [
|
||||||
(CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION),
|
(CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION),
|
||||||
(CONF_TRANSITION, DEFAULT_TRANSITION, VALID_TRANSITION),
|
(CONF_TRANSITION, DEFAULT_TRANSITION, VALID_TRANSITION),
|
||||||
(CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP, bool),
|
(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_INTERVAL, DEFAULT_INTERVAL, cv.positive_int),
|
||||||
(CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS, int_between(1, 100)),
|
(CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS, int_between(1, 100)),
|
||||||
(CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS, int_between(1, 100)),
|
(CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS, int_between(1, 100)),
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@
|
||||||
"initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️",
|
"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. 😴",
|
"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": "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: This option ignores the current state of the sleep switch. 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. 🔄",
|
"interval": "interval: Frequency to adapt the lights, in seconds. 🔄",
|
||||||
"min_brightness": "min_brightness: Minimum brightness percentage. 💡",
|
"min_brightness": "min_brightness: Minimum brightness percentage. 💡",
|
||||||
"max_brightness": "max_brightness: Maximum brightness percentage. 💡",
|
"max_brightness": "max_brightness: Maximum brightness percentage. 💡",
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ from .const import (
|
||||||
ATTR_ADAPT_BRIGHTNESS,
|
ATTR_ADAPT_BRIGHTNESS,
|
||||||
ATTR_ADAPT_COLOR,
|
ATTR_ADAPT_COLOR,
|
||||||
ATTR_TURN_ON_OFF_LISTENER,
|
ATTR_TURN_ON_OFF_LISTENER,
|
||||||
|
CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP,
|
||||||
|
CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP,
|
||||||
CONF_ADAPT_DELAY,
|
CONF_ADAPT_DELAY,
|
||||||
CONF_ADAPT_UNTIL_SLEEP,
|
CONF_ADAPT_UNTIL_SLEEP,
|
||||||
CONF_AUTORESET_CONTROL,
|
CONF_AUTORESET_CONTROL,
|
||||||
|
|
@ -933,6 +935,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
||||||
self._sun_light_settings = SunLightSettings(
|
self._sun_light_settings = SunLightSettings(
|
||||||
name=self._name,
|
name=self._name,
|
||||||
astral_location=location,
|
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],
|
adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP],
|
||||||
max_brightness=data[CONF_MAX_BRIGHTNESS],
|
max_brightness=data[CONF_MAX_BRIGHTNESS],
|
||||||
max_color_temp=data[CONF_MAX_COLOR_TEMP],
|
max_color_temp=data[CONF_MAX_COLOR_TEMP],
|
||||||
|
|
@ -1472,6 +1476,8 @@ class SunLightSettings:
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
astral_location: astral.Location
|
astral_location: astral.Location
|
||||||
|
adapt_brightness_until_sleep: bool
|
||||||
|
adapt_color_temp_until_sleep: bool
|
||||||
adapt_until_sleep: bool
|
adapt_until_sleep: bool
|
||||||
max_brightness: int
|
max_brightness: int
|
||||||
max_color_temp: int
|
max_color_temp: int
|
||||||
|
|
@ -1612,6 +1618,9 @@ class SunLightSettings:
|
||||||
return self.sleep_brightness
|
return self.sleep_brightness
|
||||||
if percent > 0:
|
if percent > 0:
|
||||||
return self.max_brightness
|
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
|
delta_brightness = self.max_brightness - self.min_brightness
|
||||||
percent = 1 + percent
|
percent = 1 + percent
|
||||||
return (delta_brightness * percent) + self.min_brightness
|
return (delta_brightness * percent) + self.min_brightness
|
||||||
|
|
@ -1624,7 +1633,7 @@ class SunLightSettings:
|
||||||
return 5 * round(ct / 5) # round to nearest 5
|
return 5 * round(ct / 5) # round to nearest 5
|
||||||
if percent == 0 or not self.adapt_until_sleep:
|
if percent == 0 or not self.adapt_until_sleep:
|
||||||
return self.min_color_temp
|
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)
|
delta = abs(self.min_color_temp - self.sleep_color_temp)
|
||||||
ct = (delta * abs(1 + percent)) + self.sleep_color_temp
|
ct = (delta * abs(1 + percent)) + self.sleep_color_temp
|
||||||
return 5 * round(ct / 5) # round to nearest 5
|
return 5 * round(ct / 5) # round to nearest 5
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,9 @@
|
||||||
"initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️",
|
"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. 😴",
|
"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": "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: This option ignores the current state of the sleep switch. 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. 🔄",
|
"interval": "interval: Frequency to adapt the lights, in seconds. 🔄",
|
||||||
"min_brightness": "min_brightness: Minimum brightness percentage. 💡",
|
"min_brightness": "min_brightness: Minimum brightness percentage. 💡",
|
||||||
"max_brightness": "max_brightness: Maximum brightness percentage. 💡",
|
"max_brightness": "max_brightness: Maximum brightness percentage. 💡",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue