Is there a simple way to have an automation happen during a date range? Say I want a light to turn on every day at sunset, but only for October 15th to the 20th?
I can’t find this in the docs… I’m using the Automations tab in Lovelace to set up automations, but there is no “date” condition.
condition:
- condition: template
value_template: >
{% set day = now().strftime('%d') %}
{% set month = now().strftime('%m') %}
{{ month == '10' and day > '14' and day < '21' }}
The conditions are a good way to approach this and I was considering changing my method but the advantage of disabling the automation is that I see feedback in the front end that the light automation is disabled. So I get less ‘why didn’t that run?’ moments.
That certainly is not correct. The number of the month cannot be both greater than or equal to 12 at the same time as being less than or equal to 1.
It’s not exactly clear what you want. Do you want the automation to be able to run on January 8th, and December 9th, or any day between them (i.e., after January 8th but before December 9th)?
Or do you want the opposite (i.e., on December 9th, and January 8th, or any day between them – after December 9th but before January 8th)?
automation should work between the days from 8 December to 8 January of the following year, every day, and another that should work on 9 January to 7 December of the same year for each day. thank you
I’m trying to turn on a Christmas tree at 5AM and turn it off at 10PM. A couple options…?
Use the switch.toggle option, and somehow make sure no one messes with it manually and gets it out of sequence…
Use two separate automations one that triggers on at 5AM, one that triggers off at 10PM
(probably a smarter way!)
i thought i saw that i could use a condition template similar to what you are doing above, but i dont know how to ‘action’ it to do an on when the condition is met and an off when not.
Using two automations is definitely simpler, and you get the added benefit of being able to individually turn them on or off if you like. But, for completeness, you can do it in one automation:
trigger:
- platform: time
at: 05:00:00
- platform: time
at: 22:00:00
action:
- service_template: >
switch.turn_{{ 'on' if trigger.now.hour == 5 else 'off' }}
entity_id: switch.SWITCH