With the new variables
and repeat
action in Home Assistant, I have created a single automation to control all my lights.
First I have a input_select.lights_mode
defined:
input_select:
lights_mode:
name: Lights mode
options:
- 'off'
- morning
- day
- evening
- bedtime
- night
And then this automation which controls all the default settings in the different modes.
automation:
- alias: "Lights mode automation"
variables:
settings:
morning:
hallway_light: [ 25, 2200 ]
wardrobe_light: [ 0, 2200 ]
bedroom_light: [ 10, 2200 ]
kitchen_light: [ 75, 2200 ]
floor_lamp_light: [ 75, 2200 ]
# more ...
evening:
hallway_light: [ 25, 2200 ]
wardrobe_light: [ 0, 2200 ]
bedroom_light: [ 25, 2200 ]
kitchen_light: [ 100, 2700 ]
floor_lamp_light: [ 100, 2700 ]
# more ...
bedtime:
# more ...
night:
# more ...
trigger:
platform: state
entity_id: input_select.lights_mode
action:
repeat:
while:
- condition: template
value_template: "{{ repeat.index <= settings[ states('input_select.lights_mode') ] | length }}"
sequence:
- variables:
lights_mode: "{{ states('input_select.lights_mode') }}"
entity_id: "{{ ( settings[ lights_mode ].keys()|list )[ repeat.index - 1] }}"
brightness_pct: "{{ ( settings[ lights_mode ].values()|list )[ repeat.index - 1][0] }}"
kelvin: "{{ ( settings[ lights_mode ].values()|list )[ repeat.index - 1][1] }}"
- service: light.turn_on
data:
entity_id: "{{ 'light.' ~ entity_id }}"
brightness_pct: "{{ brightness_pct }}"
kelvin: "{{ kelvin }}"
transition: 15
The parameters hallway_light:[ 25, 2200 ]
- first one is brightness_pct
and the second is kelvin
.
I hope this can serve as an inspiration