fabian727
(F. Scheidig)
July 1, 2024, 3:38pm
104
5 years gone and still no solution for a date?
I just tried the “time” condition given from hass (without reading the docs: my fault, as it is only comparing the day time and workday and special days, but no dates)
Couldn’t this be enhanced to also look at the date? If 0 is given for year … than it’s not compared? Or duplicate the time condition as “date”?
1 Like
Hello everyone, I had the same needs, and took your insights to create a pull request to add two new conditions: date and datetime.
This way, we would be able to choose to compare “only the date”, “only the time” or the “date and time” !
Please take a look at it Add date and datetime conditions by Passific · Pull Request #128009 · home-assistant/core · GitHub
I just used ChatGPT to generate some sensors.
template:
- binary_sensor:
# New Year's Day
- name: New Year's Day
unique_id: new_years_day
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-01-01" }}
# Valentine's Day
- name: Valentine's Day
unique_id: valentines_day
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-02-14" }}
# St. Patrick's Day
- name: St. Patrick's Day
unique_id: st_patricks_day
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-03-17" }}
# Easter (calculated dynamically)
- name: Easter
unique_id: easter
state: >
{% set a = now().year %}
{% set d = (((a * 19) % 19) + 15) % 30 %}
{% set e = ((a + (a // 4) + d + 2 - (a // 100) + ((a // 100) // 4)) % 7) %}
{% set day = 22 + d + e %}
{% if day > 31 %}
{{ now().strftime('%Y-%m-%d') == (a | string) + "-04-" + (day - 31) | string }}
{% else %}
{{ now().strftime('%Y-%m-%d') == (a | string) + "-03-" + day | string }}
{% endif %}
# Independence Day
- name: Independence Day
unique_id: independence_day
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-07-04" }}
# Halloween
- name: Halloween
unique_id: halloween
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-10-31" }}
# Thanksgiving (4th Thursday of November)
- name: Thanksgiving
unique_id: thanksgiving
state: >
{% set nov1 = strptime((now().year | string) + "-11-01", "%Y-%m-%d") %}
{% set offset = (3 - nov1.weekday()) % 7 %}
{% set thanksgiving = nov1 + timedelta(days=(offset + 21)) %}
{{ now().strftime('%Y-%m-%d') == thanksgiving.strftime('%Y-%m-%d') }}
# Christmas
- name: Christmas
unique_id: christmas
state: >
{{ now().strftime('%Y-%m-%d') == (now().year | string) + "-12-25" }}
Worked perfect