Home Assistant: Never Miss an F1 Race Start Again

As an avid Formula 1 fan, I watch nearly every race. However, I’ve lost count of the times I’ve been engrossed in coding or tinkering with my home automation setup, only to miss the race start. I wondered: could I use Home Assistant to solve this?

The answer is a resounding yes. While sending a simple race-time notification is easy enough with an F1 integration, I wanted to take it a step further. My goal was to create an actionable notification that, with a single tap, would turn on my TV and start the F1 live stream directly.

This guide will walk you through the integrations and automations required to make this happen.

The Setup

Here’s the environment I’m using for this project:

  • Home Assistant
  • Home Assistant Companion app for Android
  • An Android TV device (NVIDIA Shield in my case)
  • A subscription to F1 TV Pro
  • The F1 TV app installed on the Android TV

You can likely adapt these steps to your own setup with a few tweaks.

Step 1: F1 Integration

The F1 Sensor is an unofficial integration, available for installation through HACS. It offers a wealth of F1-related data, from the race calendar to championship standings. For this particular automation, we only need the race calendar data, but feel free to explore its other features once you’re set up.

Step 2: Android TV Debug Bridge Integration

To launch the F1 TV app on our Android TV from Home Assistant, we need the Android TV Debug Bridge (ADB) integration. This powerful tool allows us to send remote commands, like launching apps, directly to the Android system. Since it’s an official Home Assistant integration, you won’t need HACS.

Follow the official ADB integration setup guide to ensure a smooth installation.

Step 3: Create an ADB Script to Start the F1 TV Live Stream

To simplify our final automation, we’ll first create a helper script that starts the F1 TV app and navigates to the live stream. There’s a small catch: the F1 TV app for Android TV doesn’t support launching directly into the live stream via an intent. To work around this, we have to simulate a sequence of remote control button presses.

While this method works, it’s not ideal and can sometimes fail if the app is in an unexpected state. Hopefully, a future update to the F1 TV app will allow for direct deep-linking.

The script below performs the following actions:

  1. Starts the F1 TV app.
  2. Waits for 1 second.
  3. Sends a ‘wakeup’ command to ensure the screen is on.
  4. Waits for 5 seconds to give the app time to load.
  5. Simulates a ‘D-Pad Center’ press to select the featured live event (which should be the upcoming race/qualifying/sprint).
  6. Waits for 1 second.
  7. Simulates a second ‘D-Pad Center’ press to select the ‘Watch Live’ option.

Add the following script to your scripts.yaml or create it via the UI. Remember to change the entity_id to match your own Android TV media player entity!

play_f1_tv_on_shield:
  alias: 'Starts and plays F1 TV on Shield TV'
  sequence:
    - service: androidtv.adb_command
      data:
        command: am start -a android.intent.action.VIEW -d -n com.formulaone.production/com.avs.f1.ui.splash.SplashActivity
        entity_id: media_player.android_tv_192_168_1_175
    - delay: 1
    - service: androidtv.adb_command
      data:
        command: adb shell input keyevent KEYCODE_WAKEUP
        entity_id: media_player.android_tv_192_168_1_175
    - delay: 5
    - service: androidtv.adb_command
      data:
        command: adb shell input keyevent DPAD_CENTER
        entity_id: media_player.android_tv_192_168_1_175
    - delay: 1
    - service: androidtv.adb_command
      data:
        command: adb shell input keyevent DPAD_CENTER
        entity_id: media_player.android_tv_192_168_1_175

Step 4: The Notification Automation

Our notification system has two main components: Template Sensors to calculate when to send the alert, and the Automation itself, which builds and sends the actionable notification.

Template sensors

These sensors are straightforward. For each event (race, qualifying, and sprint), we take the official start time from the sensor.f1_next_race, convert it to our local timezone, and then subtract 10 minutes. This gives us the exact time to trigger our notification. If you also want alerts for practice sessions, simply create additional sensors following the same pattern.

Add the following to your configuration.yaml:

sensor:
  - platform: template
    sensors:
      formula_one_race_start_notification:
        friendly_name: 'Formula One race start notification'
        device_class: timestamp
        value_template: >-
          {{ (states('sensor.f1_next_race') | as_datetime | as_local) - timedelta(minutes = 10 | int ) }}
      formula_one_qualifying_start_notification:
        friendly_name: 'Formula One qualifying start notification'
        device_class: timestamp
        value_template: >-
          {{ (state_attr('sensor.f1_next_race', 'qualifying_start') | as_datetime | as_local) - timedelta(minutes = 10 | int ) }}
      formula_one_sprint_start_notification:
        friendly_name: 'Formula One sprint start notification'
        device_class: timestamp
        value_template: >-
          {%- if state_attr('sensor.f1_next_race', 'sprint_start') != None %}
            {{ (state_attr('sensor.f1_next_race', 'sprint_start') | as_datetime | as_local) - timedelta(minutes = 10 | int ) }}
          {%- else %}
            None
          {%- endif %}

Automation

This is the core of the project. The automation is triggered by one of our template sensors. It sends an actionable notification to my phone with a dynamic message indicating which session is about to start (e.g., “F1 race is about to start”). The notification has two buttons: ‘Play on TV’, which runs our ADB script, and ‘Ignore’, which dismisses the alert. We use trigger_id to make the notification message context-aware.

Note: You must change the service: notify.mobile_app_pixel_9_pro_xl line to your own mobile device’s notification service.

automation:
  id: 'notify_f1_start'
  alias: 'Media: Notify F1 race start'
  trigger:
  - platform: time
    at: sensor.formula_one_qualifying_start_notification
    id: qualifying
  - platform: time
    at: sensor.formula_one_sprint_start_notification
    id: sprint
  - platform: time
    at: sensor.formula_one_race_start_notification
    id: race
  action:
    - alias: Set up variables for the actions
      variables:
        action_play_f1: "{{ 'PLAY_F1_' ~ context.id }}"
        action_no: "{{ 'NO_' ~ context.id }}"
    - alias: Notify Mobile
      service: notify.mobile_app_pixel_9_pro_xl
      data:
        message: F1 {{ trigger.id }} is about to start. Do you want to play it on TV?
        data:
          importance: high
          actions:
            - action: "{{ action_play_f1 }}"
              title: Play on TV
            - action: "{{ action_no }}"
              title: Ignore
    - alias: Wait for a response
      timeout:
        minutes: 10
      continue_on_timeout: false
      wait_for_trigger:
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            action: "{{ action_play_f1 }}"
    - alias: Perform the action
      choose:
        - conditions: "{{ wait.trigger.event.data.action == action_no }}"
          sequence: []
        - conditions: "{{ wait.trigger.event.data.action == action_play_f1 }}"
          sequence:
            - service: script.play_f1_tv_on_shield
              data: {}
  mode: single

BONUS: F1 Card

If you’re looking for a quick view of the upcoming F1 race inside Home Assistant, check out the F1 Card. This is a great-looking custom Lovelace card that provides information on the next race, driver and team standings, and the full season schedule.

Further Enhancements

I’m already thinking about future improvements to take this project even further:

  • Voice Notifications: Announce the alert through my smart speakers if I’m at home.
  • Voice Activation: Start the F1 stream with a voice command or by responding to the voice notification.
  • AI-Enriched Notifications: Use AI to add more context or fun facts to the notification text.

Leave a Reply

Your email address will not be published. Required fields are marked *