Formula One Card

Here one but I recall others

and as the post you linked/replied to even states it’s Off Topic for this thread about F1…that’s what Marco is getting at :man_shrugging:t2:

edit…or maybe he’s not reading below…my bad

O yeah right. Im sorry

No worries - thought who like f1 might be interested in MotoGP too. Sorry to ot

1 Like

I’m only coming here now… I’m passionate about F1 but I know very little about the possibilities of Home assistant.
I tried to look at the linked post on Formula one API but the project is no longer supported I read. How should I go about using this card?

Edit: sorry I solve it. Now i try to make a good card :slight_smile:

Or just use the card this thread is about?

1 Like

Yes, sure, and I apologize, I intended that it was necessary to use the API of the first post.
Sorry

Sorry, I did not understand if you can see the partial results, for example now see the results of free practice

Only qualifying, sprint and race

With what card? The last visible result for me is the race in Saudi Arabia

The results card. But the api is unreliable lately.
Hope it will get better when the new api is ready. Both apis not developed by me btw

2 Likes

I can confirm this. Frequently I get error messages. Sometimes for all data, sometimes just for a part of it. Today is bad again. Next race, results, driver standings, constructor standings and schedule all in error.

Thx for sharing, happy with my new view!

1 Like

Hi all,
there’s a way to get countdown or race date as a sensor?

thanks

This one is calculating a number of different count-downs. It is not optimized at all, however flexible for count-down to a lot of different things. So, I do not optimize as this is easy to copy and reuse.

e = total hours with decimals
f = days with decimals
da = days, no decimals
h= hours within the day
m=minutes in the hour (if you need this one, then change the trigger part)

the variable you set in {{ }} is the value of the sensor. In below example the sensor will show number of days, with no decimals

  - trigger:
    - platform: time_pattern
      minutes: 0
      seconds: 0
    sensor:  
      - name: f1_nextrace_dage
        state: >
          {% set b = state_attr('calendar.f1_calendar','start_time')  %}
          {% set c = now() %}
          {% set d =  as_timestamp(b)- as_timestamp(c) %}
          {% set e = d / 60 / 60 %}
          {% set f = e / 24 %}
          {% set da = ( f ) |int %}
          {% set h = (( e ) - ((f)|int*24)) | int  %}
          {% set m = ((e%1) *60 ) | int %}
          {{da}}

Ty for answer, where did u get the f1 calendar?

Sorry, was showing my “home made calendar”, as the API was not updating earlier this year. The API works now.

Here is the full version, using the REST sensor, found in post 88 in this thread.

template:
  - trigger:
    - platform: time_pattern
      minutes: 0
    sensor:  
      - name: f1_nextrace_dage
        state: >
          {% set b = states.sensor.f1_nextrace.attributes.race_start  %}
          {% set c = now() %}
          {% set d =  as_timestamp(b)- as_timestamp(c) %}
          {% set e = d / 60 / 60 %}
          {% set f = e / 24 %}
          {% set da = ( f ) |int %}
          {% set h = (( e ) - ((f)|int*24)) | int  %}
          {% set m = ((e%1) *60 ) | int %}
          {{da}}
  - trigger:
    - platform: time_pattern
      minutes: 0
    sensor:  
      - name: f1_nextrace_timer
        state: >
          {% set b = states.sensor.f1_nextrace.attributes.race_start  %}
          {% set c = now() %}
          {% set d =  as_timestamp(b)- as_timestamp(c) %}
          {% set e = d / 60 / 60 %}
          {% set f = e / 24 %}
          {% set da = ( f ) |int %}
          {% set h = (( e ) - ((f)|int*24)) | int  %}
          {% set m = ((e%1) *60 ) | int %}
          {{h}}

##############3
## See link for information : https://community.home-assistant.io/t/formula-one-card/476902/91
## Se comment 88
#############
sensor:
  - platform: rest
    scan_interval: 86400
    resource_template: http://ergast.com/api/f1/{{ now().strftime('%Y') }}.json
    name: "F1 Schedule"
    json_attributes_path: "$.MRData"
    value_template: "OK"
    json_attributes:
      - "total"
      - "RaceTable"

  - platform: template
    sensors:
      f1_nextrace:
        friendly_name: 'Formula One Next Race'
        attribute_templates:
          data: >-
            {% set data = namespace(found=False) %}
            {% for race in state_attr("sensor.f1_schedule", "RaceTable").Races if data.found == false -%}  
              {% set datetime = ((race.date + 'T' + race.time) | as_datetime) -%}
              {%- if datetime > now() -%}
                {{ race }}
                {% set data.found = true %}
              {%- endif %}
            {%- endfor %}
          race_name: >-
            {%- if 'data' in this.attributes -%}
              {{ this.attributes.data.raceName }}        
            {%- endif %}
          race_start: >-
            {%- if 'data' in this.attributes -%}     
              {{ ((this.attributes.data.date + 'T' + this.attributes.data.time) | as_datetime) }}        
            {%- endif %}
          first_practice: >-
            {%- if 'data' in this.attributes -%}
              {{ ((this.attributes.data.FirstPractice.date + 'T' + this.attributes.data.FirstPractice.time) | as_datetime) }}        
            {%- endif %}     
          second_practice: >-
            {%- if 'data' in this.attributes -%}
              {{ ((this.attributes.data.SecondPractice.date + 'T' + this.attributes.data.SecondPractice.time) | as_datetime) }}        
            {%- endif %}
          third_practice: >-
            {%- if 'data' in this.attributes -%}
              {{ ((this.attributes.data.ThirdPractice.date + 'T' + this.attributes.data.ThirdPractice.time) | as_datetime) }}        
            {%- endif %}
          qualifying: >-
            {%- if 'data' in this.attributes and 'Qualifying' in this.attributes.data -%}
              {{ ((this.attributes.data.Qualifying.date + 'T' + this.attributes.data.Qualifying.time) | as_datetime) }}          
            {% else %}
              -
            {%- endif %}
          sprint: >-
            {%- if 'data' in this.attributes and 'Sprint' in this.attributes.data -%}
              {{ ((this.attributes.data.Sprint.date + 'T' + this.attributes.data.Sprint.time) | as_datetime) }}          
            {% else %}
              -
            {%- endif %}
        value_template: >-
          on
          
2 Likes

Keep in mind that the API isnt updating after this season

Just noticed the video link in the readme is using a photo of Formula E in monaco(3rd car is a mahindra that has only been in FE)