Hi, I’m new to using HA, but I’m trying to do some things with automation that are probably beyond my “newbie” skill level. I’m trying to write an automation that will:
- Turn on my Christmas tree every evening at sunset
- Turn off the tree at 10:45pm Sunday through Thursday (work nights)
- Turn off the tree at 1am Saturday and Sunday morning
#2 and #3 above should be ignored on Christmas Eve and Christmas Day (when the tree should stay on continuously.)
I was hoping to get feedback on how poorly this is written, what could be improved, and if it would even work as I expect.
Here’s my automation:
alias: XMas Tree On/Off (with variables)
description: >-
turn the tree on and off
trigger:
- platform: sun
event: sunset
offset: 0
id: sunset
- platform: time
at: "01:00:00"
id: 1am
- platform: time
at: "22:45:00"
id: "1045"
condition: []
action:
- variables:
# variables to make the conditions easier to read.
xmas_eve_day: "{{ ((12,24) <= (now().month, now().day) <= (12,25)) }}"
worknight: "{{ not(4 <= now().weekday() <= 5) }}"
- choose:
- conditions:
- condition: trigger
id:
- sunset
sequence:
- type: turn_on
device_id: 3dcdc0ca3773d9d90e6f5fe9ca2fae53
entity_id: ae28a3784ed5bf111167fca5dc228264
domain: switch
- conditions:
- condition: template
value_template: >-
{{ not(xmas_eve_day) and ((worknight) and (trigger.id =='1045'))
or (trigger.id == '1am') }}
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.christmas_tree
mode: single