While you can create static sensors or templates to do date-range based automation, I created this so you can easily and quickly create date-range automation on the fly (i.e., turn on Christmas lights if it is between Black Friday and January 6th) or even specific dates within a month (i.e., 1st through the 15th). You can set up four fields and use this blueprint to keep all of your automation together in one place rather than having some as sensors and some as various Py scripts.
The concept is simple, create four number inputs to hold numeric values for the full date (i.e., 20201231), full date without the year (i.e., 1231), the month and the current day. Then in automation use these to determine if the current date falls in between your requirements (i.e., above 1201 and below 1231 indicates any day in December of any year).
Once added, this will run at 5 seconds past midnight each day to calculate the values.
This is my first go at this and it works well in my system, hopefully others will find it useful.
Get started
Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)
Or import this Blueprint by using the forum topic URL:
blueprint:
name: Todays Date Helpers
description: 'Set the value of various helpers with a numeric value of todays date to use in Automation'
domain: automation
input:
full_date:
name: Full Date Input
description: The number input that holds the full date (i.e., 20201201).
selector:
entity:
domain: input_number
month_day:
name: Month/Day Date Input
description: The number input that holds the month and day (i.e., 1201).
selector:
entity:
domain: input_number
day:
name: Date Day Input
description: The number input that holds todays date (i.e., 31).
selector:
entity:
domain: input_number
month:
name: Month Input
description: The number input that holds the current month (i.e., 12).
selector:
entity:
domain: input_number
trigger:
- platform: time
at: '00:00:05'
condition: []
variables:
full_date: '{{ now().strftime("%Y%m%d") }}'
month_day: '{{ now().strftime("%m%d") }}'
day: '{{ now().strftime("%d") }}'
month: '{{ now().strftime("%m") }}'
action:
- service: input_number.set_value
data:
entity_id: !input 'full_date'
value: '{{ full_date }}'
- service: input_number.set_value
data:
entity_id: !input 'month_day'
value: '{{ month_day }}'
- service: input_number.set_value
data:
entity_id: !input 'day'
value: '{{ day }}'
- service: input_number.set_value
data:
entity_id: !input 'month'
value: '{{ month }}'
Example Automation Condition To Run Between November 1 and December 25