From 7d10259bc8ba1a39bac07af7544ad1b41d63ed72 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:01:21 -0700 Subject: [PATCH 01/11] Use RGB selector --- custom_components/adaptive_lighting/const.py | 7 +++++++ custom_components/adaptive_lighting/switch.py | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 6d144ee2..e860fa74 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -1,5 +1,6 @@ """Constants for the Adaptive Lighting integration.""" from homeassistant.components.light import VALID_TRANSITION +from homeassistant.helpers import selector import homeassistant.helpers.config_validation as cv import voluptuous as vol @@ -30,6 +31,7 @@ CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS = ( ) CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS = "sleep_brightness", 1 CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP = "sleep_color_temp", 1000 +CONF_SLEEP_RGB_COLOR, DEFAULT_SLEEP_RGB_COLOR = "sleep_rgb_color", [255, 56, 0] CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET = "sunrise_offset", 0 CONF_SUNRISE_TIME = "sunrise_time" CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET = "sunset_offset", 0 @@ -73,6 +75,11 @@ VALIDATION_TUPLES = [ (CONF_MAX_COLOR_TEMP, DEFAULT_MAX_COLOR_TEMP, int_between(1000, 10000)), (CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS, int_between(1, 100)), (CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP, int_between(1000, 10000)), + ( + CONF_SLEEP_RGB_COLOR, + DEFAULT_SLEEP_RGB_COLOR, + selector.ColorRGBSelector(selector.ColorRGBSelectorConfig()), + ), (CONF_SUNRISE_TIME, NONE_STR, str), (CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int), (CONF_SUNSET_TIME, NONE_STR, str), diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 922d1e1d..bfea3b48 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -113,6 +113,7 @@ from .const import ( CONF_SEPARATE_TURN_ON_COMMANDS, CONF_SLEEP_BRIGHTNESS, CONF_SLEEP_COLOR_TEMP, + CONF_SLEEP_RGB_COLOR, CONF_SLEEP_TRANSITION, CONF_SUNRISE_OFFSET, CONF_SUNRISE_TIME, @@ -587,6 +588,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): min_color_temp=data[CONF_MIN_COLOR_TEMP], sleep_brightness=data[CONF_SLEEP_BRIGHTNESS], sleep_color_temp=data[CONF_SLEEP_COLOR_TEMP], + sleep_rgb_color=data[CONF_SLEEP_RGB_COLOR], sunrise_offset=data[CONF_SUNRISE_OFFSET], sunrise_time=data[CONF_SUNRISE_TIME], sunset_offset=data[CONF_SUNSET_OFFSET], @@ -1074,6 +1076,7 @@ class SunLightSettings: min_color_temp: int sleep_brightness: int sleep_color_temp: int + sleep_rgb_color: tuple[int, int, int] sunrise_offset: datetime.timedelta | None sunrise_time: datetime.time | None sunset_offset: datetime.timedelta | None @@ -1192,10 +1195,8 @@ class SunLightSettings: percent = 1 + percent return (delta_brightness * percent) + self.min_brightness - def calc_color_temp_kelvin(self, percent: float, is_sleep: bool) -> float: + def calc_color_temp_kelvin(self, percent: float) -> float: """Calculate the color temperature in Kelvin.""" - if is_sleep: - return self.sleep_color_temp if percent > 0: delta = self.max_color_temp - self.min_color_temp return (delta * percent) + self.min_color_temp @@ -1214,11 +1215,15 @@ class SunLightSettings: else self.calc_percent(0) ) brightness_pct = self.calc_brightness_pct(percent, is_sleep) - color_temp_kelvin = self.calc_color_temp_kelvin(percent, is_sleep) + if is_sleep: + color_temp_kelvin = self.sleep_color_temp + rgb_color: tuple[float, float, float] = self.sleep_rgb_color + else: + color_temp_kelvin = self.calc_color_temp_kelvin(percent) + rgb_color: tuple[float, float, float] = color_temperature_to_rgb( + color_temp_kelvin + ) color_temp_mired: float = color_temperature_kelvin_to_mired(color_temp_kelvin) - rgb_color: tuple[float, float, float] = color_temperature_to_rgb( - color_temp_kelvin - ) xy_color: tuple[float, float] = color_RGB_to_xy(*rgb_color) hs_color: tuple[float, float] = color_xy_to_hs(*xy_color) return { From d3dce3166ed265fa49912af925ed1ba801493e8b Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:05:31 -0700 Subject: [PATCH 02/11] Add strings and options --- custom_components/adaptive_lighting/const.py | 5 +++++ custom_components/adaptive_lighting/strings.json | 2 ++ 2 files changed, 7 insertions(+) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index e860fa74..fc767408 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -32,6 +32,10 @@ CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS = ( CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS = "sleep_brightness", 1 CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP = "sleep_color_temp", 1000 CONF_SLEEP_RGB_COLOR, DEFAULT_SLEEP_RGB_COLOR = "sleep_rgb_color", [255, 56, 0] +CONF_SLEEP_RGB_OR_COLOR_TEMP, DEFAULT_SLEEP_RGB_OR_COLOR_TEMP = ( + "sleep_rgb_or_color_temp", + "color_temp", +) CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET = "sunrise_offset", 0 CONF_SUNRISE_TIME = "sunrise_time" CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET = "sunset_offset", 0 @@ -80,6 +84,7 @@ VALIDATION_TUPLES = [ DEFAULT_SLEEP_RGB_COLOR, selector.ColorRGBSelector(selector.ColorRGBSelectorConfig()), ), + (CONF_SLEEP_RGB_OR_COLOR_TEMP, DEFAULT_SLEEP_RGB_OR_COLOR_TEMP, bool), (CONF_SUNRISE_TIME, NONE_STR, str), (CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int), (CONF_SUNSET_TIME, NONE_STR, str), diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 5a185ea3..c20335bc 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -31,7 +31,9 @@ "prefer_rgb_color": "prefer_rgb_color, use 'rgb_color' over 'color_temp' when possible", "separate_turn_on_commands": "separate_turn_on_commands, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.", "sleep_brightness": "sleep_brightness, in %", + "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb' or 'color_temp'", "sleep_color_temp": "sleep_color_temp, in Kelvin", + "sleep_rgb_color": "sleep_rgb_color, in RGB", "sunrise_offset": "sunrise_offset, in +/- seconds", "sunrise_time": "sunrise_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunrise time at your location)", "sunset_offset": "sunset_offset, in +/- seconds", From 29a4b8a33c36afd6711c92a3c2a82de2a667b378 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:15:24 -0700 Subject: [PATCH 03/11] Add selection between RGB and color temp --- custom_components/adaptive_lighting/const.py | 15 ++++++++++++++- custom_components/adaptive_lighting/switch.py | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index fc767408..596c29d4 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -1,4 +1,5 @@ """Constants for the Adaptive Lighting integration.""" + from homeassistant.components.light import VALID_TRANSITION from homeassistant.helpers import selector import homeassistant.helpers.config_validation as cv @@ -84,7 +85,19 @@ VALIDATION_TUPLES = [ DEFAULT_SLEEP_RGB_COLOR, selector.ColorRGBSelector(selector.ColorRGBSelectorConfig()), ), - (CONF_SLEEP_RGB_OR_COLOR_TEMP, DEFAULT_SLEEP_RGB_OR_COLOR_TEMP, bool), + ( + CONF_SLEEP_RGB_OR_COLOR_TEMP, + DEFAULT_SLEEP_RGB_OR_COLOR_TEMP, + selector.SelectSelector( + selector.SelectSelectorConfig( + options=["color_temp", "rgb"], + multiple=False, + mode=selector.SelectSelectorMode.DROPDOWN, + ), + ) + # vol.Any(vol.Literal("color_temp"), vol.Literal("rgb")), + # cv.multi_select(["color_temp", "rgb_color"]), + ), (CONF_SUNRISE_TIME, NONE_STR, str), (CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int), (CONF_SUNSET_TIME, NONE_STR, str), diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index bfea3b48..95c52e55 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -12,7 +12,7 @@ from datetime import timedelta import functools import logging import math -from typing import Any +from typing import Any, Literal import astral from homeassistant.components.light import ( @@ -114,6 +114,7 @@ from .const import ( CONF_SLEEP_BRIGHTNESS, CONF_SLEEP_COLOR_TEMP, CONF_SLEEP_RGB_COLOR, + CONF_SLEEP_RGB_OR_COLOR_TEMP, CONF_SLEEP_TRANSITION, CONF_SUNRISE_OFFSET, CONF_SUNRISE_TIME, @@ -589,6 +590,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): sleep_brightness=data[CONF_SLEEP_BRIGHTNESS], sleep_color_temp=data[CONF_SLEEP_COLOR_TEMP], sleep_rgb_color=data[CONF_SLEEP_RGB_COLOR], + sleep_rgb_or_color_temp=data[CONF_SLEEP_RGB_OR_COLOR_TEMP], sunrise_offset=data[CONF_SUNRISE_OFFSET], sunrise_time=data[CONF_SUNRISE_TIME], sunset_offset=data[CONF_SUNSET_OFFSET], @@ -1075,6 +1077,7 @@ class SunLightSettings: min_brightness: int min_color_temp: int sleep_brightness: int + sleep_rgb_or_color_temp: Literal["color_temp", "rgb"] sleep_color_temp: int sleep_rgb_color: tuple[int, int, int] sunrise_offset: datetime.timedelta | None From 37304f3d3546fda6dbcfa737344d1abda3ad6d7d Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:32:57 -0700 Subject: [PATCH 04/11] test --- custom_components/adaptive_lighting/config_flow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index d0f0bf2d..0f078263 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -99,6 +99,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow): options_schema = {} for name, default, validation in VALIDATION_TUPLES: + if name == "sleep_rgb_or_color_temp": + continue key = vol.Optional(name, default=conf.options.get(name, default)) value = to_replace.get(name, validation) options_schema[key] = value From f500a3758efc5dd49543d45d0fe505e1d624d9a8 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:44:07 -0700 Subject: [PATCH 05/11] Update to translations and cleanup --- .../adaptive_lighting/config_flow.py | 2 - custom_components/adaptive_lighting/const.py | 6 +-- .../adaptive_lighting/strings.json | 40 +++++++++---------- custom_components/adaptive_lighting/switch.py | 2 +- .../adaptive_lighting/translations/en.json | 4 +- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 0f078263..d0f0bf2d 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -99,8 +99,6 @@ class OptionsFlowHandler(config_entries.OptionsFlow): options_schema = {} for name, default, validation in VALIDATION_TUPLES: - if name == "sleep_rgb_or_color_temp": - continue key = vol.Optional(name, default=conf.options.get(name, default)) value = to_replace.get(name, validation) options_schema[key] = value diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 596c29d4..08b47154 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -90,13 +90,11 @@ VALIDATION_TUPLES = [ DEFAULT_SLEEP_RGB_OR_COLOR_TEMP, selector.SelectSelector( selector.SelectSelectorConfig( - options=["color_temp", "rgb"], + options=["color_temp", "rgb_color"], multiple=False, mode=selector.SelectSelectorMode.DROPDOWN, ), - ) - # vol.Any(vol.Literal("color_temp"), vol.Literal("rgb")), - # cv.multi_select(["color_temp", "rgb_color"]), + ), ), (CONF_SUNRISE_TIME, NONE_STR, str), (CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int), diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index c20335bc..0d1491dd 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -20,28 +20,28 @@ "description": "All settings for a Adaptive Lighting component. The option names correspond with the YAML settings. No options are shown if you have this entry defined in YAML.", "data": { "lights": "lights", - "initial_transition": "initial_transition, when lights go 'off' to 'on'", - "sleep_transition": "sleep_transition, when 'sleep_state' changes", - "interval": "interval, time between switch updates in seconds", - "max_brightness": "max_brightness, in %", - "max_color_temp": "max_color_temp, in Kelvin", - "min_brightness": "min_brightness, in %", - "min_color_temp": "min_color_temp, in Kelvin", - "only_once": "only_once, only adapt the lights when turning them on", - "prefer_rgb_color": "prefer_rgb_color, use 'rgb_color' over 'color_temp' when possible", - "separate_turn_on_commands": "separate_turn_on_commands, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.", - "sleep_brightness": "sleep_brightness, in %", + "initial_transition": "initial_transition: When lights turn 'off' to 'on'. (seconds)", + "sleep_transition": "sleep_transition: When 'sleep_state' changes. (seconds)", + "interval": "interval: Time between switch updates. (seconds)", + "max_brightness": "max_brightness: Highest brightness of lights during a cycle. (%)", + "max_color_temp": "max_color_temp: Coldest hue of the color temperature cycle. (Kelvin)", + "min_brightness": "min_brightness: Lowest brightness of lights during a cycle. (%)", + "min_color_temp": "min_color_temp, Warmest hue of the color temperature cycle. (Kelvin)", + "only_once": "only_once: Only adapt the lights when turning them on.", + "prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.", + "separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).", + "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb' or 'color_temp'", - "sleep_color_temp": "sleep_color_temp, in Kelvin", "sleep_rgb_color": "sleep_rgb_color, in RGB", - "sunrise_offset": "sunrise_offset, in +/- seconds", - "sunrise_time": "sunrise_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunrise time at your location)", - "sunset_offset": "sunset_offset, in +/- seconds", - "sunset_time": "sunset_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunset time at your location)", - "take_over_control": "take_over_control, if anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.", - "detect_non_ha_changes": "detect_non_ha_changes, detects all >5% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)", - "transition": "transition, in seconds", - "adapt_delay": "Wait time between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering." + "sleep_color_temp": "sleep_color_temp: Color temperature setting for Sleep Mode. (Kelvin)", + "sunrise_offset": "sunrise_offset: How long before(-) or after(+) to define the sunrise point of the cycle (+/- seconds)", + "sunrise_time": "sunrise_time: Manual override of the sunrise time, if 'None', it uses the actual sunrise time at your location (HH:MM:SS)", + "sunset_offset": "sunset_offset: How long before(-) or after(+) to define the sunset point of the cycle (+/- seconds)", + "sunset_time": "sunset_time: Manual override of the sunset time, if 'None', it uses the actual sunrise time at your location (HH:MM:SS)", + "take_over_control": "take_over_control: If anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.", + "detect_non_ha_changes": "detect_non_ha_changes: detects all >10% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)", + "transition": "Transition time when applying a change to the lights (seconds)", + "adapt_delay": "adapt_delay: wait time between light turn on (seconds), and Adaptive Lights applying changes to the light state. May avoid flickering." } } }, diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 95c52e55..1108dd80 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1077,7 +1077,7 @@ class SunLightSettings: min_brightness: int min_color_temp: int sleep_brightness: int - sleep_rgb_or_color_temp: Literal["color_temp", "rgb"] + sleep_rgb_or_color_temp: Literal["color_temp", "rgb_color"] sleep_color_temp: int sleep_rgb_color: tuple[int, int, int] sunrise_offset: datetime.timedelta | None diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index ecc6eff8..189d68e6 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -32,6 +32,8 @@ "prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.", "separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).", "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", + "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb' or 'color_temp'", + "sleep_rgb_color": "sleep_rgb_color, in RGB", "sleep_color_temp": "sleep_color_temp: Color temperature setting for Sleep Mode. (Kelvin)", "sunrise_offset": "sunrise_offset: How long before(-) or after(+) to define the sunrise point of the cycle (+/- seconds)", "sunrise_time": "sunrise_time: Manual override of the sunrise time, if 'None', it uses the actual sunrise time at your location (HH:MM:SS)", @@ -40,7 +42,7 @@ "take_over_control": "take_over_control: If anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.", "detect_non_ha_changes": "detect_non_ha_changes: detects all >10% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)", "transition": "Transition time when applying a change to the lights (seconds)", - "adapt_delay": "Wait time between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering." + "adapt_delay": "adapt_delay: wait time between light turn on (seconds), and Adaptive Lights applying changes to the light state. May avoid flickering." } } }, From 8965e6becf02cf18c9483f49aa420164cdb99bef Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:53:27 -0700 Subject: [PATCH 06/11] Ugly first implementation --- custom_components/adaptive_lighting/switch.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 1108dd80..0e166abe 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -816,6 +816,18 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): color_temp_mired = self._settings["color_temp_mired"] color_temp_mired = max(min(color_temp_mired, max_mireds), min_mireds) service_data[ATTR_COLOR_TEMP] = color_temp_mired + if ( + self.sleep_mode_switch.is_on + and self._sun_light_settings.sleep_rgb_or_color_temp == "rgb_color" + ): + # Special case: if we're in sleep mode and the user has chosen to use RGB color + # in sleep mode, we use this + if "color" not in features: + raise ValueError( + "sleep_rgb_or_color_temp is set to 'rgb_color' however it is " + "not supported by the light." + ) + service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"] elif "color" in features and adapt_color: service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"] From 4a6c966a5353094af80eccee73cd923e20976159 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 22:54:37 -0700 Subject: [PATCH 07/11] Change order --- custom_components/adaptive_lighting/const.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 08b47154..b800015b 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -79,12 +79,6 @@ VALIDATION_TUPLES = [ (CONF_MIN_COLOR_TEMP, DEFAULT_MIN_COLOR_TEMP, int_between(1000, 10000)), (CONF_MAX_COLOR_TEMP, DEFAULT_MAX_COLOR_TEMP, int_between(1000, 10000)), (CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS, int_between(1, 100)), - (CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP, int_between(1000, 10000)), - ( - CONF_SLEEP_RGB_COLOR, - DEFAULT_SLEEP_RGB_COLOR, - selector.ColorRGBSelector(selector.ColorRGBSelectorConfig()), - ), ( CONF_SLEEP_RGB_OR_COLOR_TEMP, DEFAULT_SLEEP_RGB_OR_COLOR_TEMP, @@ -96,6 +90,12 @@ VALIDATION_TUPLES = [ ), ), ), + (CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP, int_between(1000, 10000)), + ( + CONF_SLEEP_RGB_COLOR, + DEFAULT_SLEEP_RGB_COLOR, + selector.ColorRGBSelector(selector.ColorRGBSelectorConfig()), + ), (CONF_SUNRISE_TIME, NONE_STR, str), (CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int), (CONF_SUNSET_TIME, NONE_STR, str), From c78d1bec752f807d8726d2941e0336d42402c705 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 23:08:53 -0700 Subject: [PATCH 08/11] Fix setting RGB light in sleep --- custom_components/adaptive_lighting/switch.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 0e166abe..e3688a62 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -806,29 +806,24 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): brightness = round(255 * self._settings["brightness_pct"] / 100) service_data[ATTR_BRIGHTNESS] = brightness + sleep_rgb = ( + self.sleep_mode_switch.is_on + and self._sun_light_settings.sleep_rgb_or_color_temp == "rgb_color" + ) if ( "color_temp" in features and adapt_color and not (prefer_rgb_color and "color" in features) + and not (sleep_rgb and "color" in features) ): + _LOGGER.debug("%s: Setting color_temp of light %s", self._name, light) attributes = self.hass.states.get(light).attributes min_mireds, max_mireds = attributes["min_mireds"], attributes["max_mireds"] color_temp_mired = self._settings["color_temp_mired"] color_temp_mired = max(min(color_temp_mired, max_mireds), min_mireds) service_data[ATTR_COLOR_TEMP] = color_temp_mired - if ( - self.sleep_mode_switch.is_on - and self._sun_light_settings.sleep_rgb_or_color_temp == "rgb_color" - ): - # Special case: if we're in sleep mode and the user has chosen to use RGB color - # in sleep mode, we use this - if "color" not in features: - raise ValueError( - "sleep_rgb_or_color_temp is set to 'rgb_color' however it is " - "not supported by the light." - ) - service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"] elif "color" in features and adapt_color: + _LOGGER.debug("%s: Setting rgb_color of light %s", self._name, light) service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"] context = context or self.create_context("adapt_lights") From f685f5b58b1c0da7f9550f1eb6b29ef271db2e6d Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 23:17:13 -0700 Subject: [PATCH 09/11] Update README --- README.md | 80 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 2fe5fd06..aa955ee2 100644 --- a/README.md +++ b/README.md @@ -47,30 +47,32 @@ adaptive_lighting: ``` ### Options -| option | description | required | default | type | -|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|-----------|---------| -| name | The name to use when displaying this switch. | False | default | string | -| lights | List of light entities for Adaptive Lighting to control (may be empty). | False | list | [] | -| prefer_rgb_color | Whether to use RGB color adjustment instead of native light color temperature. | False | False | boolean | -| initial_transition | How long the first transition is when the lights go from `off` to `on`. | False | 1 | time | -| sleep_transition | How long the transition is when when "sleep mode" is toggled | False | 1 | time | -| transition | How long the transition is when the lights change, in seconds. | False | 45 | integer | -| interval | How often to adapt the lights, in seconds. | False | 90 | integer | -| min_brightness | The minimum percent of brightness to set the lights to. | False | 1 | integer | -| max_brightness | The maximum percent of brightness to set the lights to. | False | 100 | integer | -| min_color_temp | The warmest color temperature to set the lights to, in Kelvin. | False | 2000 | integer | -| max_color_temp | The coldest color temperature to set the lights to, in Kelvin. | False | 5500 | integer | -| sleep_brightness | Brightness of lights while the sleep mode is enabled. | False | 1 | integer | -| sleep_color_temp | Color temperature of lights while the sleep mode is enabled. | False | 1000 | integer | -| sunrise_time | Override the sunrise time with a fixed time. | False | time | | -| sunrise_offset | Change the sunrise time with a positive or negative offset. | False | 0 | time | -| sunset_time | Override the sunset time with a fixed time. | False | time | | -| sunset_offset | Change the sunset time with a positive or negative offset. | False | 0 | time | -| only_once | Whether to keep adapting the lights (false) or to only adapt the lights as soon as they are turned on (true). | False | False | boolean | -| take_over_control | If another source calls `light.turn_on` while the lights are on and being adapted, disable Adaptive Lighting. | False | True | boolean | -| detect_non_ha_changes | Whether to detect state changes and stop adapting lights, even not from `light.turn_on`. Needs `take_over_control` to be enabled. Note that by enabling this option, it calls 'homeassistant.update_entity' every 'interval'! | False | False | boolean | -| separate_turn_on_commands | Whether to use separate `light.turn_on` calls for color and brightness, needed for some types of lights | False | False | boolean | -| adapt_delay | Wait time in seconds between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering. | False | 0 | integer | +| option | description | required | default | type | +| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------------- | ------- | +| name | The name to use when displaying this switch. | False | default | string | +| lights | List of light entities for Adaptive Lighting to control (may be empty). | False | list | [] | +| prefer_rgb_color | Whether to use RGB color adjustment instead of native light color temperature. | False | False | boolean | +| initial_transition | How long the first transition is when the lights go from `off` to `on`. | False | 1 | time | +| sleep_transition | How long the transition is when when "sleep mode" is toggled | False | 1 | time | +| transition | How long the transition is when the lights change, in seconds. | False | 45 | integer | +| interval | How often to adapt the lights, in seconds. | False | 90 | integer | +| min_brightness | The minimum percent of brightness to set the lights to. | False | 1 | integer | +| max_brightness | The maximum percent of brightness to set the lights to. | False | 100 | integer | +| min_color_temp | The warmest color temperature to set the lights to, in Kelvin. | False | 2000 | integer | +| max_color_temp | The coldest color temperature to set the lights to, in Kelvin. | False | 5500 | integer | +| sleep_brightness | Brightness of lights while the sleep mode is enabled. | False | 1 | integer | +| sleep_rgb_or_color_temp | Use either 'rgb_color' or 'color_temp' when in sleep mode. | False | 'color_temp' | string | +| sleep_rgb_color | List of three numbers between 0-255, indicating the RGB color in sleep mode (only used when sleep_rgb_or_color_temp is 'rgb_color'). | False | `[255, 56, 0]` | list | +| sleep_color_temp | Color temperature of lights while the sleep mode is enabled (only used when sleep_rgb_or_color_temp is 'color_temp'). | False | 1000 | integer | +| sunrise_time | Override the sunrise time with a fixed time. | False | time | | +| sunrise_offset | Change the sunrise time with a positive or negative offset. | False | 0 | time | +| sunset_time | Override the sunset time with a fixed time. | False | time | | +| sunset_offset | Change the sunset time with a positive or negative offset. | False | 0 | time | +| only_once | Whether to keep adapting the lights (false) or to only adapt the lights as soon as they are turned on (true). | False | False | boolean | +| take_over_control | If another source calls `light.turn_on` while the lights are on and being adapted, disable Adaptive Lighting. | False | True | boolean | +| detect_non_ha_changes | Whether to detect state changes and stop adapting lights, even not from `light.turn_on`. Needs `take_over_control` to be enabled. Note that by enabling this option, it calls 'homeassistant.update_entity' every 'interval'! | False | False | boolean | +| separate_turn_on_commands | Whether to use separate `light.turn_on` calls for color and brightness, needed for some types of lights | False | False | boolean | +| adapt_delay | Wait time in seconds between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering. | False | 0 | integer | Full example: @@ -101,25 +103,25 @@ adaptive_lighting: ### Services -`adaptive_lighting.apply` applies Adaptive Lighting settings to lights on demand. +`adaptive_lighting.**apply**` applies Adaptive Lighting settings to lights on demand. -| Service data attribute | Optional | Description | -|---------------------------|----------|-------------------------------------------------------------------------| -| `entity_id` | no | The `entity_id` of the switch with the settings to apply. | -| `lights` | no | A light (or list of lights) to apply the settings to. | -| `transition` | yes | The number of seconds for the transition. | -| `adapt_brightness` | yes | Whether to change the brightness of the light or not. | -| `adapt_color` | yes | Whether to adapt the color on supporting lights. | -| `prefer_rgb_color` | yes | Whether to prefer RGB color adjustment over of native light color temperature when possible. | -| `turn_on_lights` | yes | Whether to turn on lights that are currently off. | +| Service data attribute | Optional | Description | +| ---------------------- | -------- | -------------------------------------------------------------------------------------------- | +| `entity_id` | no | The `entity_id` of the switch with the settings to apply. | +| `lights` | no | A light (or list of lights) to apply the settings to. | +| `transition` | yes | The number of seconds for the transition. | +| `adapt_brightness` | yes | Whether to change the brightness of the light or not. | +| `adapt_color` | yes | Whether to adapt the color on supporting lights. | +| `prefer_rgb_color` | yes | Whether to prefer RGB color adjustment over of native light color temperature when possible. | +| `turn_on_lights` | yes | Whether to turn on lights that are currently off. | `adaptive_lighting.set_manual_control` can mark (or unmark) whether a light is "manually controlled", meaning that when a light has `manual_control`, the light is not adapted. -| Service data attribute | Optional | Description | -|------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------| -| `entity_id` | no | The `entity_id` of the switch in which to (un)mark the light as being "manually controlled". | -| `lights` | yes | entity_id(s) of lights, if not specified, all lights in the switch are selected. | -| `manual_control` | yes | Whether to add ('true') or remove ('false') the light from the 'manual_control' list, default: true | +| Service data attribute | Optional | Description | +| ---------------------- | -------- | --------------------------------------------------------------------------------------------------- | +| `entity_id` | no | The `entity_id` of the switch in which to (un)mark the light as being "manually controlled". | +| `lights` | yes | entity_id(s) of lights, if not specified, all lights in the switch are selected. | +| `manual_control` | yes | Whether to add ('true') or remove ('false') the light from the 'manual_control' list, default: true | ## Automation examples From 9ed588816ce946781cbb7ae19c734cd1f836da8c Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 23:17:38 -0700 Subject: [PATCH 10/11] Fix translations --- custom_components/adaptive_lighting/strings.json | 2 +- custom_components/adaptive_lighting/translations/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 0d1491dd..0755cca8 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -31,7 +31,7 @@ "prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.", "separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).", "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", - "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb' or 'color_temp'", + "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'", "sleep_rgb_color": "sleep_rgb_color, in RGB", "sleep_color_temp": "sleep_color_temp: Color temperature setting for Sleep Mode. (Kelvin)", "sunrise_offset": "sunrise_offset: How long before(-) or after(+) to define the sunrise point of the cycle (+/- seconds)", diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index 189d68e6..d4070a30 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -32,7 +32,7 @@ "prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.", "separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).", "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", - "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb' or 'color_temp'", + "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'", "sleep_rgb_color": "sleep_rgb_color, in RGB", "sleep_color_temp": "sleep_color_temp: Color temperature setting for Sleep Mode. (Kelvin)", "sunrise_offset": "sunrise_offset: How long before(-) or after(+) to define the sunrise point of the cycle (+/- seconds)", From 07a0dec20381f25f0079678af3fcb97c8755f6ae Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 31 Aug 2022 23:19:40 -0700 Subject: [PATCH 11/11] Bump to 1.1.0 --- custom_components/adaptive_lighting/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index 529820f3..5b852cb4 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -6,7 +6,7 @@ "config_flow": true, "dependencies": [], "codeowners": ["@basnijholt", "@RubenKelevra"], - "version": "1.0.20", + "version": "1.1.0", "requirements": [], "iot_class": "calculated" }