Sports Standings and Scores

Thanks @kbrown01 - I had tried that but the challenge was that I want to show all big 12 games and if a Big 12 team is not playing at home they are not shown. This weekend as an example TCU is away but it is masked because of the number of Big12 vs Big12 games.

What I was trying to do was create a list on venues and then when the next team was cycled through I could see if the venue was already in the list and then I would bypass that card.

If your list is big 12 entries then I would thing the logic would be:

For all Big 12 teams ā€¦

a) If team is home, output card
b) Else (away) if they are not playing a big 12 team, output card

End For

I am trying to noodle your thought. If a Big 12 is playing a Big 12 team - attribute team_homeaway is either (home or away) So 1 Big 12 team would show home other shows away. How would I gate the Away logic so I know that they are not playing a Big 12 team but they are away? I was hoping to use conference_id and with that not in the sensor, I have been trying to use either venue or I also was trying to put team_abbr and opponent_abbr in a list to check if that card has been displayed yet.

Can post the URL you are using to get the data? Then I can hit it and look though what is there. IF the sensor is only Big 12, then the second test would be away teams, then if the home team is in the Big 12, show it ā€¦ if not donā€™t (because you would already have the Big 12 team as a home team).

I believe Teamtracker is doing that. The sensor above is created in the sensors.yaml. Here is what is getting pulled.

- platform: teamtracker
  league_id: "NCAAF"
  team_id: "ASU"
  sport_path: football   
  league_path: "college-football"  
  conference_id: 4
  name: "Arizona State University"

I would need to look at @vasqued2 code but my guess is that it is automatically either adding 4 (conference_id) or 80 to the pull and I am assuming it is this link - https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard?groups=4

Ah. I was thinking standings. Then yes, you would need something in the data. I will need to create NCAAF team(s) to diagnose.

No I am trying to filter the cards by conference. I am going to add more tabs that are similar to what I have for big 12 for all of the other NCAAF conferences. A kind of 1-stop conference shop that has the conference standings, more statistics, schedules and games. I am not going to separate out pre,live,post because there will only be less than 20 on each tab. But I want to show all conference games within that tab. I think I am on the right path with the list, but HA isnā€™t letting me compare the current (for loop) venue with the list I am adding it to. I know it is seeing venue because as a test I stuck Venue as a title in the TT card and it shows up. Itā€™s the gate logic that is failing.

You canā€™t modify a list in a loop and use it later without using namespaces. In YAML, a variableā€™s context is only within the loop.

Take this example from my NHL standings:

###
### NHL Wildcard
###
  - name: NHL Wildcard Standings
    unique_id: sensor.nhl_wildcard_standings
    state: "{{ now() }}"
    attributes:
      east_atlantic_top: "{{ state_attr('sensor.nhl_wildcard','overall')[0]['children'][0]['standings']['entries'] }}"
      east_metropolitan_top: "{{ state_attr('sensor.nhl_wildcard','overall')[0]['children'][1]['standings']['entries'] }}"
      east_wildcard: "{{ state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'][:2] }}"
      east_hunt: >
          {% set hteams = namespace(hteam=[]) %}
          {% for team in state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'][2:] %}
            {% for stat in team['stats'] | selectattr('name','eq','clincher') %}
            {% else %}
                  {% set hteams.hteam = hteams.hteam + [team] %}
            {% endfor %}
          {% endfor %}
          {{ hteams.hteam }}

You use a ā€œsetā€ to create a namespaced variable and then you can use that outside of the loop.

Thanks - not a Jinja2 expert but it looks like this is filtering teams to find the teams that are still in the hunt. I am looking to filter the cards being displayed inside the For loop. something like this (I know this isnā€™t correct but you can see my logic

ncaaf_conference_game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: grid
        layout:
          grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))
      card_param: cards
      filter:
        template: |
          {% set venue = namespace(venuesetting=[]) %}
          {%- for team in state_attr('[[group]]','entity_id')-%}
            {%- if state_attr(team, 'venue') not in venue  -%}
               {{{"type": "custom:teamtracker-card","entity": team,
               "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
               "home_side": "right"}}},
            {%- endif -%}
            {% set venue.venuesetting = venue.venuesetting + state_attr(team, 'venue')  %}
          {%- endfor -%}
        exclude:
          - entity_id: '*team_tracker*'
      sort:
        method: attribute
        attribute: date

Thanks for the help by the way (added my whole template section)

Just build a list of ā€˜teamā€™ then iterate over all the ā€˜teamā€™ entries. Don;t try to do both.

Youā€™re correct. When a conference_id is specified I append groups=conference_id as you listed above.

I can add add a conference_id attribute to the sensor if that would help. It would be whatever conference_id value was specified when it was set up. I could also add a team_conference_id and an opponent_conference_id if that would make things easier.

lmk.

@vasqued2 - I am guessing it would but itā€™s because I am not a jinja2 ninja like @kbrown01 so its overcoming my lack of knowledge.

