using this template for switching on lights at random, being triggered repeatedly:
- service: light.turn_on
data_template:
entity_id: light.{{['light1','light2','light3','light4']|random}}
how can I change that if I want these lights to all have profile: relax
in 1 go? Other than listing the separate entities like this:
- service: light.turn_on
data:
entity_id:
- light.light1
- light.light2
- light.light3
- light.light4
profile: relax
tried it without the |random:
entity_id: light.{{['light1','light2','light3','light4']}}
but that wont go…
Brett_C
(Brett C)
July 6, 2018, 12:04pm
2
I’m not sure I follow why you don’t want to list them out like that? Could be worth checking out Light Groups to see if that’s what you’re looking for though.
petro
(Petro)
July 6, 2018, 12:22pm
3
I think it can only be done with json:
- service: light.turn_on
data_template: "{'entity_id': [{% for i in range(1,5) %}light.light{{i}},{% endfor %}], 'profile':'relax'}"
1 Like
not big deal, just always try find something better possible.
had a peek at this, but that might a bit overcomplicating things…
action:
- service: light.turn_on
data_template:
entity_id: light.{{ objectLocation | replace(" ","_") }}
color_name: {{ objectColor }}
brightness: >-
{% if objectBrightness -%}
{{objectBrightness}}
{%- else -%}
{{state_attr('light.' + objectLocation.replace(" ","_"), 'brightness')}}
{%- endif %}
thats nice indeed, especially for the numbered ones!
can that also be used for named lights? If so I could rebuild some…
range(1,5) change into kitchen, bathroom, bedroom, dining etc
petro
(Petro)
July 6, 2018, 12:27pm
6
range() just makes a list of numbers, you can use it anywhere. a range(1,5) returns [1,2,3,4]. a range(5) returns [0,1,2,3,4]. a range(2,9) returns [2,3,4,5,6,7,8].
sure, got that.
but to make [light.bathroom, light.dining, light.hall] Id need something else than the range (), dont know what though…