I’ve got a string of LEDs run by an ESP8266 with WLED 0.14.0. In HA I have an automation to turn them on and off every day at sunset(ish) and 11pm respectively. I also have a good chunk of preset patterns/effects that I’d like to select from when turning them on each day. However, I want to change which preset is selected based on the (roughly) month for the given holiday.
For example, in December, I want to have one of several Christmas presets randomly selected. If I was to illustrate this with a JSON map, it would look something like this:
{
1: ['rainbow'],
2: ['valentines1', 'valentines2'],
3: ['rainbow'],
4: ['rainbow'],
5: ['rainbow'],
6: ['rainbow'],
7: ['fourth1', 'fourth2'],
8: ['rainbow'],
9: ['rainbow'],
10: ['spooky1', 'spooky2'],
11: ['rainbow'],
12: ['xmas1', 'xmas2', 'xmas3'],
}
Where the object has entries for each of the 12 months and for each of those entries, a set of presets to randomly choose from.
Currently I have this automation which, while it works, seems like there is likely a much better way to write this to be a bit more concise and easier to update/work with.
What tools should I be looking for to template out this decision better?
Thanks!
alias: WLED Porch onoff
description: ""
trigger:
- platform: sun
event: sunset
offset: "-00:15:00"
id: ontime
- platform: time
at: "23:00:00"
id: offtime
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: ontime
sequence:
- type: turn_on
device_id: 5909944fa51dc9d1e443e63aa05789d1
entity_id: light.wledporch_master
domain: light
- choose:
- conditions:
- condition: template
value_template: "{{ now().month in [12] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: "{{ ['xmas tri wipe', 'xmas twinkles'] | random }}"
- conditions:
- condition: template
value_template: "{{ now().month in [10] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: halloween
- conditions:
- condition: template
value_template: "{{ now().month in [7] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: fourth
- conditions:
- condition: template
value_template: "{{ now().month in [11] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: thanksgiving
- conditions:
- condition: template
value_template: "{{ now().month in [2] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: valentines
- conditions:
- condition: template
value_template: "{{ now().month in [1,3,4,5,6,8,9] }}"
sequence:
- service: select.select_option
target:
entity_id: select.wledporch_preset
data:
option: rainbowtime
- conditions:
- condition: trigger
id: offtime
sequence:
- type: turn_off
device_id: 5909944fa51dc9d1e443e63aa05789d1
entity_id: light.wledporch_master
domain: light
mode: single