Sports Standings and Scores

I give up … really. I am watching these and no way they update with our technique. Needs a whole new thought processes to see how the GUI can update for teams entering/exiting “red zone”

Geez … I might have it. Stupid YAML (sucks) … let me watch and if it looks OK I will post

OMG … working perfect …

Right now

and now

OK.

I created the following sensor (not sure I really need the “state” now but hey, I am happy):

  - name: NFL Red Zone
    unique_id: sensor.nfl_red_zone
    state: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "NFL" -%}
            {%- if states(team) == "IN" -%}
            {%- if state_attr(team, "team_homeaway") == "home" -%}
            {%- if state_attr(team,'possession') is not none -%}
            {% set possession = state_attr(team,'possession') %}
            {% set team_id = state_attr(team,'team_id') %}
            {% set opponent_id = state_attr(team,'opponent_id') %}
            {% set team_abbr = state_attr(team,'team_abbr') %}
            {% set opponent_abbr = state_attr(team,'opponent_abbr') %}
            {% set down_distance_text = state_attr(team,'down_distance_text') %}
            {% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
            {% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
            {% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
            {% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
            {%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
            {% set redzone.teams = redzone.teams + [team] %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endfor %}
            {{ redzone.teams | count }}
    attributes:
        teams: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "NFL" -%}
            {%- if states(team) == "IN" -%}
            {%- if state_attr(team, "team_homeaway") == "home" -%}
            {%- if state_attr(team,'possession') is not none -%}
            {% set possession = state_attr(team,'possession') %}
            {% set team_id = state_attr(team,'team_id') %}
            {% set opponent_id = state_attr(team,'opponent_id') %}
            {% set team_abbr = state_attr(team,'team_abbr') %}
            {% set opponent_abbr = state_attr(team,'opponent_abbr') %}
            {% set down_distance_text = state_attr(team,'down_distance_text') %}
            {% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
            {% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
            {% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
            {% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
            {%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
            {% set redzone.teams = redzone.teams + [team] %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endfor %}
            {{ redzone.teams }}

This creates a sensor that contains anyone in the Red Zone and the state is the count of teams in the Red Zone. As @jeffcrum has posted, my templates assume you watch the entire NFL and have every team. If you don’t he can assist in modifying this for only teams you are focused on.

My decluttering template is like this:

  red_zone:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: masonry
      card_param: cards
      filter:
        template: |
          {%- for team in state_attr('sensor.nfl_red_zone','teams') -%}
          {{{"type": "custom:teamtracker-card",
             "entity": team,
             "home_side": "right"}}},
          {%- endfor -%}
        exclude:
          - entity_id: '*team_tracker*'
      sort:
        method: attribute
        attribute: date

Of course, you can just short that and start from the card type and make your own card.

NOPE: Still does not update with only one team. No idea now. If is all in the GUI

I just noticed something incorrect in my install that may have caused some issues. I had specified the Seahawks as abbr SE and not SEA. The game has not appearing of course as it was an error. I am wondering if this had some effect. Changed now so we shall see

You broke mine too :rofl:

I have fixed it as well. Thanks for catching that!

I also have the Red Zone sensor installed. So, will be watching for complete awesomeness.

Using this in Dev Tools | Template:

{%- for team in integration_entities("teamtracker") %}
  {%- if state_attr(team, "league") == "NFL" %}
    {%- if states(team) == "NOT_FOUND" %}
{{ state_attr(team, 'friendly_name') }}-{{ state_attr(team, 'team_abbr') }}-{{ states(team) }}
    {%- endif -%}
  {%- endif -%}
{%- endfor -%}

I get several NOT_FOUND. Are you seeing this too?

New York Giants-NYG-NOT_FOUND
Cleveland Browns-CLE-NOT_FOUND
Cincinnati Bengals-CIN-NOT_FOUND

Going to check each one that is not found and see.

I just went to list entities and searched for teamtracker …

Everything was correct

Mine looks that way too. Until click on it and see:

HMM. Let me look at mine.
I am already making myself an enhancement request … instead of having a “Red Zone” tab, we use card-mod and do something like this. Faked for baseball as it was in game … just turn the card background red!

Oooo, I like that a LOT!

And, know you have other things going on. Please, deal with other things first. I am just throwing out what I see.

To answer your other question, NOT_FOUND is correct. You have to read up on Teamtracker but essentially it means that ESPN no longer reports the game as POST and it is not close enough for them to be PRE so you end up with no stats which is reported as NOT_FOUND.

You would see that for Giants game and probably Bengals v Falcons too.

It just means they are not POST, IN or PRE … so they are not in the ESPN scoring report.

I am going to be out for 1st half … but I made on slight modification in the decluttering templates:

  game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: masonry
      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 {\n    background-color:  #ffcccc; \n}\n"},
                "home_side": "right"}}},
            {%- else -%}
              {{{"type": "custom:teamtracker-card",
                "entity": team,
                "home_side": "right"}}},
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
          {%- endfor -%}
        exclude:
          - entity_id: '*team_tracker*'
      sort:
        method: attribute
        attribute: date

So the teamtracker card while watching games should turn red if a team is in the red zone.

Fingers crossed. Probably could move the if inside to make it simpler. I tested by forcing a team onto the list and displaying the PRE game tab and it was red.

UPDATE: I thought about it and this will not work for away team so that needs to be addressed. I can probably just eliminate the test for home or away from red zone teams and they both would be flagged.

Yeah. Sorry. I was chasing the ‘wrong’ team thing. I get it. All good.

i actually think this will work better than just a “Red Zone” tab. I was forcing teams onto and off the red zone list and I noticed that the standard teamtracker view updated red almost immediately but the view that only had red zone teams sometimes left one behind. I think this should update every 5 seconds if I read the documentation right so we shall see.

I have not had a chance to look it over yet. But, will when I can.

Now to see if it turns on/off … and it does!
Now to see if the change I made will flag either team, so need Ravens to get in red zone.

And it works!

I will post all of this later tonight/tomorrow but now we have Red Zone.

Great news so far. Sorry, I have not had a chance to look at it or watch it. But, I love seeing this!

I like it like this! Waiting for Thursday now for better testing beyond one game.

image

Note: Just a test … I made every card be like that to test my card-mod code.

Hello -

I have a quick, but probably dumb question, but I i figured Id ask anyway.

I just did direct copies of your GitHub.

I placed sensors in my sensors folder, and all the teams are discovered as I could make my own nfl-cards.

However, the dashboard is not loading any details. Take a look at the screenshots below.

I have my template exactly where yours would be located (or so I think it is).

Screenshot 2023-09-15 094350

also in the template, I get the following as well.

{{ state_attr('sensor.nhl_east_atlantic','entries')[0].stats }} = UndefinedError: None has no element 0

{{ state_attr('sensor.nhl_east_atlantic','entries') }} = null

Any thoughts

The rest sensors and all teamtracker items come into sensor.

The breakdown of the stats come into template. You have them in a file in the www folder. I can’t see the filename. But, your template !include is template.yaml.

As @jeffcrum says, based on what you have shown all your includes should be in the same folder as you have the configuration YAML