Can someone walk me through the process on automating a calendar integration for Xmas lights?
-Setup the Local Calendar integration
-Created a calendar called “Xmas Lights”
– Starts Nov 26th and ends Jan 14th
–Time starts at 7pm and ends at 10:30pm (same day)
–Devices are in a scene called “Xmas Lights On”
I was thinking i could do an Action - If / Then / Else but there’s no condition for Calendar integration.
Do I need two automations to turn on & off the Xmas Lights scenes?
How do I get the calendar based trigger to work off the sun? E.g. I would like my lights to turn on 30 mins after sunset. Not based on a specific time.
I have a Christmas event in my Holiday calendar which runs from mid November to the first week in January. I want my WLED lights to come on during this time period, but only 30mins after sunset to 2am.
It would be simpler to add a condition, to the example I posted above, that employs a hard-coded time period rather than one derived from a calendar.
The following example turns on the light at 30 minutes after sunset from November 15 to January 6, inclusively. It turns off the light at 02:00 from November 15 to January 7, inclusively. It’s one extra day because the light is always turned off the next day at 02:00.
alias: example
description: Control Christmas Lights
trigger:
- id: 'on'
platform: sun
event: sunset
offset: '00:30:00'
- id: 'off'
platform: time
at: '02:00:00'
condition:
- condition: template
value_template: >
{% set start = (11, 15) %}
{% set end = (1, iif(trigger.id == 'on', 6, 7)) %}
{% set t = (now().month, now().day) %}
{{ t >= start or t <= end }}
action:
- service: 'light.turn_{{ trigger.id }}'
target:
entity_id: light.wled
If you don’t want to hard-code the time period as shown above, you’ll need to devise a method of checking the Calendar and determining if it contains an All Day event for activating the WLED light. You can’t simply check the Calendar entity’s attributes.
I suggest creating a Trigger-based Template Binary Sensor (binary_sensor.xmas) that is triggered at the start of every day (00:00), checks if the current day’s calendar contains an All Day WLED event, and then reports on if it does (otherwise off). Then the automation posted above can use a State Condition to check if binary_sensor.xmas is on.
However this approach does not handle the complication created by the 02:00 turn-off time which occurs the day after the last day the light is turned on. In other words, if the Calendar’s Christmas period ends January 6th, the automation will turn on the light, shortly after sunset, on the 6th but not turn it off (at 02:00) on the 7th.
The example with the hard-coded Template Condition is designed to handle this situation.
Thanks, This is what I wanted to know. I really wanted the flexibilty of updating the Calendar itself as needed. I also didn’t really want triggering outside of those dates.
I see what you mean. Is there a efficient way doing tempate conditions for like 10+ holiday date ranges? Would I have to end up using If/else conditions?
It depends on the nature of the 10 date ranges. If they don’t overlap, your Template Condition can use a dictionary to store them. Finding a match in a dictionary is quicker than traversing a long if-elif-else-endif chain.
How would that look like? They wont overlap for sure as this calendar is specifically for holiday lights. I tried this if-else template condition, which didn’t work even though the template worked in developer tools.