### F1 Formation Start Status Example Source: https://nicxe.github.io/f1_sensor/entities/live-data Represents the state of the F1 formation start procedure, indicating when it is ready. The state is typically 'on' when ready and 'off' otherwise. This is useful for triggering automations related to race starts. ```text on ``` -------------------------------- ### F1 Driver List JSON Structure Example Source: https://nicxe.github.io/f1_sensor/entities/live-data An example of the JSON structure for the F1 driver list, showing the 'drivers' array with individual driver details like racing number, name, team, and image URLs. ```json { "drivers": [ { "racing_number": "1", "tla": "VER", "name": "Max VERSTAPPEN", "first_name": "Max", "last_name": "Verstappen", "team": "Red Bull Racing", "team_color": "#3671C6", "team_color_rgb": [54, 113, 198], "headshot_small": "https://media.formula1.com/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png", "headshot_large": "https://media.formula1.com/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01-large.png", "reference": "max_verstappen" }, { "racing_number": "44", "tla": "HAM", "name": "Lewis HAMILTON", "first_name": "Lewis", "last_name": "Hamilton", "team": "Ferrari", "team_color": "#ED1131", "team_color_rgb": [237, 17, 49], "headshot_small": "https://media.formula1.com/content/dam/fom-website/drivers/L/LEWHAM01_Lewis_Hamilton/lewham01.png", "headshot_large": "https://media.formula1.com/content/dam/fom-website/drivers/L/LEWHAM01_Lewis_Hamilton/lewham01-large.png", "reference": "lewis_hamilton" } ] } ``` -------------------------------- ### F1 Driver Positions Sensor Data Example Source: https://nicxe.github.io/f1_sensor/entities/live-data This snippet shows an example of the live driver positions and lap-by-lap timing data available from the F1 sensor. It includes the current lap number and a detailed breakdown of each driver's status and performance metrics. ```json { "drivers": [ { "racing_number": "1", "tla": "VER", "name": "Max Verstappen", "team": "Red Bull Racing", "team_color": "#3671C6", "team_color_rgb": [54, 113, 198], "grid_position": "1", "current_position": "1", "laps": { "1": "1:32.456", "2": "1:31.789", "3": "1:31.234" }, "completed_laps": 45, "status": "on_track", "in_pit": false, "pit_out": false, "retired": false, "stopped": false, "fastest_lap": true, "fastest_lap_time": "1:29.123", "fastest_lap_time_secs": 89.123, "fastest_lap_lap": 42, "sector_1": 28.123, "sector_2": null, "sector_3": null, "sector_1_overall_fastest": true, "sector_1_personal_fastest": true, "sector_2_overall_fastest": null, "sector_2_personal_fastest": null, "sector_3_overall_fastest": null, "sector_3_personal_fastest": null, "best_sector_1": 27.891 } ], "total_laps": 71, "fastest_lap": { "driver_tla": "VER", "lap": 42, "time": "1:29.123" }, "current_qualifying_part": null } ``` -------------------------------- ### Get Position Changes from Grid with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template iterates through each driver and is intended to show their position changes from the starting grid. The provided snippet is a starting point for calculating these changes. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_positions', 'drivers') %} {% for d in drivers %} ``` -------------------------------- ### Jinja2: Count Drivers by Starting Compound Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to count the number of drivers who started a race on specific tyre compounds (MEDIUM and HARD) using the F1 Tyre Statistics sensor. It filters the 'start_compounds' list to count entries matching each compound. ```jinja2 {% set starts = state_attr('sensor.f1_tyre_statistics', 'start_compounds') %} {% if starts %} {% set mediums = starts | selectattr('compound', 'eq', 'MEDIUM') | list | length %} {% set hards = starts | selectattr('compound', 'eq', 'HARD') | list | length %} Started on MEDIUM: {{ mediums }} Started on HARD: {{ hards }} {% endif %} ``` -------------------------------- ### F1 Tyre Statistics Sensor - JSON Structure Example Source: https://nicxe.github.io/f1_sensor/entities/live-data This snippet shows the expected JSON structure for the F1 Tyre Statistics sensor data. It details the fields available for fastest times, compound deltas, starting compounds, and detailed statistics per compound, including best lap times, total laps, and tyre set usage. ```json { "fastest_time": "1:31.234", "fastest_time_secs": 91.234, "deltas": { "SOFT": "+0.000", "MEDIUM": "+0.342", "HARD": "+0.891" }, "start_compounds": [ { "racing_number": "1", "compound": "MEDIUM" }, { "racing_number": "44", "compound": "HARD" }, { "racing_number": "4", "compound": "MEDIUM" } ], "compounds": { "SOFT": { "best_times": [ { "time": "1:31.234", "racing_number": "1", "tla": "VER" }, { "time": "1:31.456", "racing_number": "4", "tla": "NOR" }, { "time": "1:31.567", "racing_number": "44", "tla": "HAM" } ], "total_laps": 45, "sets_used": 8, "sets_used_total": 12, "compound_color": "#FF0000", "compound_color_rgb": [255, 0, 0] }, "MEDIUM": { "best_times": [ { "time": "1:31.576", "racing_number": "1", "tla": "VER" }, { "time": "1:31.789", "racing_number": "16", "tla": "LEC" } ], "total_laps": 120, "sets_used": 15, "sets_used_total": 20, "compound_color": "#FFFF00", "compound_color_rgb": [255, 255, 0] }, "HARD": { "best_times": [ { "time": "1:32.125", "racing_number": "63", "tla": "RUS" } ], "total_laps": 80, "sets_used": 6, "sets_used_total": 8, "compound_color": "#FFFFFF", "compound_color_rgb": [255, 255, 255] } } } ``` -------------------------------- ### Example Predicted Driver TLA Source: https://nicxe.github.io/f1_sensor/entities/live-data This example shows the expected output for the predicted P1 driver's three-letter abbreviation (TLA) when available from the Championship Prediction sensor. ```text VER ``` -------------------------------- ### F1 Constructor Points Progression JSON Structure Source: https://nicxe.github.io/f1_sensor/entities/static-data Example JSON structure for the F1 Constructor Points Progression sensor, illustrating the data format for seasons, rounds, constructors, and series. ```json { "season": "2025", "rounds": [ { "round": "1", "race_name": "Bahrain Grand Prix", "date": "2025-03-02" }, { "round": "2", "race_name": "Saudi Arabian Grand Prix", "date": "2025-03-09" }, { "round": "3", "race_name": "Australian Grand Prix", "date": "2025-03-23" } ], "constructors": { "red_bull": { "name": "Red Bull Racing", "constructorId": "red_bull", "points_by_round": [44, 33, 40], "cumulative_points": [44, 77, 117], "wins_by_round": [1, 0, 1], "totals": { "points": 117, "wins": 2 } }, "ferrari": { "name": "Ferrari", "constructorId": "ferrari", "points_by_round": [33, 44, 28], "cumulative_points": [33, 77, 105], "wins_by_round": [0, 1, 0], "totals": { "points": 105, "wins": 1 } }, "mclaren": { "name": "McLaren", "constructorId": "mclaren", "points_by_round": [28, 25, 33], "cumulative_points": [28, 53, 86], "wins_by_round": [0, 0, 0], "totals": { "points": 86, "wins": 0 } } }, "series": { "labels": ["R1", "R2", "R3"], "series": [ { "key": "red_bull", "name": "Red Bull Racing", "data": [44, 33, 40], "cumulative": [44, 77, 117] }, { "key": "ferrari", "name": "Ferrari", "data": [33, 44, 28], "cumulative": [33, 77, 105] } ] } } ``` -------------------------------- ### Calibrating F1 Live Delay with Switch Entity Source: https://nicxe.github.io/f1_sensor/help/faq The F1 Sensor integration provides a built-in calibration workflow using the `switch.f1_delay_calibration` entity. This switch can be used to initiate a guided process for adjusting the live data delay. ```yaml switch.f1_delay_calibration ``` -------------------------------- ### Jinja2: Get Team Total Points Source: https://nicxe.github.io/f1_sensor/entities/static-data Jinja2 template to retrieve the total points for a specific constructor from the F1 sensor data. It accesses the 'constructors' attribute and then the 'totals.points' for the specified team. ```jinja2 {% set constructors = state_attr('sensor.f1_constructor_points_progression', 'constructors') %} {% if constructors and constructors.red_bull %} Red Bull total: {{ constructors.red_bull.totals.points }} points {% endif %} ``` -------------------------------- ### GET sensor.f1_weather Source: https://nicxe.github.io/f1_sensor/entities/static-data Retrieves current and projected weather data for the upcoming F1 race circuit location. ```APIDOC ## GET sensor.f1_weather ### Description Provides compact weather data for the current circuit location, including current conditions and projected weather at race start. ### Method GET ### Endpoint sensor.f1_weather ### Response #### Success Response (200) - **state** (number) - Current air temperature (°C) - **attributes** (object) - Contains detailed weather metrics including humidity, cloud cover, precipitation, wind speed, and race-start projections. #### Response Example { "state": 18.6, "attributes": { "season": "2023", "race_name": "British Grand Prix", "current_temperature": 18.6, "current_humidity": 65, "race_weather_icon": "mdi:weather-partly-cloudy" } } ``` -------------------------------- ### Accessing F1 Track Limits Data via Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data Examples of how to retrieve and filter track limit data from the sensor attributes using Jinja2 templates. These snippets demonstrate accessing specific driver data, identifying drivers at risk, and summarizing session-wide statistics. ```Jinja2 {% set by_driver = state_attr('sensor.f1_track_limits', 'by_driver') %} {% set ham = by_driver.get('HAM') %} {% if ham %} HAM: {{ ham.deletions }} deletions{% if ham.warning %}, WARNING{% endif %} {% endif %} ``` ```Jinja2 {% set by_driver = state_attr('sensor.f1_track_limits', 'by_driver') %} {% for tla, data in by_driver.items() if data.warning %} {{ tla }} (#{{ data.racing_number }}) - {{ data.deletions }} deletions {% endfor %} ``` ```Jinja2 {% set by_driver = state_attr('sensor.f1_track_limits', 'by_driver') %} {% for tla, data in by_driver.items() if data.deletions >= 3 and not data.warning %} {{ tla }}: {{ data.deletions }} deletions - at risk! {% endfor %} ``` ```Jinja2 {% set deletions = state_attr('sensor.f1_track_limits', 'total_deletions') %} {% set warnings = state_attr('sensor.f1_track_limits', 'total_warnings') %} {% set penalties = state_attr('sensor.f1_track_limits', 'total_penalties') %} Deletions: {{ deletions }}, Warnings: {{ warnings }}, Penalties: {{ penalties }} ``` ```Jinja2 {% set by_driver = state_attr('sensor.f1_track_limits', 'by_driver') %} {% for tla, data in by_driver.items() if data.penalty %} {{ tla }}: {{ data.penalty }} {% endfor %} ``` -------------------------------- ### GET sensor.f1_driver_positions Source: https://nicxe.github.io/f1_sensor/entities/live-data Retrieves live driver positions and detailed lap-by-lap timing data for all drivers currently in the session. ```APIDOC ## GET sensor.f1_driver_positions ### Description Retrieves the current state of the F1 session, including a list of drivers, their positions, lap times, and sector performance metrics. ### Method GET ### Endpoint sensor.f1_driver_positions ### Response #### Success Response (200) - **drivers** (list) - List of driver objects containing performance and status data. - **total_laps** (number) - Total race distance in laps. - **fastest_lap** (object) - Fastest lap details for the session. - **current_qualifying_part** (number) - Active qualifying segment (1, 2, or 3). #### Response Example { "drivers": [ { "racing_number": "1", "tla": "VER", "name": "Max Verstappen", "team": "Red Bull Racing", "team_color": "#3671C6", "current_position": "1", "status": "on_track", "completed_laps": 45 } ], "total_laps": 58, "current_qualifying_part": null } ``` -------------------------------- ### F1 Current Tyres Sensor JSON Structure Source: https://nicxe.github.io/f1_sensor/entities/live-data This is an example of the JSON structure returned by the F1 Current Tyres sensor. It includes a list of drivers, each with their racing number, team information, current position, tyre compound details, and stint information. ```json { "drivers": [ { "racing_number": "1", "tla": "VER", "team_color": "#3671C6", "team_color_rgb": [54, 113, 198], "position": "1", "compound": "MEDIUM", "compound_short": "M", "compound_color": "#FFFF00", "compound_color_rgb": [255, 255, 0], "new": false, "stint_laps": 15 }, { "racing_number": "44", "tla": "HAM", "team_color": "#ED1131", "team_color_rgb": [237, 17, 49], "position": "2", "compound": "HARD", "compound_short": "H", "compound_color": "#FFFFFF", "compound_color_rgb": [255, 255, 255], "new": true, "stint_laps": 3 }, { "racing_number": "4", "tla": "NOR", "team_color": "#FF8000", "team_color_rgb": [255, 128, 0], "position": "3", "compound": "SOFT", "compound_short": "S", "compound_color": "#FF0000", "compound_color_rgb": [255, 0, 0], "new": true, "stint_laps": 1 } ] } ``` -------------------------------- ### Jinja2: Get Team Color for Styling Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template shows how to get a driver's team color using their racing number. The retrieved hex color code can be used for CSS styling, such as setting a background color. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_list', 'drivers') %} {% set driver = drivers | selectattr('racing_number', 'eq', '44') | first %} {% if driver %} background-color: {{ driver.team_color }}; {% endif %} ``` -------------------------------- ### GET sensor.f1_last_race_results Source: https://nicxe.github.io/f1_sensor/entities/static-data Retrieves the results of the most recent Formula 1 race. ```APIDOC ## GET sensor.f1_last_race_results ### Description Returns the results of the most recent race, with the state representing the winner's family name. ### Method GET ### Endpoint sensor.f1_last_race_results ### Response #### Success Response (200) - **state** (string) - Winner's surname - **attributes** (object) - Contains race metadata, circuit details, and a list of results including driver and constructor information. #### Response Example { "state": "Verstappen", "attributes": { "race_name": "British Grand Prix", "results": [ { "position": 1, "driver": { "givenName": "Max", "familyName": "Verstappen" }, "constructor": { "name": "Red Bull" } } ] } } ``` -------------------------------- ### Session Start Reminder (YAML) Source: https://nicxe.github.io/f1_sensor/automation This automation sends a reminder notification 30 minutes before any F1 session (practice, qualifying, sprint, or race) using the F1 Season Calendar entity. The reminder message includes the session summary. The offset can be adjusted to change the reminder timing. ```yaml alias: F1 - Session starting soon description: Send a reminder 30 minutes before any F1 session trigger: - platform: calendar event: start entity_id: calendar.f1_season_calendar offset: "-0:30:0" condition: [] action: - service: notify.mobile_app_your_phone data: title: "F1 starting soon" message: "{{ trigger.calendar_event.summary }} starts in 30 minutes." mode: single ``` -------------------------------- ### F1 Sensor Current Lap Number Example Source: https://nicxe.github.io/f1_sensor/entities/live-data This snippet demonstrates how to access the current lap number from the F1 sensor data. The value is an integer representing the leader's current lap, or 'unknown' if the data is not available. ```text 45 ``` -------------------------------- ### Jinja2: Get Points in Last Round Source: https://nicxe.github.io/f1_sensor/entities/static-data Jinja2 template to calculate and display the points scored by a constructor in the most recent round. It accesses the 'points_by_round' list and retrieves the last element. ```jinja2 {% set constructors = state_attr('sensor.f1_constructor_points_progression', 'constructors') %} {% set ferrari = constructors.ferrari %} {% if ferrari %} {% set pts = ferrari.points_by_round %} Ferrari last round: {{ pts[-1] if pts else 0 }} points {% endif %} ``` -------------------------------- ### GET sensor.f1_tyre_statistics Source: https://nicxe.github.io/f1_sensor/entities/live-data Retrieves the aggregated tyre performance statistics. The state represents the fastest compound, while attributes contain detailed performance metrics. ```APIDOC ## GET sensor.f1_tyre_statistics ### Description Returns the aggregated tyre performance statistics for a race, including fastest lap times, deltas between compounds, and usage data per driver. ### Method GET ### Endpoint sensor.f1_tyre_statistics ### Parameters #### Path Parameters - **None** #### Query Parameters - **None** ### Request Body - **None** ### Request Example N/A (State-based sensor) ### Response #### Success Response (200) - **state** (string) - Name of the fastest compound (e.g., "SOFT") or "unknown". - **fastest_time** (string) - Overall fastest lap time across all compounds. - **fastest_time_secs** (number) - Fastest lap time in seconds. - **deltas** (object) - Time delta to fastest for each compound. - **start_compounds** (list) - List of compounds used at race start per driver. - **compounds** (object) - Detailed statistics per compound (best_times, total_laps, sets_used, compound_color). #### Response Example { "fastest_time": "1:31.234", "fastest_time_secs": 91.234, "deltas": { "SOFT": "+0.000", "MEDIUM": "+0.342", "HARD": "+0.891" }, "start_compounds": [ { "racing_number": "1", "compound": "MEDIUM" } ], "compounds": { "SOFT": { "best_times": [{ "time": "1:31.234", "racing_number": "1", "tla": "VER" }], "total_laps": 45, "sets_used": 8, "compound_color": "#FF0000" } } } ``` -------------------------------- ### Home Assistant Race Control Event Payloads Source: https://nicxe.github.io/f1_sensor/entities/events Example payloads for the 'f1_sensor_race_control_event' in Home Assistant. These events provide real-time race control communications like flags and incident reports, complementing the Race Control sensor. ```yaml event_type: f1_sensor_race_control_event data: message: Utc: "2025-09-19T12:40:18" Category: Flag Flag: CLEAR Scope: Sector Sector: 6 Message: CLEAR IN TRACK SECTOR 6 received_at: "2025-09-19T12:40:44+00:00" origin: LOCAL time_fired: "2025-09-19T12:40:44.106956+00:00" event_type: f1_sensor_race_control_event data: message: Utc: "2025-09-19T12:40:07" Category: Flag Flag: YELLOW Scope: Sector Sector: 6 Message: YELLOW IN TRACK SECTOR 6 received_at: "2025-09-19T12:40:44+00:00" event_type: f1_sensor_race_control_event data: message: Utc: "2025-09-19T12:40:06" Category: Other Message: INCIDENT INVOLVING CAR 81 (PIA) NOTED - YELLOW FLAG INFRINGEMENT received_at: "2025-09-19T12:40:44+00:00" ``` -------------------------------- ### Jinja2: Get Team with Most Wins Source: https://nicxe.github.io/f1_sensor/entities/static-data Jinja2 template to identify and display the constructor with the highest number of wins. It sorts constructors by their 'totals.wins' attribute in descending order and selects the first one. ```jinja2 {% set constructors = state_attr('sensor.f1_constructor_points_progression', 'constructors') %} {% set winner = constructors.values() | sort(attribute='totals.wins', reverse=true) | first %} {% if winner %} Most wins: {{ winner.name }} with {{ winner.totals.wins }} {% endif %} ``` -------------------------------- ### GET sensor.f1_session_time_remaining Source: https://nicxe.github.io/f1_sensor/entities/live-data Retrieves the amount of scheduled session time remaining, accounting for pauses during interruptions. ```APIDOC ## GET sensor.f1_session_time_remaining ### Description Returns the remaining scheduled time for the current F1 session. Note that this does not account for lap-based race endings. ### Method GET ### Endpoint sensor.f1_session_time_remaining ### Response #### Success Response (200) - **state** (string) - Remaining time formatted as H:MM:SS or 'unavailable'. - **session_type** (string) - Type of session. - **value_seconds** (number) - Remaining time in whole seconds. - **clock_total_s** (number) - Total scheduled duration in seconds. #### Response Example { "state": "0:36:15", "attributes": { "session_type": "Practice", "value_seconds": 2175, "clock_total_s": 3600 } } ``` -------------------------------- ### GET sensor.f1_session_time_elapsed Source: https://nicxe.github.io/f1_sensor/entities/live-data Retrieves the amount of scheduled session time that has passed, accounting for pauses during interruptions. ```APIDOC ## GET sensor.f1_session_time_elapsed ### Description Returns the elapsed time for the current F1 session based on the ExtrapolatedClock feed. The clock pauses during red flags or safety car periods. ### Method GET ### Endpoint sensor.f1_session_time_elapsed ### Response #### Success Response (200) - **state** (string) - Elapsed time formatted as H:MM:SS or 'unavailable'. - **session_type** (string) - Type of session (e.g., "Practice"). - **value_seconds** (number) - Elapsed time in whole seconds. - **source_quality** (string) - Reliability of the data source (official, official_no_heartbeat, sessiondata_fallback, or unavailable). #### Response Example { "state": "0:23:45", "attributes": { "session_type": "Practice", "value_seconds": 1425, "source_quality": "official" } } ``` -------------------------------- ### Get Predicted Champion with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to retrieve and display the predicted Formula 1 champion's three-letter abbreviation (TLA) and their predicted points from the F1 Championship Prediction sensor. ```jinja2 {% set p1 = state_attr('sensor.f1_championship_prediction_drivers', 'predicted_driver_p1') %} {% if p1 %} Predicted champion: {{ p1.tla }} with {{ p1.points }} points {% endif %} ``` -------------------------------- ### Automate Formation Lap Notification Source: https://nicxe.github.io/f1_sensor/automation Triggers a notification when the formation lap binary sensor turns on. This provides an early warning that the race is about to start. ```yaml alias: F1 - Formation lap started description: Notify when the formation lap begins trigger: - platform: state entity_id: binary_sensor.f1_formation_start to: "on" condition: [] action: - service: notify.mobile_app_your_phone data: title: "Formation lap" message: "The formation lap has started. Lights out soon." mode: single ``` -------------------------------- ### Get Specific Driver by Number with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template shows how to find a specific driver using their racing number. It selects the driver from the list where 'racing_number' matches the specified value and then displays their name and current position. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_positions', 'drivers') %} {% set driver = drivers | selectattr('racing_number', 'eq', '44') | first %} {% if driver %} {{ driver.name }} is in P{{ driver.current_position }} {% endif %} ``` -------------------------------- ### Jinja2: Get Predicted Constructors Champion Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet retrieves and displays the name of the team currently predicted to win the constructors' championship. It accesses the `predicted_team_p1` attribute from the F1 championship prediction sensor. ```jinja2 {% set p1 = state_attr('sensor.f1_championship_prediction_teams', 'predicted_team_p1') %} {% if p1 %} Predicted constructors champion: {{ p1.team_name }} {% endif %} ``` -------------------------------- ### Jinja2: Get Fastest Compound Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to retrieve the name of the fastest tyre compound from the F1 Tyre Statistics sensor state. It directly accesses the sensor's state, which is expected to be a string representing the fastest compound or 'unknown'. ```jinja2 Fastest compound: {{ states('sensor.f1_tyre_statistics') }} ``` -------------------------------- ### Jinja2: Get Driver Headshot URL Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to retrieve the large headshot URL for a specific driver using their three-letter abbreviation (TLA). It filters the drivers list and selects the first match. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_list', 'drivers') %} {% set ver = drivers | selectattr('tla', 'eq', 'VER') | first %} {% if ver %} {{ ver.headshot_large }} {% endif %} ``` -------------------------------- ### Jinja2: Get Driver's Current Tyre Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to retrieve and display the current tyre compound and stint information for a specific driver, identified by their TLA (three-letter abbreviation). It checks if the driver exists and then formats the output, indicating if the tyres are new. ```jinja2 {% set drivers = state_attr('sensor.f1_current_tyres', 'drivers') %} {% set ver = drivers | selectattr('tla', 'eq', 'VER') | first %} {% if ver %} VER on {{ ver.compound }} ({{ ver.stint_laps }} laps{% if ver.new %}, NEW{% endif %}) {% endif %} ``` -------------------------------- ### Getting Current Session Name with Sensor Source: https://nicxe.github.io/f1_sensor/help/faq As of version 2.2.0, the `sensor.f1_current_session` entity indicates the name of the currently running F1 session (e.g., 'Practice 1', 'Qualifying', 'Race'). This complements the session status sensor by providing specific session identification. ```yaml sensor.f1_current_session ``` -------------------------------- ### Get Race Leader with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet demonstrates how to retrieve the current race leader's details from the F1 sensor data. It filters the drivers list to find the driver with 'current_position' equal to '1'. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_positions', 'drivers') %} {% if drivers %} {% set leader = drivers | selectattr('current_position', 'eq', '1') | first %} {% if leader %} Leader: {{ leader.tla }} ({{ leader.name }}) {% endif %} {% endif %} ``` -------------------------------- ### Jinja2: Get Fastest Time on Specific Compound Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet shows how to extract the fastest lap time for a specific tyre compound (e.g., SOFT) from the F1 Tyre Statistics sensor. It accesses the 'compounds' attribute, filters for the desired compound, and then retrieves the 'time' from the first entry in its 'best_times' list. ```jinja2 {% set compounds = state_attr('sensor.f1_tyre_statistics', 'compounds') %} {% if compounds and compounds.SOFT %} {% set best = compounds.SOFT.best_times | first %} Fastest on SOFT: {{ best.time }} by {{ best.tla }} {% endif %} ``` -------------------------------- ### Jinja2: Count Drivers by Tyre Compound Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template snippet counts the number of drivers on each tyre compound (SOFT, MEDIUM, HARD). It filters the driver list by compound and then uses the 'length' filter to get the count for each. ```jinja2 {% set drivers = state_attr('sensor.f1_current_tyres', 'drivers') %} {% if drivers %} SOFT: {{ drivers | selectattr('compound', 'eq', 'SOFT') | list | length }} MEDIUM: {{ drivers | selectattr('compound', 'eq', 'MEDIUM') | list | length }} HARD: {{ drivers | selectattr('compound', 'eq', 'HARD') | list | length }} {% endif %} ``` -------------------------------- ### Jinja2: Get Driver by Car Number in F1 Standings Source: https://nicxe.github.io/f1_sensor/entities/static-data This Jinja2 template snippet retrieves and displays information for a driver based on their permanent car number. It uses the 'selectattr' filter to find the driver with the matching 'Driver.permanentNumber'. ```jinja2 {% set standings = state_attr('sensor.f1_driver_standings', 'driver_standings') %} {% set driver = standings | selectattr('Driver.permanentNumber', 'eq', '44') | first %} {% if driver %} #44 {{ driver.Driver.familyName }} is P{{ driver.position }} {% endif %} ``` -------------------------------- ### Get Driver's Last Lap Time with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template retrieves the last completed lap time for a specific driver. It first finds the driver by their racing number, then accesses their 'laps' dictionary using the 'completed_laps' count as the key. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_positions', 'drivers') %} {% set driver = drivers | selectattr('racing_number', 'eq', '1') | first %} {% if driver and driver.laps %} {% set last_lap = driver.completed_laps | string %} Last lap: {{ driver.laps.get(last_lap, 'N/A') }} {% endif %} ``` -------------------------------- ### Jinja2: Get Championship Leader from F1 Driver Standings Source: https://nicxe.github.io/f1_sensor/entities/static-data This Jinja2 template snippet demonstrates how to retrieve the championship leader's name and points from the F1 driver standings sensor. It accesses the 'driver_standings' attribute and extracts information from the first entry in the list. ```jinja2 {% set standings = state_attr('sensor.f1_driver_standings', 'driver_standings') %} {% if standings and standings | length > 0 %} {% set leader = standings[0] %} Leader: {{ leader.Driver.givenName }} {{ leader.Driver.familyName }} ({{ leader.points }} pts) {% endif %} ``` -------------------------------- ### Notify when Race Week Begins (YAML) Source: https://nicxe.github.io/f1_sensor/automation This automation uses the F1 Race Week sensor to send a notification when race week starts. It's useful for initiating weekly routines or providing a heads-up about upcoming events. The notification includes details about the next race. ```yaml alias: F1 - Race week started description: Notify when race week begins trigger: - platform: state entity_id: binary_sensor.f1_race_week to: "on" condition: [] action: - service: notify.mobile_app_your_phone data: title: "Formula 1" message: > Race week is here! Next up: {{ state_attr('sensor.f1_next_race', 'race_name') }} at {{ state_attr('sensor.f1_next_race', 'circuit_name') }}. mode: single ``` -------------------------------- ### Jinja2: Get Specific Driver's F1 Standings Source: https://nicxe.github.io/f1_sensor/entities/static-data This Jinja2 template snippet shows how to find and display the position, points, and wins for a specific driver using their three-letter code (TLA). It filters the 'driver_standings' list based on the 'Driver.code' attribute. ```jinja2 {% set standings = state_attr('sensor.f1_driver_standings', 'driver_standings') %} {% set ver = standings | selectattr('Driver.code', 'eq', 'VER') | first %} {% if ver %} VER is P{{ ver.position }} with {{ ver.points }} points and {{ ver.wins }} wins {% endif %} ``` -------------------------------- ### Jinja2: List All Teams by Points Source: https://nicxe.github.io/f1_sensor/entities/static-data Jinja2 template to list all constructors ordered by their total points in descending order. It iterates through the sorted constructors and displays their name and points. ```jinja2 {% set constructors = state_attr('sensor.f1_constructor_points_progression', 'constructors') %} {% for c in constructors.values() | sort(attribute='totals.points', reverse=true) %} {{ c.name }}: {{ c.totals.points }} pts {% endfor %} ``` -------------------------------- ### Jinja2: Create Driver Lookup by TLA Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template creates a dictionary (lookup table) where keys are driver TLAs and values are the corresponding driver objects. This allows for quick retrieval of driver information by their abbreviation. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_list', 'drivers') %} {% set lookup = dict.from_keys(drivers | map(attribute='tla') | list, drivers) %} {{ lookup.VER.name }} drives for {{ lookup.VER.team }} ``` -------------------------------- ### Jinja2: Set Light to Driver's Team Color Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template demonstrates how to control a light entity by setting its color to a driver's team color. It retrieves the RGB values for the team and uses the `light.turn_on` service. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_list', 'drivers') %} {% set ver = drivers | selectattr('tla', 'eq', 'VER') | first %} {% if ver and ver.team_color_rgb %} service: light.turn_on data: entity_id: light.living_room rgb_color: {{ ver.team_color_rgb }} {% endif %} ``` -------------------------------- ### Retrieve and Sort Q3 Qualifying Results Source: https://nicxe.github.io/f1_sensor/entities/live-data Fetches driver data from the F1 sensor, filters for those who set a Q3 time, and sorts them by their Q3 position. Outputs a list of drivers with their respective times. ```Jinja2 {% set drivers = state_attr('sensor.f1_driver_positions', 'drivers') %} {% set q3 = drivers | selectattr('q3_time', 'ne', None) | sort(attribute='q3_position') %} {% for d in q3 %} P{{ d.q3_position }}: {{ d.tla }} — {{ d.q3_time }} {% endfor %} ``` -------------------------------- ### Enable Debug Logging for F1 Sensor Source: https://nicxe.github.io/f1_sensor/help/beta-tester This configuration snippet enables debug logging for the F1 Sensor custom component within Home Assistant. It requires adding a 'logger' section to your `configuration.yaml` file. This is crucial for troubleshooting and providing detailed logs when reporting issues. ```yaml logger: default: warning logs: custom_components.f1_sensor: debug ``` -------------------------------- ### Jinja2 Templates for F1 Investigation Data Source: https://nicxe.github.io/f1_sensor/entities/live-data Collection of Jinja2 templates for querying and displaying F1 investigation data within Home Assistant. These snippets demonstrate how to filter investigations, list penalties, and summarize active matters. ```jinja2 {% set investigations = state_attr('sensor.f1_investigations', 'under_investigation') %} {% set ver_involved = investigations | selectattr('drivers', 'contains', 'VER') | list %} {% if ver_involved | length > 0 %} VER is under investigation! {% endif %} ``` ```jinja2 {% set penalties = state_attr('sensor.f1_investigations', 'penalties') %} {% for p in penalties %} {{ p.driver }}: {{ p.penalty }} ({{ p.reason }}) {% endfor %} ``` ```jinja2 {% set noted = state_attr('sensor.f1_investigations', 'noted') | length %} {% set investigating = state_attr('sensor.f1_investigations', 'under_investigation') | length %} Noted: {{ noted }}, Under Investigation: {{ investigating }} ``` ```jinja2 {% set investigations = state_attr('sensor.f1_investigations', 'under_investigation') %} {% for inv in investigations if inv.after_race %} {{ inv.drivers | join(' vs ') }} - {{ inv.reason }} (after race) {% endfor %} ``` ```jinja2 {% set nfi = state_attr('sensor.f1_investigations', 'no_further_action') %} {% for item in nfi %} {{ item.drivers | join('/') }}: No Further Action ({{ item.reason }}) {% endfor %} ``` -------------------------------- ### Query F1 Sensor Data with Jinja2 Source: https://nicxe.github.io/f1_sensor/entities/static-data Use Jinja2 templates to extract specific driver statistics, calculate rolling sums, or iterate through race calendars from the sensor attributes. ```Jinja2 {% set drivers = state_attr('sensor.f1_driver_points_progression', 'drivers') %} {# Get total points #} {{ drivers.VER.totals.points }} {# Get last round points #} {% set pts = drivers.VER.points_by_round %} {{ pts[-1] if pts else 0 }} {# Calculate last 3 rounds sum #} {{ drivers.VER.points_by_round[-3:] | sum }} {# Get driver with most wins #} {% set winner = drivers.values() | sort(attribute='totals.wins', reverse=true) | first %} {{ winner.code }} ``` -------------------------------- ### Configure Home Assistant Template Integration Source: https://nicxe.github.io/f1_sensor/example/custom-card-by Enables the template integration in the main configuration file by including an external YAML file. ```yaml template: !include templates.yaml ``` -------------------------------- ### Jinja2: Generate Image Elements for All Drivers Source: https://nicxe.github.io/f1_sensor/entities/live-data This Jinja2 template generates HTML image elements for each driver in the list. It uses the driver's small headshot URL and team color to create styled image tags. ```jinja2 {% set drivers = state_attr('sensor.f1_driver_list', 'drivers') %} {% for d in drivers %} {{ d.name }} {% endfor %} ``` -------------------------------- ### Import F1 Track Status Blueprint Source: https://nicxe.github.io/f1_sensor/blueprints/track-status-light This code snippet provides the URL to import the F1 Sensor Track Status Light blueprint into Home Assistant. This blueprint automates the control of RGB lights based on live F1 race conditions. ```yaml https://raw.githubusercontent.com/Nicxe/f1_sensor/main/blueprints/f1_track_status.yaml ``` -------------------------------- ### Jinja2: Calculate Gap Between Teams Source: https://nicxe.github.io/f1_sensor/entities/static-data Jinja2 template to compute and display the point difference between two constructors. It subtracts the total points of one team from another. ```jinja2 {% set c = state_attr('sensor.f1_constructor_points_progression', 'constructors') %} {% if c.red_bull and c.ferrari %} {% set gap = c.red_bull.totals.points - c.ferrari.totals.points %} Red Bull leads Ferrari by {{ gap }} points {% endif %} ```