Hi there
I’d like to setup an automation that is triggered by a virtual button and then based on time of year (for example, January to June) turns on certain lights (and their associated effects) then with the same button (ideally same automation) pressed in July through September each year sets a different number of lights with different effects.
I’ve already setup how the light strips and bulbs will react color and effect wise through the button but scratching my head on how to take range of months in a year within the automation. I believe Template may be the way to go but not sure how to get started with this. Can anyone offer assistance or a script/template ?
Thanks so much
You can use a Choose statement with template conditions to do different things in different months. For instance, this template would be true for January through June (inclusive)
{{ now().strftime("%m") | int < 7 }}
@atlflyer
Thats great so I could have the button stay the constant (on or off) and then use the choose statement for 3-4 different times of year to change to the specific lighting ?
How do I add day of month into that template example and also how would you straddle years (Dec through Jan) etc ?
Thanks
Also if you wanted a specific day so for example 4th July for 1 light scene but jan through July 3rd for another, 5th July through November 22nd another etc etc
Something like this for a date selection but what about specific dates etc, 1 off date if you will ?
{{ (1,10) <= (now().month, now().day) <= (10,31) }}
Choose actions check the options’ conditions sequentially, so put more specific options first:
actions:
- variables:
now: '{{ now() }}'
day: '{{ now.day }}'
month: '{{ now.month }}'
- action: choose
- alias: 4th of July
conditions:
- condition: template
value_template: '{{ (month, day) == (7, 4) }}'
sequence:
- action: scene.freedom_hell_yeah_lights
- alias: St Patrick's Day
conditions:
- condition: template
value_template: '{{ (month, day) == (3, 17) }}'
sequence:
- action: scene.lights_of_the_irish
- alias: Jan-July
conditions:
- condition: template
value_template: '{{ month <= 7 }}'
sequence:
- action: scene.jan_july_lights
1 Like
Thats fantastic. Thanks so much both.
One last question. This is more integration specific but I am using the Kasa integration and there is a specific entity/ action that I can setup using an automation to layout color options etc BUT does not show up in Scenes therefore not able to capture the colors, timing etc. As mentioned I can easily do this in the automation but though that it would benefit from a Scene type of approach since then I can always adjust the color, timing centrally rather than in each automation.
What can be done in situations like this where a Device Action or Entity is not show in the Scenes setup, are there better ways to trap current specifics of a device ?
Thanks again
Full example of what is working for me
- id: "456789012345"
alias: Seasonal Front Lights Sunset Trigger
description: Turns on holiday scene duing specific date ranges, and Normal scene the rest of the year.
mode: single
# 1. Trigger: Run every day 30 minutes before official sunset
trigger:
- trigger: sun
event: sunset
offset: -00:30:00
- trigger: state
entity_id:
- binary_sensor.front_lights_input_0_input
from:
to:
conditions:
- condition: device
type: is_off
device_id: 28305aa57406cccdfefe308ef07452f6
entity_id: de26e071bc1a008a5068101eaab02ed7
domain: light
action:
# Set a variable for the current month number (1 for Jan, 10 for Oct, etc.)
- variables:
current_month: "{{ now().month }}"
current_day: "{{ now().day }}"
- choose:
# CHOICE 1: It is October (month 10)
- conditions:
- condition: template
value_template: "{{ current_month == 10 }}"
#Example useing month and day: value_template: '{{ (current_month, current_day) == (7, 4) }}'
sequence:
- action: scene.turn_on
target:
entity_id: scene.halloween
data: {}
# DEFAULT: Used anytime no condtions above match
default:
- action: scene.turn_on
target:
entity_id: scene.normal_front_lights
data: {}