Creates a binary sensor whose state is “on” between the defined start and end dates.
This can be used to define your own custom “seasons” to use as conditions for lighting effects, electricity tariffs, holidays, sports seasons, etc. Date spans that cross over New Year are supported.
Changelog:
- 2025-12-17:
- Updated to handle date strings with or without the year and either
-or/separators.
- Updated to handle date strings with or without the year and either
blueprint:
author: Didgeridrew
homeassistant:
min_version: 2025.10.6
name: Annual Date Range Binary Sensor
description: |
Creates a sensor whose state is "on" when the current date is between two static dates. Crossing the new year is supported.
domain: template
input:
start_date:
name: Start Date
description: |
The date (YYYY/MM/DD or MM/DD) you want to be the first day of your range.
The resulting binary sensor will turn "on" at 0:00:00 on this date.
The year will not be used for this binary sensor.
selector:
date:
end_date:
name: End Date
description: |
The date (YYYY/MM/DD or MM/DD) you want to be the last day of your range.
The resulting binary sensor will turn "off" after 23:59:59 on this date.
The year will not be used for this binary sensor.
selector:
date:
variables:
_start_date: !input start_date
start_l: |
{% set sep = '-' if _start_date is search '-' else '/' %}
{% set d_list = _start_date.split(sep) %}
{% set ymd = d_list | count %}
{{ (d_list|map('int',0)|list)[ymd-2:ymd] }}
_end_date: !input end_date
end_l: |
{% set sep = '-' if _end_date is search '-' else '/' %}
{% set d_list = _end_date.split(sep) %}
{% set ymd = d_list | count %}
{{ (d_list|map('int',0)|list)[ymd-2:ymd] }}
crosses_year: "{{ start_l > end_l }}"
current_l: "{{ [now().month, now().day] }}"
trigger:
- trigger: homeassistant
event: start
- trigger: time_pattern
hours: /1
binary_sensor:
state: |
{% if start_l == end_l %}
{{ start_l == current_l }}
{% elif crosses_year %}
{{ start_l <= current_l or current_l <= end_l }}
{% else %}
{{ start_l <= current_l <= end_l }}
{% endif %}
availability: "{{true}}"