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