Add modern configuration for template light and switch (#38332)

This commit is contained in:
Petro31 2025-04-02 18:11:37 -04:00 committed by GitHub
parent 0a8d96f088
commit 1bb66e92f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,12 +50,14 @@ For other types, please see the specific pages:
- [Alarm control panel](/integrations/alarm_control_panel.template/)
- [Cover](/integrations/cover.template/)
- [Fan](/integrations/fan.template/)
- [Light](/integrations/light.template/)
- [Lock](/integrations/lock.template/)
- [Switch](/integrations/switch.template/)
- [Vacuum](/integrations/vacuum.template/)
- [Weather](/integrations/weather.template/)
For Legacy types, please see the specific pages:
- [Light](/integrations/light.template/)
- [Switch](/integrations/switch.template/)
{% include integrations/config_flow.md %}
{% important %}
@ -74,7 +76,7 @@ Entities (sensors, binary sensors, buttons, images, numbers, and selections) are
_For old sensor/binary sensor configuration format, [see below](#legacy-binary-sensor-configuration-format)._
### State-based template binary sensors, buttons, images, numbers, selects, sensors, and weathers
### State-based template binary sensors, buttons, images, lights, numbers, selects, sensors, switches, and weathers
Template entities will by default update as soon as any of the referenced data in the template updates.
@ -307,6 +309,125 @@ image:
required: false
type: boolean
default: true
light:
description: List of your lights.
required: true
type: map
keys:
state:
description: Defines a template to set the state of the light. If not defined, the switch will optimistically assume all commands are successful.
required: false
type: template
default: optimistic
level:
description: Defines a template to get the brightness of the light.
required: false
type: template
default: optimistic
temperature:
description: Defines a template to get the color temperature of the light.
required: false
type: template
default: optimistic
hs:
description: Defines a template to get the HS color of the light. Must render a tuple (hue, saturation).
required: false
type: template
default: optimistic
rgb:
description: Defines a template to get the RGB color of the light. Must render a tuple or a list (red, green, blue).
required: false
type: template
default: optimistic
rgbw:
description: Defines a template to get the RGBW color of the light. Must render a tuple or a list (red, green, blue, white).
required: false
type: template
default: optimistic
rgbww:
description: Defines a template to get the RGBWW color of the light. Must render a tuple or a list (red, green, blue, cold white, warm white).
required: false
type: template
default: optimistic
supports_transition:
description: Defines a template to get if the light supports transition. Should return a boolean value (True/False). If this value is `True`, the transition parameter in a `turn on` or `turn off` call will be passed as a named parameter `transition` in either of the scripts.
required: false
type: template
default: false
effect_list:
description: Defines a template to get the list of supported effects. Must render a list.
required: inclusive
type: template
default: optimistic
effect:
description: Defines a template to get the effect of the light.
required: inclusive
type: template
default: optimistic
min_mireds:
description: Defines a template to get the minimum mired value of the light.
required: false
type: template
default: optimistic
max_mireds:
description: Defines a template to get the maximum mired value of the light.
required: false
type: template
default: optimistic
turn_on:
description: Defines an action to run when the light is turned on. May receive the variables `brightness` and/or `transition`.
required: true
type: action
turn_off:
description: Defines an action to run when the light is turned off. May receive the variable `transition`.
required: true
type: action
set_level:
description: Defines an action to run when the light is given a brightness command. The script will only be called if the `turn_on` call only ha brightness, and optionally transition. Receives variables `brightness` and, optionally, `transition`.
required: false
type: action
set_temperature:
description: Defines an action to run when the light is given a color temperature command. Receives variable `color_temp`. May also receive variables `brightness` and/or `transition`.
required: false
type: action
set_hs:
description: "Defines an action to run when the light is given a hs color command. Available variables: `hs` as a tuple, `h` and `s`"
required: false
type: action
set_rgb:
description: "Defines an action to run when the light is given an RGB color command. Available variables: `rgb` as a tuple, `r`, `g` and `b`."
required: false
type: action
set_rgbw:
description: "Defines an action to run when the light is given an RGBW color command. Available variables: `rgbw` as a tuple, `rgb` as a tuple, `r`, `g`, `b` and `w`."
required: false
type: action
set_rgbww:
description: "Defines an action to run when the light is given an RGBWW color command. Available variables: `rgbww` as a tuple, `rgb` as a tuple, `r`, `g` `b`, `cw` and `ww`."
required: false
type: action
set_effect:
description: Defines an action to run when the light is given an effect command. Receives the variable `effect`. May also receive the variables `brightness`, and/or `transition`.
required: inclusive
type: action
switch:
description: List of switches
required: true
type: map
keys:
state:
description: Defines a template to set the state of the switch. If not defined, the switch will optimistically assume all commands are successful.
required: false
type: template
default: optimistic
turn_on:
description: Defines an action or list of actions to run when the switch is turned on.
required: true
type: action
turn_off:
description: Defines an action or list of actions to run when the switch is turned off.
required: true
type: action
weather:
description: List of weather entities
required: true
@ -392,7 +513,7 @@ weather:
description: Unit for precipitation output. Valid options are km, mi, ft, m, cm, mm, in, yd.
required: false
type: string
"[all sensor, binary sensor, button, image, number, select, weather entities]":
"[all sensor, binary sensor, button, image, light, number, select, switch, weather entities]":
description: Fields that can be used above for sensors, binary sensors, buttons, numbers, and selects.
required: false
type: map