Automation During Date Range

I will try it out. Tnx :smiley:

guys can anyone help ? Id like to set a date range between 11 of january to 14 of november all months between included how can i do that? and also one for 15 of november to 10 of january

See my post above:

      value_template: >-
        {% set fromts = '01-11' %}
        {% set tots = '11-14' %}
        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}

That will give you a condition that is true for your 11 Jan – 14 Nov date range and false for your second range — so you could use it in a NOT condition to work around the problem of the second range crossing the year boundary.

It works because properly-ordered date/time strings are sortable.

thank you so much for your answer ill test it tommorow and see if it works

sorry bout the latency but i just found some time to test the automation and unfortunately it does not work here it is

trigger:
  - platform: sun
    event: sunset
    offset: +00:21:00
  condition:
  - condition: not
    conditions:
    - condition: template
      value_template: "{% set fromts = '01-11' %}\n        {% set tots = '11-14' %}\n\
        \        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False)\
        \ <= tots }}"
  action:
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_on
  - after: '23:20:00'
    condition: time
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_off

hope you can tell me why it does not work

@Amarilia_Amarilia_Am First of all, your code looks nowhere like that of @Troon… Might be your editor (or UI) but checking if it’s correct is important. So make it look like that and it will work :slight_smile:

trigger:
  - platform: sun
    event: sunset
    offset: +00:21:00
  condition:
  - condition: not
    conditions:
    - condition: template
      value_template: >-
        {% set fromts = '01-11' %}
        {% set tots = '11-14' %}
        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}
  action:
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_on
  - after: '23:20:00'
    condition: time
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_off

its the editor it is like troon’s but do not know why it is not working maybe its the offset ?

@Amarilia_Amarilia_Am Is the NOT actually what you want? That flips the logic and give you a valid range from 14 November to 11 January.

what i actually want is my lights to turn on from 11 january to 14 of november

Than remove the NOT :smiley:

i did that too but i do not see the lights turn on after the sun offset :frowning:

Please repost the complete automation after changing it. Yaml is very sensitive and the lack of (or excess of) spaces does not show in my crystal ball. :wink:

 trigger:
  - platform: sun
    event: sunset
    offset: +00:21:00
  condition:
  - condition: template
     value_template: >-
        {% set fromts = '01-11' %}
        {% set tots = '11-14' %}
        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}
  action:
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_on
  - after: '23:20:00'
    condition: time
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_off

for a stupid reason the editor showing this :

- condition: template
    value_template: "{% set fromts = '01-11' %}\n        {% set tots = '11-14' %}\n\
      \        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <=\
      \ tots }}"

By editor you mean the UI? Otherwise, do you have an alternative way to access your automations.yaml? For example with Notepad++ vi Samba?

Because I do think the templates gets mangled somehow.

i mean the file editor addon in supervisor and the main editor shows the same

Okay, what happens when you fix the template to

"{% set fromts = '01-11' %}{% set tots = '11-14' %}{{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}"

Also, value_template should aline with condition.

we will find out in 20 minutes :stuck_out_tongue:

crossing fingers

no unfortunately it does not work

though i found something interesting :

Triggered by the sunset with offset at April 9, 2021, 8:15:54 PM

Test Test a template

Stopped because of unknown reason “failed_conditions” at April 9, 2021, 8:15:54 PM (runtime: 0.00 seconds)

Right, good time to open up the new automation debugger! :smiley:

Your indentation is still not correct in the post above. The trigger, condition and action lines should all start in the same column:

trigger:
  - platform: sun
    event: sunset
    offset: "+00:21:00"
condition:
  - condition: template
    value_template: >-
        {% set fromts = '01-11' %}
        {% set tots = '11-14' %}
        {{ fromts <= now()|as_timestamp|timestamp_custom('%m-%d', False) <= tots }}
action:
  - entity_id: switch.sonoff_1000321709
    service: switch.turn_on

I think the oddity in the template line is because when you paste it, it’s adding a load of spaces somewhere. Make it look exactly as above, and make sure there are no spaces at the end of each line.

I’d recommend a second automation to switch the lights off at 23:20.

2 Likes