I wanted to create a blueprint that would support turning on/off one light or many lights, as well as have some intelligence around the lights’ capabilities. For example, only attempt to use a color_temp value if all of the lights support that feature.
The first part was defining a blueprint input (standard stuff):
target_light:
description: >-
Light or group of lights that should turn on in response to occupancy.
Note that color temperature is supported, but only if ALL target lights
support that feature, and the actual temperature may be limited by
the lowest maximum value of the lights in the target group.
name: Light
selector:
target:
entity:
domain: light
Then I created a variable to store the entity or entities:
variables:
target_light: !input target_light
# Make the entities variable always a list, even
# if there is only one light in the group
target_light_entities: >-
{%
if target_light.entity_id is iterable
and target_light.entity_id is not string
and target_light.entity_id is not mapping
%}
{{ target_light.entity_id }}
{% else %}
{{ [target_light.entity_id] }}
{% endif %}
Then you can do things like determine if some of the lights don’t support color:
# Loop through all the target lights...
# If any don't support color_temp,
# then we don't have color support for this group of lights
has_color_support: >-
{% set ns = namespace(is_all_color_lights=true) %}
{% for entity in target_light_entities %}
{% set supported_features = state_attr(entity, 'supported_features') %}
{% if
supported_features|int
|bitwise_and(SUPPORTED_FEATURES_COLOR_TEMP_BIT)
== 0
%}
{% set ns.is_all_color_lights = false %}
{% endif%}
{% endfor %}
{{ ns.is_all_color_lights }}
and determine the maximum allowable color_temp value for the lights:
# Lowest value of max_mireds for all target lights is
# the largest legal value for the group
target_lights_max_color_temp: >-
{% if not has_color_support %}
{{ NO_COLOR_TEMP }}
{% else %}
{% set ns = namespace(lowest_max_color_temp=MAX_COLOR_TEMP) %}
{% for entity in target_light_entities %}
{% set ns.lowest_max_color_temp =
[
state_attr(entity, 'max_mireds')|int,
ns.lowest_max_color_temp
]
|min
%}
{% endfor %}
{{ ns.lowest_max_color_temp }}
{% endif %}
Then in your actions, you can use the standard stuff:
sequence:
- service: light.turn_on
target: !input target_light
data:
brightness_pct: "{{ light_brightness_pct }}"
color_temp: "{{ light_color_temp }}"
transition: "{{ light_transition }}"
Hope that helps.