diff --git a/apps/controllerx/const.py b/apps/controllerx/const.py index 96496e50..5af3758a 100644 --- a/apps/controllerx/const.py +++ b/apps/controllerx/const.py @@ -12,14 +12,19 @@ class Light: TOGGLE = "toggle" RELEASE = "release" ON_FULL_BRIGHTNESS = "on_full_brightness" + ON_FULL_WHITE_VALUE = "on_full_white_value" ON_FULL_COLOR_TEMP = "on_full_color_temp" ON_MIN_BRIGHTNESS = "on_min_brightness" + ON_MIN_WHITE_VALUE = "on_min_white_value" ON_MIN_COLOR_TEMP = "on_min_color_temp" SET_HALF_BRIGHTNESS = "set_half_brightness" + SET_HALF_WHITE_VALUE = "set_half_white_value" SET_HALF_COLOR_TEMP = "set_half_color_temp" SYNC = "sync" CLICK_BRIGHTNESS_UP = "click_brightness_up" CLICK_BRIGHTNESS_DOWN = "click_brightness_down" + CLICK_WHITE_VALUE_UP = "click_white_value_up" + CLICK_WHITE_VALUE_DOWN = "click_white_value_down" CLICK_COLOR_UP = "click_color_up" CLICK_COLOR_DOWN = "click_color_down" CLICK_COLOR_TEMP_UP = "click_colortemp_up" @@ -29,6 +34,9 @@ class Light: HOLD_BRIGHTNESS_UP = "hold_brightness_up" HOLD_BRIGHTNESS_DOWN = "hold_brightness_down" HOLD_BRIGHTNESS_TOGGLE = "hold_brightness_toggle" + HOLD_WHITE_VALUE_UP = "hold_white_value_up" + HOLD_WHITE_VALUE_DOWN = "hold_white_value_down" + HOLD_WHITE_VALUE_TOGGLE = "hold_white_value_toggle" HOLD_COLOR_UP = "hold_color_up" HOLD_COLOR_DOWN = "hold_color_down" HOLD_COLOR_TOGGLE = "hold_color_toggle" diff --git a/apps/controllerx/core/type/light_controller.py b/apps/controllerx/core/type/light_controller.py index 1c932faf..2a1e9799 100644 --- a/apps/controllerx/core/type/light_controller.py +++ b/apps/controllerx/core/type/light_controller.py @@ -11,6 +11,8 @@ DEFAULT_AUTOMATIC_STEPS = 10 DEFAULT_MIN_BRIGHTNESS = 1 DEFAULT_MAX_BRIGHTNESS = 254 +DEFAULT_MIN_WHITE_VALUE = 1 +DEFAULT_MAX_WHITE_VALUE = 254 DEFAULT_MIN_COLOR_TEMP = 153 DEFAULT_MAX_COLOR_TEMP = 500 DEFAULT_TRANSITION = 300 @@ -37,6 +39,7 @@ class LightController(TypeController, ReleaseHoldController): """ ATTRIBUTE_BRIGHTNESS = "brightness" + ATTRIBUTE_WHITE_VALUE = "white_value" # With the following attribute, it will select color_temp or xy_color, depending on the light. ATTRIBUTE_COLOR = "color" ATTRIBUTE_COLOR_TEMP = "color_temp" @@ -81,6 +84,8 @@ async def initialize(self) -> None: automatic_steps = self.args.get("automatic_steps", DEFAULT_AUTOMATIC_STEPS) self.min_brightness = self.args.get("min_brightness", DEFAULT_MIN_BRIGHTNESS) self.max_brightness = self.args.get("max_brightness", DEFAULT_MAX_BRIGHTNESS) + self.min_white_value = self.args.get("min_white_value", DEFAULT_MIN_WHITE_VALUE) + self.max_white_value = self.args.get("max_white_value", DEFAULT_MAX_WHITE_VALUE) self.min_color_temp = self.args.get("min_color_temp", DEFAULT_MIN_COLOR_TEMP) self.max_color_temp = self.args.get("max_color_temp", DEFAULT_MAX_COLOR_TEMP) self.transition = self.args.get("transition", DEFAULT_TRANSITION) @@ -89,6 +94,9 @@ async def initialize(self) -> None: LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper( self.min_brightness, self.max_brightness, manual_steps ), + LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper( + self.min_white_value, self.max_white_value, manual_steps + ), LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper( self.min_color_temp, self.max_color_temp, manual_steps ), @@ -98,6 +106,9 @@ async def initialize(self) -> None: LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper( self.min_brightness, self.max_brightness, automatic_steps ), + LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper( + self.min_white_value, self.max_white_value, automatic_steps + ), LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper( self.min_color_temp, self.max_color_temp, automatic_steps ), @@ -127,6 +138,10 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping: self.on_full, LightController.ATTRIBUTE_BRIGHTNESS, ), + Light.ON_FULL_WHITE_VALUE: ( + self.on_full, + LightController.ATTRIBUTE_WHITE_VALUE, + ), Light.ON_FULL_COLOR_TEMP: ( self.on_full, LightController.ATTRIBUTE_COLOR_TEMP, @@ -135,6 +150,10 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping: self.on_min, LightController.ATTRIBUTE_BRIGHTNESS, ), + Light.ON_MIN_WHITE_VALUE: ( + self.on_min, + LightController.ATTRIBUTE_WHITE_VALUE, + ), Light.ON_MIN_COLOR_TEMP: ( self.on_min, LightController.ATTRIBUTE_COLOR_TEMP, @@ -144,6 +163,11 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping: LightController.ATTRIBUTE_BRIGHTNESS, 0.5, ), + Light.SET_HALF_WHITE_VALUE: ( + self.set_value, + LightController.ATTRIBUTE_WHITE_VALUE, + 0.5, + ), Light.SET_HALF_COLOR_TEMP: ( self.set_value, LightController.ATTRIBUTE_COLOR_TEMP, @@ -160,6 +184,16 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping: LightController.ATTRIBUTE_BRIGHTNESS, Stepper.DOWN, ), + Light.CLICK_WHITE_VALUE_UP: ( + self.click, + LightController.ATTRIBUTE_WHITE_VALUE, + Stepper.UP, + ), + Light.CLICK_WHITE_VALUE_DOWN: ( + self.click, + LightController.ATTRIBUTE_WHITE_VALUE, + Stepper.DOWN, + ), Light.CLICK_COLOR_UP: ( self.click, LightController.ATTRIBUTE_COLOR, @@ -205,6 +239,21 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping: LightController.ATTRIBUTE_BRIGHTNESS, Stepper.TOGGLE, ), + Light.HOLD_WHITE_VALUE_UP: ( + self.hold, + LightController.ATTRIBUTE_WHITE_VALUE, + Stepper.UP, + ), + Light.HOLD_WHITE_VALUE_DOWN: ( + self.hold, + LightController.ATTRIBUTE_WHITE_VALUE, + Stepper.DOWN, + ), + Light.HOLD_WHITE_VALUE_TOGGLE: ( + self.hold, + LightController.ATTRIBUTE_WHITE_VALUE, + Stepper.TOGGLE, + ), Light.HOLD_COLOR_UP: ( self.hold, LightController.ATTRIBUTE_COLOR, @@ -359,6 +408,7 @@ async def get_value_attribute( return 0 elif ( attribute == LightController.ATTRIBUTE_BRIGHTNESS + or attribute == LightController.ATTRIBUTE_WHITE_VALUE or attribute == LightController.ATTRIBUTE_COLOR_TEMP ): value = await self.get_entity_state(self.light["name"], attribute) diff --git a/docs/others/custom-controllers.md b/docs/others/custom-controllers.md index 88ba4b6b..62d7947f 100644 --- a/docs/others/custom-controllers.md +++ b/docs/others/custom-controllers.md @@ -11,39 +11,47 @@ Class: `CustomLightController` This controller lets you map controller events with predefined light actions. This is a [Light controller](/controllerx/start/type-configuration#light-controller), so it inheritance all its parameters. This is the list of predefined actions that can be mapped as a value in the key-value map from the `mapping` attribute. -| value | description | -| ------------------------ | --------------------------------------------------------------------------------------------------------------------------- | -| `on` | It turns on the light | -| `off` | It turns off the light | -| `toggle` | It toggles the light | -| `release` | It stops `hold` actions | -| `on_full_brightness` | It puts the brightness to the maximum value | -| `on_full_color_temp` | It puts the color temp to the maximum value | -| `on_min_brightness` | It puts the brightness to the minimum value | -| `on_min_color_temp` | It puts the color temp to the minimum value | -| `set_half_brightness` | It sets the brightness to 50% | -| `set_half_color_temp` | It sets the color temp to 50% | -| `sync` | It syncs the light(s) to full brightness and white colour or 2700K (370 mireds) | -| `click_brightness_up` | It brights up accordingly with the `manual_steps` attribute | -| `click_brightness_down` | It brights down accordingly with the `manual_steps` attribute | -| `click_color_up` | It turns the color up accordingly with the `manual_steps` attribute | -| `click_color_down` | It turns the color down accordingly with the `manual_steps` attribute | -| `click_colortemp_up` | It turns the color temp up accordingly with the `manual_steps` attribute | -| `click_colortemp_down` | It turns the color temp down accordingly with the `manual_steps` attribute | -| `click_xycolor_up` | It turns the xy color up accordingly with the `manual_steps` attribute | -| `click_xycolor_down` | It turns the xy color down accordingly with the `manual_steps` attribute | -| `hold_brightness_up` | It brights up until release accordingly with the `automatic_steps` attribute | -| `hold_brightness_down` | It brights down until release accordingly with the `automatic_steps` attribute | -| `hold_brightness_toggle` | It brights up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | -| `hold_color_up` | It turns the color up until release accordingly with the `automatic_steps` attribute | -| `hold_color_down` | It turns the color down until release accordingly with the `automatic_steps` attribute | -| `hold_color_toggle` | It turns the color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | -| `hold_colortemp_up` | It turns the color temp up until release accordingly with the `automatic_steps` attribute | -| `hold_colortemp_down` | It turns the color temp down until release accordingly with the `automatic_steps` attribute | -| `hold_colortemp_toggle` | It turns the color temp up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | -| `hold_xycolor_up` | It turns the xy color up until release accordingly with the `automatic_steps` attribute | -| `hold_xycolor_down` | It turns the xy color down until release accordingly with the `automatic_steps` attribute | -| `hold_xycolor_toggle` | It turns the xy color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | +| value | description | +| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | +| `on` | It turns on the light | +| `off` | It turns off the light | +| `toggle` | It toggles the light | +| `release` | It stops `hold` actions | +| `on_full_brightness` | It puts the brightness to the maximum value | +| `on_full_white_value` | It puts the white value to the maximum value | +| `on_full_color_temp` | It puts the color temp to the maximum value | +| `on_min_brightness` | It puts the brightness to the minimum value | +| `on_min_white_value` | It puts the white value to the minimum value | +| `on_min_color_temp` | It puts the color temp to the minimum value | +| `set_half_brightness` | It sets the brightness to 50% | +| `set_half_white_value` | It sets the white value to 50% | +| `set_half_color_temp` | It sets the color temp to 50% | +| `sync` | It syncs the light(s) to full brightness and white colour or 2700K (370 mireds) | +| `click_brightness_up` | It brights up accordingly with the `manual_steps` attribute | +| `click_brightness_down` | It brights down accordingly with the `manual_steps` attribute | +| `click_white_value_up` | It turns the white value up accordingly with the `manual_steps` attribute | +| `click_white_value_down` | It turns the white value down accordingly with the `manual_steps` attribute | +| `click_color_up` | It turns the color up accordingly with the `manual_steps` attribute | +| `click_color_down` | It turns the color down accordingly with the `manual_steps` attribute | +| `click_colortemp_up` | It turns the color temp up accordingly with the `manual_steps` attribute | +| `click_colortemp_down` | It turns the color temp down accordingly with the `manual_steps` attribute | +| `click_xycolor_up` | It turns the xy color up accordingly with the `manual_steps` attribute | +| `click_xycolor_down` | It turns the xy color down accordingly with the `manual_steps` attribute | +| `hold_brightness_up` | It brights up until release accordingly with the `automatic_steps` attribute | +| `hold_brightness_down` | It brights down until release accordingly with the `automatic_steps` attribute | +| `hold_brightness_toggle` | It brights up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | +| `hold_white_value_up` | It turns the white value up until release accordingly with the `automatic_steps` attribute | +| `hold_white_value_down` | It turns the white value down until release accordingly with the `automatic_steps` attribute | +| `hold_white_value_toggle` | It turns the white value up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | +| `hold_color_up` | It turns the color up until release accordingly with the `automatic_steps` attribute | +| `hold_color_down` | It turns the color down until release accordingly with the `automatic_steps` attribute | +| `hold_color_toggle` | It turns the color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | +| `hold_colortemp_up` | It turns the color temp up until release accordingly with the `automatic_steps` attribute | +| `hold_colortemp_down` | It turns the color temp down until release accordingly with the `automatic_steps` attribute | +| `hold_colortemp_toggle` | It turns the color temp up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | +| `hold_xycolor_up` | It turns the xy color up until release accordingly with the `automatic_steps` attribute | +| `hold_xycolor_down` | It turns the xy color down until release accordingly with the `automatic_steps` attribute | +| `hold_xycolor_toggle` | It turns the xy color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click | #### Example of CustomLightController diff --git a/docs/start/type-configuration.md b/docs/start/type-configuration.md index c8b2d933..760520e4 100644 --- a/docs/start/type-configuration.md +++ b/docs/start/type-configuration.md @@ -17,19 +17,21 @@ This controller allows the devices to control light or group of lights. This all - Smooth increase/decrease (holding button) of brightness and color - Color loop changing if the light supports xy color. -| key | type | value | description | -| ---------------------------- | -------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `light`\* | string \| dictionary | `group.livingroom_lights` or `light.kitchen` | The light (or group of lights) you want to control | -| `manual_steps` | int | 10 | Number of steps to go from min to max when clicking. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | -| `automatic_steps` | int | 10 | Number of steps to go from min to max when smoothing. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | -| `min_brightness` | int | 1 | The minimum brightness to set to the light. | -| `max_brightness` | int | 255 | The maximum brightness to set to the light. | -| `min_color_temp` | int | 153 | The minimum color temperature to set to the light. | -| `max_color_temp` | int | 500 | The maximum color temperature to set to the light. | -| `smooth_power_on` | boolean | False | If `True` the associated light will be set to minimum brightness when brightness up is clicked or hold ad light is off. | -| `delay` | int | [Controller specific](/controllerx/controllers) | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behavior. | -| `transition` | int | 300 | Time in milliseconds that takes the light to transition from one state to another one. | -| `add_transition` | boolean | True | If `true` adds transition if supported, otherwise it does not adds the `transition` attribute. | +| key | type | value | description | +| ---------------------------- | -------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `light`\* | string \| dictionary | `group.livingroom_lights` or `light.kitchen` | The light (or group of lights) you want to control | +| `manual_steps` | int | 10 | Number of steps to go from min to max when clicking. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | +| `automatic_steps` | int | 10 | Number of steps to go from min to max when smoothing. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | +| `min_brightness` | int | 1 | The minimum brightness to set to the light. | +| `max_brightness` | int | 255 | The maximum brightness to set to the light. | +| `min_white_value` | int | 1 | The minimum white value to set to the light. | +| `max_white_value` | int | 255 | The maximum white value to set to the light. | +| `min_color_temp` | int | 153 | The minimum color temperature to set to the light. | +| `max_color_temp` | int | 500 | The maximum color temperature to set to the light. | +| `smooth_power_on` | boolean | False | If `True` the associated light will be set to minimum brightness when brightness up is clicked or hold ad light is off. | +| `delay` | int | [Controller specific](/controllerx/controllers) | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behavior. | +| `transition` | int | 300 | Time in milliseconds that takes the light to transition from one state to another one. | +| `add_transition` | boolean | True | If `true` adds transition if supported, otherwise it does not adds the `transition` attribute. | | `add_transition_turn_toggle` | boolean | True | If `false` does not add transition when turning on/off or toggling, otherwise it adds the `transition` attribute to the call. See [FAQ #6](/controllerx/faq#6-light-is-not-turning-on-to-the-previous-brightness) for a further explanation on the use of this parameter. | _\* Required fields_