Hi,
I have a group of 8 spotlights under ‘group.lv_lights’. I have created a For Loop to go through each entity of the group. I want to be able to adjust the brightness of only bulb that is turned ON. For the bulb that is OFF, the for loop are suppose to skip it so that it will not be adjusted on the brightness. Currently I’m having error in the for loop section which I’m not sure how to correctly… Appreciate any help out there. Thanks
# --------------------------------------------- INPUT NUMBER --------
input_number:
lr11_bright:
name: brightness
min: 0
max: 100
step: 1
# --------------------------------------------- Groups ————--------
group:
lv_lights:
name: all living room lights
entities:
- light.lv_spot11
- light.lv_spot12
- light.lv_spot13
- light.lv_spot21
- light.lv_spot22
- light.lv_spot31
- light.lv_spot32
- light.lv_spot33
#
Automation:
- alias: control brightness for active lightbulb
trigger:
platform: state
entity_id: input_number.lr11_bright
action:
- service: light.turn_on
data_template: >
{% for entity in states.group.lv_lights.attributes.entity_id -%}
{%- if states[entity.split('.')[0]][entity.split('.')[1]].state == 'on' %}
entity_id: "{{ states[entity.split('.')[0]][entity.split('.')[1]].entity_id }}"
brightness: "{{ trigger.to_state.state | multiply(2.55) | int }}"
{%- endif %}
{%- endfor %}