3 m

Christmas treeTomorrow, the advent period starts. A good time to talk about holidays, seasons, birthdays and other special days you can think of within Home Assistant. How do you tell Home Assistant when such a special day or season happens without changing dates in automations every year? I thought a lot about that and ended up with a sensor in which I can define the moments which are special to me throughout the year. In this article, I will tell you how to create this sensor and I will give you some automation ideas as well.

The first challenge was to learn Home Assistant the date without the year. This way, all my automations will work the next year without changing dates within the code. I expect that there are multiple ways to do this, but I found the method below convenient and sustainable.

I created a sensor which shows the date as a number. I divided the days by 100, so they became decimals and add the number of the months to it. So, December 1th will be ‘12.01’ and May 20th (my birthday) will be ‘5.20’. This way, I can use simple numeric state conditions when defining my special moments. The sensor is below:

# Numeric month and day sensor
  - platform: template
        value_template: "{{ (float(now().day) / 100) + float(now().month)| round(2) }}"

Seasonal mode sensor

Next, I created a template sensor which defines the current seasons with if-statements. I did this for the whole year: advent, Christmas, top2000 (a Dutch music chart between Christmas and New Year’s Eve), summer and many more. The fun part is that, since it is a template, you can take more than only the date in account. For example, for summer I also use the sun and the outside temperature as a condition and since my music is also connected to this sensor, I only wanted the advent season state happening after sunset. The downside is that with this many statements, the template will grow big real quick, so I recommend you to create a separate yaml file for this sensor, since it will get longer and longer when time pass.

I created a new file called ‘seasons.yaml’ and added the following lines to my sensor entry in the configuration.yaml file:

  - platform: template
      seasonal_mode: !include seasons.yaml

Since the seasons.yaml file is long, I won’t show it here, but you can seasons.yaml.

Now you have a sensor which shows the current season or special day. When there is no special season or day, it shows ‘none’.

Automation ideas

Below is a list with some automation ideas. Feel free to add more in the comments:

  • Keep your Christmas lights on while advent and/or Christmas Day is happening
  • Automatically activate your special Christmas light scene on Christmas
  • Give your lights your child’s favorite color on his or her birthday
  • Play happy birthday when it is someone’s birthday
  • Play summer hits when it’s sunny and hot outside within the summer period
  • Flash your lights like fireworks when the new year starts
  • Change your doorbell chime for each season

And that is the seasonal mode sensor. Let me know what you are going to do with it or what you want/can change.