Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adapt_brightness_until_sleep and adapt_color_temp_until_sleep #566

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4e1c769
initial commit
th3w1zard1 Apr 10, 2023
b53a5af
add new config option
th3w1zard1 Apr 10, 2023
553265a
Merge b53a5aff68f06501c41f64070e2cc9f327f250c2 into e30b7debe551e58cc…
th3w1zard1 Apr 10, 2023
2d74a31
Update README.md, strings.json, and services.yaml
github-actions[bot] Apr 10, 2023
840aab6
add `adapt_color_temp_until_sleep`
th3w1zard1 Apr 10, 2023
bca9f1b
Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijh…
th3w1zard1 Apr 10, 2023
06dd2a5
Revert "Merge branch 'adjust_adapt_until_sleep' of https://github.com…
th3w1zard1 Apr 10, 2023
a4d5f86
autofill workaround
th3w1zard1 Apr 10, 2023
7f952e0
Merge a4d5f861ff2e0cadcfc33bef1a78dc3c840cdbcc into e30b7debe551e58cc…
th3w1zard1 Apr 10, 2023
3b61f49
Update README.md, strings.json, and services.yaml
github-actions[bot] Apr 10, 2023
e7e266b
Update const.py
th3w1zard1 Apr 10, 2023
e46d867
Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijh…
th3w1zard1 Apr 10, 2023
4509c0a
Merge e46d867854ad0ebe000868f4e82be03111104d7a into e30b7debe551e58cc…
th3w1zard1 Apr 10, 2023
91d6065
Update README.md, strings.json, and services.yaml
github-actions[bot] Apr 10, 2023
7244a5f
Update const.py
th3w1zard1 Apr 10, 2023
c4b5067
Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijh…
th3w1zard1 Apr 10, 2023
bc39f5e
Merge c4b5067b052527cefbfb014a1dd024550865434e into e30b7debe551e58cc…
th3w1zard1 Apr 10, 2023
78395ee
Update README.md, strings.json, and services.yaml
github-actions[bot] Apr 10, 2023
5b927db
Merge branch 'main' into adjust_adapt_until_sleep
th3w1zard1 Apr 10, 2023
b1a27d6
Merge branch 'main' into adjust_adapt_until_sleep
basnijholt Apr 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | `True` | `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 |
Expand Down
18 changes: 17 additions & 1 deletion custom_components/adaptive_lighting/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,22 @@
)
DOCS[CONF_ADAPT_UNTIL_SLEEP] = (
"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] = (
Expand Down Expand Up @@ -231,6 +245,8 @@ def int_between(min_int, max_int):
(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)),
Expand Down
4 changes: 3 additions & 1 deletion custom_components/adaptive_lighting/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. 💡",
Expand Down
11 changes: 10 additions & 1 deletion custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
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,
Expand Down Expand Up @@ -896,6 +898,8 @@ def _set_changeable_settings(
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],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1576,6 +1582,9 @@ def calc_brightness_pct(self, percent: float, is_sleep: bool) -> float:
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
Expand All @@ -1588,7 +1597,7 @@ def calc_color_temp_kelvin(self, percent: float) -> int:
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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/adaptive_lighting/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. 💡",
Expand Down