This post may contain affiliate links. Please read my disclaimer for more info.

Football season is upon us and I wanted to automate the lights in my house for my favorite team. I was looking for a way to trigger some automations a few hours before the game to set the lighting around my house and get in the gameday spirit!

Read on to learn how I used Home Assistant, Google Calendar, and a template sensor to track when my team plays and create automations leading up to the game.

Google Calendar for Team Schedule

Subscribing to Your Team

To automatically get your team’s schedule, you can leverage Google Calendar. Using a calendar subscription you’ll automatically get the correct times for when your team kicks off, even if the game changes times (which happens often in college football). Google Calendar has team calendars you can subscribe to. We can then use the Home Assistant integration to create automations. Adding your sports team to Google Calendar is very straightforward.

Go to calendar.google.com and click on the “Gear” icon in the top right.

On the left-hand side, under “Add calendar”, choose “Browse Calendars of interest”.

From there, you can browse for your favorite team and add them to your calendar.

After subscribing, you should see the calendar for your team in your Google Calendar.

Adding to Home Assistant

Now that your team’s calendar is displayed in your Google Calendar, we just need to hook up Home Assistant to use Google Calendar as well.

The Home Assistant documentation has some great instructions on how to enable Google Calendar using the official Google API. Rather than repeat them here, I recommend you read through their instructions.

Once complete and Home Assistant has been restarted, you should get a notification indicating that Google Calendar has been set up successfully.

You’ll now have a google_calendars.yaml file generated in your Home Assistant configuration directory. You can edit this file to change how Home Assistant interacts with your calendars. You can set track: false for any calendars you don’t want Home Assistant to create sensors for.

Custom Offset Sensors

If you want to create automations that start at a preset time before the event starts, it can be helpful to create custom sensors that show the time before the next event occurs. I’m using a template sensor to calculate the number of minutes kickoff.

platform: template sensors: time_until_next_longhorn_game: friendly_name: Time Until Next Longhorn Game entity_id: sensor.time unit_of_measurement: minutes value_template: >- {% if states.calendar.texas_longhorns.attributes.start_time %} {{((as_timestamp(states.calendar.texas_longhorns.attributes.start_time) - as_timestamp(now())) / 60) | int }} {%- else -%} 0 {%- endif %} 1 2 3 4 5 6 7 8 9 10 11 12 platform : template sensors : time _ until _ next _ longhorn _ game : friendly _ name : Time Until Next Longhorn Game entity _ id : sensor.time unit _ of _ measurement : minutes value _ template : > - { % if states . calendar . texas _ longhorns . attributes . start _ time % } { { ( ( as _ timestamp ( states . calendar . texas _ longhorns . attributes . start _ time ) - as _ timestamp ( now ( ) ) ) / 60 ) | int } } { % - else - % } 0 { % - endif % }

You can see in the above sensor configuration, the value of the sensor is calculated as the number of minutes between the start time and the current time. I had to explicitly add the sensor.time entity to the entity_id to tell the template sensor it needs to be updated every minute. The value of the sensor basically goes down by 1 every minute until the game starts.

This allows to easily create automations leading up to kickoff by triggering on the value.

Creating Automations

With this custom template sensor set up, creating an automation before kickoff is really easy. For example, I wanted to set the lights in my house to a specific color starting an hour before kickoff.

--- alias: Longhorn Start Gameday trigger: - platform: state entity_id: sensor.time_until_next_longhorn_game to: "60" action: - service: scene.turn_on entity_id: scene.longhorn_gameday - service: tts.google_translate_say entity_id: media_player.kitchen_speaker data: message: "Longhorn's kickoff in one hour!" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 --- alias : Longhorn Start Gameday trigger : - platform : state entity _ id : sensor.time_until_next_longhorn_game to : "60" action : - service : scene.turn_on entity _ id : scene.longhorn_gameday - service : tts.google_translate_say entity _ id : media_player.kitchen_speaker data : message : "Longhorn's kickoff in one hour!"

The above automation basically triggers whenever the “time_until_next_game” sensor reaches “60”. It then triggers a scene to set lights correctly around my house to set the atmosphere of the game. For example, my under cabinet kitchen lighting changes to burnt orange to support my Texas Longhorns.

It also announces over my Google Home that the game will kickoff in an hour using the Google TTS integration.

I have another automation that triggers after the game has ended. Unfortunately, the Google Calendar end times don’t really reflect the actual end times of the game. They typically estimate about 3 hours for football. To give some buffer, my automation triggers an hour and a half after the game has ended in Google Calendar.

--- alias: Longhorn Finish Gameday trigger: - platform: state entity_id: calendar.texas_longhorns from: "on" to: "off" for: hours: 1 minutes: 30 action: - service: scene.turn_on entity_id: scene.normal_lighting 1 2 3 4 5 6 7 8 9 10 11 12 13 14 --- alias : Longhorn Finish Gameday trigger : - platform : state entity _ id : calendar.texas_longhorns from : "on" to : "off" for : hours : 1 minutes : 30 action : - service : scene.turn_on entity _ id : scene.normal_lighting

So while this doesn’t trigger exactly when the game ends in real life, it does reset the lights back in a reasonable amount of time after the game ends.

Summary

What are you doing to automate your game day? I think there is a lot of potential here to create an awesome atmosphere when supporting your favorite team if you’re a sports nut like me. If you are an NHL or MLB fan, you should check out the goalfeed Home Assistant integration to create some automations whenever your team scores.

Let me know in the comments what your game day looks like and how you could use Home Assistant!

Please consider supporting the blog by joining my mailing list, following the blog on social media or directly through Buy Me a Coffee. Thanks for reading!