Morning all, I’m trying to create an automation that loops through a group of lights, if any of those lights are on, change the brightness level to 250, if they’re not on, leave them alone. I’m a software developer by background, but relatively new to home assistant…I’ve got it working with just one light, and trying to figure out best how to loop through the group (haven’t yet been successful).
I’m trying to figure out whether it’s best to create an actual group
of lights (I have one called group.downstairs
) and loop thru with {% for light in lights.downstairs … etc. %} or whether I can have multiple entity_ids like entity_id: light.bathroom_1, light.bathroom_2
and then I can use the jinja loop to loop through the stated entities (I haven’t found in the docs how to do that).
Here is what I have for the one light that works great for me:
- id: "1600521261308"
alias: Morning Lights
description: ""
trigger:
- platform: time
at: 06:00:00
condition: []
action:
- service: light.turn_on
data_template:
entity_id: light.guest_bathroom_1
brightness:
"{% if states.light.guest_bathroom_1.attributes.brightness < 250
%} 250 {% endif %}"
mode: single
An idea of what I’m aiming for:
- id: "1600521261308"
alias: Morning Lights
description: ""
trigger:
- platform: time
at: 06:00:00
condition: []
action:
- service: light.turn_on
data_template:
entity_id: light.guest_bathroom_1, light.guest_bathroom_2
brightness: >
"{% for light in <entities_listed_above>" %}
{% if light.attributes.brightness < 250%} 250 {% endif %}
{% endfor %}"
mode: single