The Problem

Home Assistant can tell you if it’s Thanksgiving if you have a calendar plugin configured with Thanksgiving scheduled. But the included Calendar plugin doesn’t have that pre-scheduled, and what if you don’t want to use a Cloud calendar service? The date sensor isn’t very good with date math, and getting “Thanksgiving” to a date is difficult because it’s not a fixed day.

The Solution

Template Sensors and Date Math

I found most of this on the Home Assistant Forums, but I’ve lost the link.

The YAML below will set a “holiday-season” sensor’s state to “christmas” between the day after Thanksgiving and Jan 5th.

It’ll set the state to “halloween” in October.

Otherwise it sets the state to “none”. Simple enough.

Home Assistant Automation Configuration
- trigger:
  - platform: time_pattern
    # This will update every night
    hours: '0'
    minutes: '0'
  - platform: event
    event_type: event_template_reloaded
  - platform: homeassistant
    event: start

    - name: "holiday-season"
      state: >
        {%- set today = now().date() -%}
        {%- set month, week, day = 11, 4, 3 -%}
        {%- set temp = today.replace(month=month, day=1) -%}
        {%- set adjust = (day - temp.weekday()) % 7 -%}
        {%- set temp = temp + timedelta(days=adjust) -%}
        {%- set thanksgiving = temp + timedelta(weeks = week - 1) -%}
        {%- set jan6th = temp.replace(month=1, day=6) -%}

        {% if today <= jan6th or today > thanksgiving -%}
          {%- set season = "christmas" -%}
        {%- elif today.month == 10 -%}
          {%- set season = "halloween" -%}
        {%- else -%}
          {%- set season = "none" -%}
        {%- endif -%}        

Example Use Cases


Using the Card Mod plugin, you can style dashboard cards and use this sensor to change your themes.

Example Dashboard

How to do this in a dashboard:

Selecting a Scene

Using scenes whenever possible, rather than trying to capture everything manually is the best way to handle lighting and switches and such. In this case, rather than activating a scene, trigger an automation that activates the appropriate scene.

Example Dashboard

This also works for playlists, videos, whatever.

The YAML version of the above configuration
alias: Select Holiday Scene
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.holiday_season
            state: christmas

          - service: scene.turn_on
              entity_id: scene.bsow_bar_christmas_scene
            metadata: {}

      - conditions:
          - condition: state
            entity_id: sensor.holiday_season
            state: halloween

          - service: scene.turn_on
              entity_id: scene.bsow_bar_halloween_scene
            metadata: {}
      - service: scene.turn_on
          entity_id: scene.bsow_bar_default_scene
        metadata: {}

mode: single
icon: mdi:palette-swatch-variant