Automation During Date Range

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

1 Like

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

Outside the US, Independence Day depends on the person and when they got divorced! :wink:

I’m really struggling to understand how this is working for you! But if it somehow is, great! I would think {{ now().month in [1,2,3,4,5,10,11,12] }} would exclude Jun-Sept? My thinking is the automation should look like this to only water on Tuesday & Saturday, June 1 to August 31:

description: ""
mode: single
triggers:
  - trigger: time
    at: "06:00:00"
conditions:
### (when multiple conditions are listed, the default is to 'and' them)
  - condition: time
    weekday:
      - tue
      - sat
  - condition: template
    value_template: "{{ now().month in [6,7,8] }}"
actions:
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.water_frontard

I’ve read the Winter sprinkler switch-off - Water Corporation, WA and in my mind, the dates are back-asswards! “The Winter Sprinkler Switch-off runs throughout winter from 1 June to 31 August every year”?? Shouldn’t that read “The Winter Sprinkler Switch-off runs throughout winter from 31 August to 1 June every year”??
I’m totally dumbfounded!

PS. It would help everyone trying to read your automation if you posted it as code rather than as a quote.

hardly…

you’re doing string manipulations, where you should really be entering numbers in those date time templates…

state: >
  {{now().month == 7 and now().day == 4}}

would be a better solution

or:

{{(now().month,now().day) == (7,4)}}

please leave ChatGPT out of here

2 Likes

Relax. ChatGPT…worked fine for what I needed to do.

It produced a functional but clumsy solution.

In fairness, based on its track record of producing solutions, that’s better than average. Sometimes its suggestions are simply invalid. FWIW, that’s why the community forum banned the use of ChatGPT as a tool for offering solutions to other users.

1 Like

Well I was not aware of that. Folks simply had to say so versus being rude and dismissive. Thank you for explaining it.

You’re welcome!

Here’s the relevant blog post:

Wonder what makes you say that.
As far as I can find, there have only been helpful responses?

Meh…IMO you were rude. Maybe you didn’t mean to be rude by saying “Leave ChatGPT out of here” but that is how it came off. I am not a regular in this community so I do not follow announcements like that. I tried some of the things mentioned and it did not work for me. Maybe I did something wrong.

Regardless, If ChatGPT is banned all you needed to do is say so. Simple as that.

you forgot to quote the first word of that sentence…

and no, I didnt mean to be rude.
Nor do I appreciate to be called out to be, or to be told to take it easy.

moreover, it was the last sentence in my reply to you. all other stuff was helping you out and showing you how you could solve your issue

Hi Phil
Awesome work here, I know you have answered this already here but I am new and having trouble getting this to work, trying to get my heating to come on just for June July August.

{{ now().month in [6,7,8] }}

This is what I have broken

condition: template
value_template: |
  {% set n = now() %} {{ n.month == 6 and 5 <= n.month <= 8 and 20 }}

So replace with

condition: template
value_template: |
  {{ now().month in [6,7,8] }}

ok that passes test at least, thank you.