From ff6494240d0b3c05b08af66346f880cadca27b54 Mon Sep 17 00:00:00 2001 From: Mark Niemeyer <64665067+Mark-Niemeyer@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:47:50 +0100 Subject: [PATCH 1/3] add a delay between sending of commands when using separate_turn_on_commands --- custom_components/adaptive_lighting/const.py | 2 ++ custom_components/adaptive_lighting/strings.json | 1 + custom_components/adaptive_lighting/switch.py | 4 +++- custom_components/adaptive_lighting/translations/de.json | 1 + custom_components/adaptive_lighting/translations/en.json | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 36c84a2d..62c71fa2 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -62,6 +62,7 @@ CONF_TURN_ON_LIGHTS = "turn_on_lights" CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0 TURNING_OFF_DELAY = 5 +CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY = "send_split_delay", 0 def int_between(min_int, max_int): @@ -108,6 +109,7 @@ VALIDATION_TUPLES = [ (CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool), (CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool), (CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS, bool), + (CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY, int_between(0, 10000)), (CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY, int_between(0, 10000)), ] diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 754cb9bc..74099754 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -30,6 +30,7 @@ "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).", + "send_split_delay": "send_split_delay: wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly.", "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'", "sleep_rgb_color": "sleep_rgb_color, in RGB", diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index ff100a44..500154be 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -112,6 +112,7 @@ from .const import ( CONF_MIN_SUNSET_TIME, CONF_ONLY_ONCE, CONF_PREFER_RGB_COLOR, + CONF_SEND_SPLIT_DELAY, CONF_SEPARATE_TURN_ON_COMMANDS, CONF_SLEEP_BRIGHTNESS, CONF_SLEEP_COLOR_TEMP, @@ -574,6 +575,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._take_over_control = data[CONF_TAKE_OVER_CONTROL] self._transition = data[CONF_TRANSITION] self._adapt_delay = data[CONF_ADAPT_DELAY] + self._send_split_delay = data[CONF_SEND_SPLIT_DELAY] _loc = get_astral_location(self.hass) if isinstance(_loc, tuple): # Astral v2.2 @@ -872,7 +874,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): if len(service_datas) == 2: transition = service_datas[0].get(ATTR_TRANSITION) if transition is not None: - await asyncio.sleep(transition) + await asyncio.sleep(transition + self._send_split_delay / 1000.0) await turn_on(service_datas[1]) async def _update_attrs_and_maybe_adapt_lights( diff --git a/custom_components/adaptive_lighting/translations/de.json b/custom_components/adaptive_lighting/translations/de.json index a68df8e4..cc427138 100644 --- a/custom_components/adaptive_lighting/translations/de.json +++ b/custom_components/adaptive_lighting/translations/de.json @@ -31,6 +31,7 @@ "only_once": "only_once, passe die Lichter nur beim Einschalten an", "prefer_rgb_color": "prefer_rgb_color, nutze 'rgb_color' vor 'color_temp', wenn möglich", "separate_turn_on_commands": "separate_turn_on_commands, für jedes Attribut (Farbe, Helligkeit usw.) in 'light.turn_on' werden separate Befehle gesendet. Wird für manche Leuchtmittel benötigt.", + "send_split_delay": "send_split_delay: Wartezeit zwischen dem Senden der Befehle (Millisekunden), wenn separate_turn_on_commands genutzt wird. Kann helfen, wenn die Leuchtmittel die separaten Befehle nicht korrekt umsetzen.", "sleep_brightness": "sleep_brightness, Schlafhelligkeit in %", "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, nutze 'rgb_color' oder 'color_temp'", "sleep_rgb_color": "sleep_rgb_color, in RGB", diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index 1318a0bb..be556ec0 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -31,6 +31,7 @@ "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).", + "send_split_delay": "send_split_delay: wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly.", "sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)", "sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'", "sleep_rgb_color": "sleep_rgb_color, in RGB", From bf82beab8287f682c324d9c39af6d0a32f23c702 Mon Sep 17 00:00:00 2001 From: Mark Niemeyer <64665067+Mark-Niemeyer@users.noreply.github.com> Date: Sun, 27 Nov 2022 19:26:47 +0100 Subject: [PATCH 2/3] add send_split_delay to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 65bf5e35..6eef09af 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ adaptive_lighting: | `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 | +| `send_split_delay` | Wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly. | False | 0 | integer | | `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: From 97bb2cf3debcba39cbfab76e27357dba531681da Mon Sep 17 00:00:00 2001 From: Mark Niemeyer <64665067+Mark-Niemeyer@users.noreply.github.com> Date: Sun, 27 Nov 2022 19:29:10 +0100 Subject: [PATCH 3/3] use send_split_delay also when no transition is used --- custom_components/adaptive_lighting/switch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 500154be..e2dee95f 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -874,7 +874,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): if len(service_datas) == 2: transition = service_datas[0].get(ATTR_TRANSITION) if transition is not None: - await asyncio.sleep(transition + self._send_split_delay / 1000.0) + await asyncio.sleep(transition) + await asyncio.sleep(self._send_split_delay / 1000.0) await turn_on(service_datas[1]) async def _update_attrs_and_maybe_adapt_lights(