I’m trying to reduce the clutter on Lovelace by making most things conditional that don’t need constant control or are controlled mainly elsewhere.
I’ve now got to my three Christmas switches and want the card to appear during the festive period only. The card part is fine, but I’m trying to set up a sensor template to sense if it’s Christmas or not. I copied this from another post, but I’m getting an error in the log.
The error is;
Could not render template christmas_time: UndefinedError: list object has no element 1
# Create the time_date sensors
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
# Christmas time sensor to show the cards and other useful things
sensor:
- platform: template
sensors:
christmas_time:
value_template: >
{% set today = states('sensor.date').split('-') %}
{% set month = today[1]|int %}
{% set day = today[2]|int %}
{{ month == 12 and day >= 5 or
month == 1 and day <= 6 }}