My guess is if you added that I could just use something like this in the template, passing the conference_id as a variable [[conference]]

          template: |
            {%- for team in state_attr('[[group]]','entity_id') %}
              {%- set conference_id = state_attr(team, 'conference_id') %}
              {%- set team_homeaway = state_attr(team, 'team_homeaway') %}
              {%- if conference_id == [[conference]] and team_homeaway == "home" -%}
                 {{{"type": "custom:teamtracker-card","entity": team,
                 "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                 "home_side": "right"}}},
              {%- else conference_id != [[conference]] and team_homeaway == "home" -%}
                 {{{"type": "custom:teamtracker-card","entity": team,
                 "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                 "home_side": "left"}}},
              {%- endif %}
            {%- endfor %}

Ok I know that this is like talking about kites or balloons but I like smaller Teamtracker cards. I use a pc vs phone and maybe my view will change but I love the cardmod on making these puppies smaller

game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: grid
        layout:
          grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))
      card_param: cards
      filter:
        template: |
          {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "[[sport]]" -%}
            {%- if states(team) == "[[status]]" -%}
            {%- if state_attr(team, "team_homeaway") == "home" -%}
            {%- if team in state_attr('sensor.nfl_red_zone','teams') -%}
              {{{"type": "custom:teamtracker-card",
                "entity": team,
                "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                "home_side": "right"}}},
            {%- else -%}
              {{{"type": "custom:teamtracker-card",
                "entity": team, 
                "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                "home_side": "right"}}},
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
          {%- endfor -%}

specifically this change

"card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},

vs not having it there - you can see the difference between the pictures below with mod added and mod left out

Unmodded:

Modded:

Ok I got it working but I probably need to clean this up but I followed @kbrown01 's advice.

In my template.yaml file I created a sensor that pulls out the team names and sticks them in the sensor.

########
##NCAA Football Teams
#### Big 12
    - name: ncaaf_team_names_big_12
      unique_id: sensor.ncaaf_team_names_big_12
      state: "{{ now() }}"
      attributes: 
        team_names: >
          {% set cteams = namespace(cteam=[]) %}
          {% for team in state_attr('sensor.college_football_standings', 'children')[2]['standings']['entries'] %}
            {% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
          {% endfor %}
          {{ cteams.cteam | join(', ') }}

I then pass both the group and team names to the template like this:

- attributes:
                                label: Big 12 Conference
                                icon: mdi:account-group
                              card:
                                type: horizontal-stack
                                cards:
                                  - type: vertical-stack
                                    cards:
                                      - type: custom:decluttering-card
                                        template: ncaa_conference_settings
                                        variables:
                                          - title: NCAA Big 12 Conference
                                          - entity: sensor.ncaaf_big_12_games
                                          - attribute: events
                                      - type: markdown
                                        content: |
                                          <h1>Big 12 conference</h1>
                                      - type: custom:decluttering-card
                                        template: ncaaf_conference_game_stats
                                        variables:
                                          - group: group.big_12_conference_teams_group
                                          - team_names: sensor.ncaaf_team_names_big_12

I then updated the template to include all home games from the group and then go through the away teams and see if the home team is a big 12 team, if not print the card.

ncaaf_conference_game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: grid
        layout:
          grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))
      card_param: cards
      filter:
        template: >
          {% set team_names = state_attr('[[team_names]]',
          'team_names').split(', ') %} {%- for team in
          state_attr('[[group]]','entity_id') %}
            {%- if state_attr(team, "team_homeaway") == "home" and state_attr(team, "opponent_abbr") in team_names-%} 
                  {{{"type": "custom:teamtracker-card","entity": team,
                  "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px; border: 2px solid blue; background-color: rgba(224, 247, 250, 0.1); }"},
                  "home_side": "right",}}},
            {%- elif state_attr(team, "team_homeaway") == "home" -%} 
                  {{{"type": "custom:teamtracker-card","entity": team,
                  "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                  "home_side": "right",}}},
           {%- elif state_attr(team, "team_homeaway") != "home" and state_attr(team, "opponent_abbr") not in team_names  -%}   
                  {{{"type": "custom:teamtracker-card","entity": team,
                  "card_mod": {"style": "ha-card { font-size: .7em; line-height: .7em; width: 280px;}"},
                  "home_side": "right",}}},
           {%- endif -%}
          {%- endfor %}
        exclude:
          - entity_id: '*team_tracker*'
      sort:
        method: attribute
        attribute: date

Took @kbrown01 idea of the red zone card customization and applied it to in-conference games.
Before image:

After:

Thanks @kbrown01 for pointing me in the right direction. Any recommendations on cleaning this up are always welcome.

Eventually I will add tabs for the other conferences and then just pass the 2 sensors to the template.

That is excellent and close to my red zone solution ā€¦ except it is running all during games as it changes.

Another solution could be to join the home and away teams and eliminate duplicates and non-Big 12 teams (assuming you just have a list of Big 12 teams)

Possibly, the thing that I like at this moment is that by pulling out the team abbr, I may be able to use that against other sensors to parse data. Headlines, rss feeds possibly, etc. Down the road maybe, but thanks for all of your help and this great foundation.

As a separate question: With all of the sports and all of the sensors the file is getting unruly. Has anyone ever tried to put these in separate files? Donā€™t even know if you can have the template.yaml call other mini-template.yamls same with sensors.yaml but it was a thought.

Sure you can. Just read up here:

1 Like

Iā€™m trying to get all the FBS 1-A scoreboard integrated (ultimately, I want the team name and the game lines) and i have a feeling that Iā€™m missing the json_attributes_path to the schedule, but hereā€™s what i have so far that returns null values

  - platform: rest
    name: FBS_Schedule
    scan_interval: 86400
    resource: https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard
    value_template: "{{ now() }}"
    json_attributes_path: "$['children'][0]['scoreboard']"
    json_attributes:
      - entries  

the api iā€™ve confirmed has the data - any thoughts?

Appreciate the assist!!!

Iā€™m sorry I am not sure what you are looking for on this link? It seems that the returns are all over NCCAF. You get BYU and Monroe in this return. What conference are you looking for?

Iā€™m assuming you are looking for scoreboard - but I donā€™t see that option - I donā€™t see children either. This is what I am showing is packed in that link - https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard

nochildren

Have someone else the same problem, that some teams are missing.

For example:

  • Detroit Red Wings
  • Chicago Blackhawks