I would like to make a card only visible between the 1st of December each year until the 6th of January the next year. This is so that during this period there is a card for manually turning the Christmas lights on and off. The rest of the year they are not required! I can see time as a condition but that isn’t suitable. I guess I need to have a variable with a state which is true between these dates. Any ideas?
Simplest would be to create a Template Helper (as Binary senor) and use that helper as condition for the condition card.
With the template being: (always test it out in the Dev tools)
{% set x = now() %}
{{ (x.month == 12 and 1 <= x.day) or (x.month == 1 and x.day <= 6) }}
I knew it would be simple! This is great thank you!
I have similar requirements for “Festive Season” and “Pool Season”. I use a Trigger-based Template Binary Sensor because, for this application, it’s more efficient.
template:
- triggers:
- trigger: time
at: '00:00:00'
- trigger: event
event_type: event_template_reloaded
- trigger: homeassistant
event: start
binary_sensor:
- name: Festive Season
state: >
{% set x = (now().month, now().day) %}
{{ x >= (12,1) or x <= (1,6) }}
A Template Binary Sensor employing the now() function, like the one suggested in the previous post, will have its template evaluated every minute. That means 60x24=1440 times a day and 1440x365=525600 times a year.
If the goal is to simply determine if a given day is within a desired date range, checking a half-million times a year seems, to put it mildly, excessive.
In contrast, a Trigger-based Template Binary Sensor will evaluate its template only when triggered. The “Festive Season” example will trigger once a day at 00:00 so that’s just 365 times a year.
In case Home Assistant is offline at 00:00 there are two additional triggers, at startup and whenever Template entities are reloaded, to ensure the template is evaluated at least once a day. Realistically, the template will be evaluated less than 500 times a year which is orders of magnitude less than 525600.
Even better solution many thanks Taras!
I did not realize that. Thanks for the heads up. I have a template sensor to adjust now ![]()
![]()