Formula One Card

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