Sports Standings and Scores

@kbrown01 - I need more replies to post, including the pictures.

NFL Picture (Natl. cutoff in picture for Wildcards and part of Divl)

MLB

MLB - Groups

mlb_teams:
  name: mlb_teams
  entities:
    - sensor.arizona_diamondbacks
    - sensor.atlanta_braves
    - sensor.baltimore_orioles
    - sensor.boston_red_sox
    - sensor.chicago_cubs
    - sensor.chicago_white_sox
    - sensor.cincinnati_reds
    - sensor.cleveland_guardians
    - sensor.colorado_rockies
    - sensor.detroit_tigers
    - sensor.houston_astros
    - sensor.kansas_city_royals
    - sensor.los_angeles_angels
    - sensor.los_angeles_dodgers
    - sensor.miami_marlins
    - sensor.milwaukee_brewers
    - sensor.minnesota_twins
    - sensor.new_york_mets
    - sensor.new_york_yankees
    - sensor.oakland_athletics
    - sensor.philadelphia_phillies
    - sensor.pittsburgh_pirates
    - sensor.san_diego_padres
    - sensor.san_francisco_giants
    - sensor.seattle_mariners
    - sensor.st_louis_cardinals
    - sensor.tampa_bay_rays
    - sensor.texas_rangers
    - sensor.toronto_blue_jays
    - sensor.washington_nationals

mlb_al_teams:
  name: mlb_al_teams
  entities:
    - sensor.baltimore_orioles
    - sensor.boston_red_sox
    - sensor.chicago_white_sox
    - sensor.cleveland_guardians
    - sensor.detroit_tigers
    - sensor.houston_astros
    - sensor.kansas_city_royals
    - sensor.los_angeles_angels
    - sensor.minnesota_twins
    - sensor.new_york_yankees
    - sensor.oakland_athletics
    - sensor.seattle_mariners
    - sensor.tampa_bay_rays
    - sensor.texas_rangers
    - sensor.toronto_blue_jays

mlb_nl_teams:
  name: mlb_nl_teams
  entities:
    - sensor.arizona_diamondbacks
    - sensor.atlanta_braves
    - sensor.chicago_cubs
    - sensor.cincinnati_reds
    - sensor.colorado_rockies
    - sensor.los_angeles_dodgers
    - sensor.miami_marlins
    - sensor.milwaukee_brewers
    - sensor.new_york_mets
    - sensor.philadelphia_phillies
    - sensor.pittsburgh_pirates
    - sensor.san_diego_padres
    - sensor.san_francisco_giants
    - sensor.st_louis_cardinals
    - sensor.washington_nationals

MLB - REST sensors

##
## Wildcards
##
- resource: https://site.web.api.espn.com/apis/v2/sports/baseball/mlb/standings?region=us&lang=en&contentorigin=espn&type=3&level=2&sort=playoffseed%3Aasc%2Cpoints%3Adesc%2Cgamesplayed%3Aasc%2Crotwins%3Adesc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "MLB Wildcard"
      unique_id: mlb_wildcard
      icon: mdi:baseball
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"

##
## Playoff Standings
##
- resource: https://site.web.api.espn.com/apis/v2/sports/baseball/mlb/standings?region=us&lang=en&contentorigin=espn&type=3&level=3&sort=playoffseed:asc,points:desc,gamesplayed:asc,rotwins:desc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "MLB PO Standings"
      unique_id: mlb_po_standings
      icon: mdi:baseball
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"
##
## Playoff Standings - Postseason
##
- resource_template: "https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard?limit=1000&dates={{ now().year }}"
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "MLB Standings Postseason"
      unique_id: mlb_standings_postseason
      json_attributes:
        - leagues
        - events
      value_template: "{{ now() }}"

##
## Schedule
##
- resource: https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard
  # every 24 hours
  scan_interval: 86400
  sensor:
    - name: "MLB Schedule"
      unique_id: mlb_schedule
      json_attributes:
        - events
      value_template: "{{ now() }}"

MLB - Template Sensors

###
### TV Coverage
###
- sensor:
    - name: MLB PO TV Coverage
      unique_id: mlb_po_tv_coverage
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], tv_channels=[], game_ctr=0, ctr=0, home='', away='') -%}
          {%- set po_schedule = "sensor.mlb_schedule" -%}
          {%- set po_tv = state_attr(po_schedule, 'events') | list %}

          {% for po_tv_sched in po_tv %}
            {% for game in po_tv_sched['competitions'] %}
              {% set gm_dte = as_local(as_datetime(game.startDate)).strftime('%Y-%m-%d %H:%M:%S') %}
              {% set game_dte =  as_local(as_datetime(game.startDate)).strftime('%b %d') %}
              {% set game_time =  as_local(as_datetime(game.startDate)).strftime('%I:%M %p') %}
              {% for channel in game['broadcasts'] %}
                {%- set ns.tv_channels = ns.tv_channels + [channel.names[0]] -%}
              {% endfor -%}

              {%- set ns.ctr = 0 %}
              {% for team in game['competitors'] %}
                {%- if team.homeAway == 'home' %}
                  {%- set ns.home = team.team.displayName %}
                {% else -%}
                  {%- set ns.away = team.team.displayName %}
                {% endif -%}

                {%- if ns.ctr == 1 %}
                  {% set ns.results = ns.results + [{'date': game_dte, 'time': game_time, 'home': ns.home,
                  'away': ns.away, 'tv': ns.tv_channels, 'gm_dte': gm_dte}] %}
                {% endif -%}
                {%- set ns.ctr = ns.ctr + 1 %}
              {% endfor -%}
            {%- endfor -%}
          {%- endfor -%}
          {{ ns.results }}

###
### Major League Baseball
###
###
### Obtain Playoff Seeds, Playoff Games by League, and Teams by "Bracket" (WildCard, Division, League, "World")
###

###
### Wildcards - Used in Playoffs Tab to Forecast until the Playoff season starts
###
- sensor:
    - name: MLB Wildcard Standings
      unique_id: sensor.mlb_wildcard_standings
      state: "{{ now() }}"
      attributes:
        mlb_al_east_top: "{{ state_attr('sensor.mlb_po_standings','children')[0]['children'][0]['standings']['entries'][:1] }}"
        mlb_al_central_top: "{{ state_attr('sensor.mlb_po_standings','children')[0]['children'][1]['standings']['entries'][:1] }}"
        mlb_al_west_top: "{{ state_attr('sensor.mlb_po_standings','children')[0]['children'][2]['standings']['entries'][:1] }}"
        mlb_al_wc: >
          {% set amer_east_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][0]['standings']['entries'][:1] %}
          {% set amer_central_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][1]['standings']['entries'][:1] %}
          {% set amer_west_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][2]['standings']['entries'][:1] %}
          {% set amer_east_name = amer_east_top[0].team.displayName %}
          {% set amer_central_name = amer_central_top[0].team.displayName %}
          {% set amer_west_name = amer_west_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.mlb_wildcard','children')[0]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', amer_east_name) |
            rejectattr('team.displayName', 'eq', amer_central_name) |
            rejectattr('team.displayName', 'eq', amer_west_name) | list  %}
          {{ amer_wc[:3] }}
        mlb_al_hunt: >
          {% set amer_east_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][0]['standings']['entries'][:1] %}
          {% set amer_central_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][1]['standings']['entries'][:1] %}
          {% set amer_west_top = state_attr('sensor.mlb_po_standings','children')[0]['children'][2]['standings']['entries'][:1] %}
          {% set amer_east_name = amer_east_top[0].team.displayName %}
          {% set amer_central_name = amer_central_top[0].team.displayName %}
          {% set amer_west_name = amer_west_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.mlb_wildcard','children')[0]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', amer_east_name) |
            rejectattr('team.displayName', 'eq', amer_central_name) |
            rejectattr('team.displayName', 'eq', amer_west_name) | list  %}
          {% set wc = amer_wc[:3] %}
          {% set wc_amer_east_name = wc[0].team.displayName %}
          {% set wc_amer_central_name = wc[1].team.displayName %}
          {% set wc_amer_west_name = wc[2].team.displayName %}
          {% set amer_hunt = amer_all |
            rejectattr('team.displayName', 'eq', amer_east_name) |
            rejectattr('team.displayName', 'eq', amer_central_name) |
            rejectattr('team.displayName', 'eq', amer_west_name) |
            rejectattr('team.displayName', 'eq', wc_amer_east_name) |
            rejectattr('team.displayName', 'eq', wc_amer_central_name) |
            rejectattr('team.displayName', 'eq', wc_amer_west_name) | list  %}
          {{ amer_hunt[:2] }}
        mlb_al_eliminated: >
          {% set ns = namespace(eteam=[]) %}
          {%- set wc_teams = state_attr('sensor.mlb_wildcard','children')[0]['standings']['entries'] | sort(attribute="stats.playoffSeed") -%}
          {% for team in wc_teams[8:] %}
            {% for stat in team['stats'] %}
              {% if stat.name == 'clincher' %}
                  {% set ns.eteam = ns.eteam + [team] %}
              {% endif %}
            {% endfor %}
          {% endfor %}
          {{ ns.eteam }}
        mlb_nl_east_top: "{{ state_attr('sensor.mlb_po_standings','children')[1]['children'][0]['standings']['entries'][:1] }}"
        mlb_nl_central_top: "{{ state_attr('sensor.mlb_po_standings','children')[1]['children'][1]['standings']['entries'][:1] }}"
        mlb_nl_west_top: "{{ state_attr('sensor.mlb_po_standings','children')[1]['children'][2]['standings']['entries'][:1] }}"
        mlb_nl_wc: >
          {% set natl_east_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][0]['standings']['entries'][:1] %}
          {% set natl_central_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][1]['standings']['entries'][:1] %}
          {% set natl_west_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][2]['standings']['entries'][:1] %}
          {% set natl_east_name = natl_east_top[0].team.displayName %}
          {% set natl_central_name = natl_central_top[0].team.displayName %}
          {% set natl_west_name = natl_west_top[0].team.displayName %}
          {% set natl_all = state_attr('sensor.mlb_wildcard','children')[1]['standings']['entries'] %}
          {% set natl_wc = natl_all |
            rejectattr('team.displayName', 'eq', natl_east_name) |
            rejectattr('team.displayName', 'eq', natl_central_name) |
            rejectattr('team.displayName', 'eq', natl_west_name) | list  %}
          {{ natl_wc[:3] }}
        mlb_nl_hunt: >
          {% set natl_east_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][0]['standings']['entries'][:1] %}
          {% set natl_central_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][1]['standings']['entries'][:1] %}
          {% set natl_west_top = state_attr('sensor.mlb_po_standings','children')[1]['children'][2]['standings']['entries'][:1] %}
          {% set natl_east_name = natl_east_top[0].team.displayName %}
          {% set natl_central_name = natl_central_top[0].team.displayName %}
          {% set natl_west_name = natl_west_top[0].team.displayName %}
          {% set natl_all = state_attr('sensor.mlb_wildcard','children')[1]['standings']['entries'] %}
          {% set natl_wc = natl_all |
            rejectattr('team.displayName', 'eq', natl_east_name) |
            rejectattr('team.displayName', 'eq', natl_central_name) |
            rejectattr('team.displayName', 'eq', natl_west_name) | list  %}
          {% set wc = natl_wc[:3] %}
          {% set wc_natl_east_name = wc[0].team.displayName %}
          {% set wc_natl_central_name = wc[1].team.displayName %}
          {% set wc_natl_west_name = wc[2].team.displayName %}
          {% set natl_hunt = natl_all |
            rejectattr('team.displayName', 'eq', natl_east_name) |
            rejectattr('team.displayName', 'eq', natl_central_name) |
            rejectattr('team.displayName', 'eq', natl_west_name) |
            rejectattr('team.displayName', 'eq', wc_natl_east_name) |
            rejectattr('team.displayName', 'eq', wc_natl_central_name) |
            rejectattr('team.displayName', 'eq', wc_natl_west_name) | list  %}
          {{ natl_hunt[:2] }}
        mlb_nl_eliminated: >
          {% set ns = namespace(eteam=[]) %}
          {%- set wc_teams = state_attr('sensor.mlb_wildcard','children')[1]['standings']['entries'] | sort(attribute="stats.playoffSeed") -%}
          {% for team in wc_teams[8:] %}
            {% for stat in team['stats'] %}
              {% if stat.name == 'clincher' %}
                  {% set ns.eteam = ns.eteam + [team] %}
              {% endif %}
            {% endfor %}
          {% endfor %}
          {{ ns.eteam }}
        entries: >
          {%- set ns = namespace(ateams=[],nteams=[],al_team=[],nl_team=[],results=[]) -%}
          {%- set elim_def = 'Eliminated from Playoff Contention' -%}
          {%- set al_dict = {'league':'AL'} -%}
          {%- set nl_dict = {'league':'NL'} -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.mlb_standings','children')[0]['children'][0]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.mlb_standings','children')[0]['children'][1]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.mlb_standings','children')[0]['children'][2]['standings']['entries'] -%}
          {% set ns.nteams = ns.nteams + state_attr('sensor.mlb_standings','children')[1]['children'][0]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.mlb_standings','children')[1]['children'][1]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.mlb_standings','children')[1]['children'][2]['standings']['entries'] %}

          {%- for team in ns.ateams -%}
            {%- set po_stat = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- if po_stat[0] != elim_def -%}
              {%- set rec_dict = dict(team.items(), **al_dict) -%}
              {%- set ns.al_team = ns.al_team + [rec_dict] -%}
            {%- endif -%}
          {%- endfor -%}

          {%- for team in ns.nteams -%}
            {%- set po_stat = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- if po_stat[0] != elim_def -%}
              {%- set rec_dict = dict(team.items(), **nl_dict) -%}
              {%- set ns.nl_team = ns.nl_team + [rec_dict] -%}
            {%- endif %}
          {%- endfor %}
          {%- set tmp_teams = ns.al_team + ns.nl_team -%}
          {{ tmp_teams }}

###
### Playoffs Seeds
###
- sensor:
    - name: MLB Playoff Seeds
      unique_id: sensor.mlb_playoff_seeds
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], tmp_recs=[]) -%}
          {%- set sense = 'sensor.mlb_wildcard_standings' -%}

          {%- for team in state_attr(sense, 'entries') -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','winPercent') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}
            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league':team.league, 'seed': seed,
              'po_status': position[0],'home_rec': home_rec[0], 'away_rec': away_rec[0], 'wins': wins, 'losses': losses,
              'winPercent':winPercent,'logo': logo}}] -%}
          {%- endfor -%}
          {%- set ns.tmp_recs = ns.results | sort(attribute='team.league,team.seed') -%}
          {{ ns.tmp_recs }}
        po_amer_wc_seeds: >
          {%- set ns = namespace(results=[], amer_result=[], ctr=0) -%}
          {%- set sense = 'sensor.mlb_wildcard_standings' -%}

          {%- for team in state_attr(sense, 'entries') | selectattr('league','eq','AL') | list -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','winPercent') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}
            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league': team.league,
              'seed': seed, 'po_status': position[0], 'home_rec': home_rec[0], 'away_rec': away_rec[0],
              'logo': logo}}] -%}
          {%- endfor -%}
          {% set ns.amer_result = ns.results | sort(attribute='team.seed') %}
          {{ ns.amer_result }}
        po_natl_wc_seeds: >
          {%- set ns = namespace(results=[], natl_result=[], ctr=0) -%}
          {%- set sense = 'sensor.mlb_wildcard_standings' -%}

          {%- for team in state_attr(sense, 'entries') | selectattr('league','eq','NL') | list -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','winPercent') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}
            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league': team.league,
              'seed': seed, 'po_status': position[0], 'home_rec': home_rec[0], 'away_rec': away_rec[0],
              'logo': logo}}] -%}
          {%- endfor -%}
          {% set ns.natl_result = ns.results | sort(attribute='team.seed') %}
          {{ ns.natl_result }}

###
### Playoffs - Games
###
### Need to set games as there are multiple games in a series
### MLB data does not have a good key to get the data directly
###
- sensor:
    - name: MLB PO Team Games
      unique_id: sensor.mlb_po_team_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], game_day='', game_dte = '', gm_dte='', gtype= '', series='',
            seriesStatus='', leag='', gamesInSeries='', gameNumber='', seriesGameNumber='', winner='', loser='',
            home='', away='', home_wins='', home_loss='', away_wins='', away_loss='', home_score='', away_score='',
            odds='', weather='',win_num=0, gm_teams='',teams_chg=0,wc_al=1,wc_nl=1, home_advantage='') -%}
          {%- set po_teams = 'sensor.mlb_playoff_seeds' -%}
          {%- set po_schedule = state_attr("sensor.mlb_standings_postseason_2023", 'events') -%}
          {%- set po_sched_teams = po_schedule | selectattr('season.slug','eq','post-season') |
            sort(attribute='date') | list -%}
          {%- set al_teams =  expand('group.mlb_al_teams') | map(attribute='attributes.friendly_name') |
            list -%}
          {%- set nl_teams =  expand('group.mlb_nl_teams') | map(attribute='attributes.friendly_name') |
            list -%}
          {%- set mlb_teams =  expand('group.mlb_teams') | map(attribute='attributes.friendly_name') | list -%}

          {%- set gamelvlnum = {
            'FINAL': 4,
            'SEMI': 3,
            'QTR': 2,
            'RD16': 1 } -%}

          {%- for evt in po_sched_teams -%}
            {%- set gtype = evt.competitions[0].type.abbreviation -%}
            {%- set ns.series = gamelvlnum.get(gtype) -%}

            {%- if ns.series != ns.prior_lvl -%}
              {%- set ns.al_ctr = 1 -%}
              {%- set ns.nl_ctr = 1 -%}
              {%- set ns.prior_lvl = ns.series -%}
            {%- endif %}

            {%- for game in evt.competitions -%}
              {%- set ns.ser_gm = game.notes[0].headline.split("Game ")[1] -%}
              {%- set game_teams = '' %}

              {%- for team in game['competitors'] -%}
                  {%- set team_name = team.team.displayName -%}
                  {%- if team.homeAway == 'home' -%}
                    {%- if team.team.displayName in al_teams -%}
                      {%- set ns.leag = 'AL' -%}
                      {%- set ns.home = team_name -%}
                    {%- elif team.team.displayName in nl_teams -%}
                      {%- set ns.leag = 'NL' -%}
                      {%- set ns.home = team_name -%}
                    {%- else -%}
                      {%- set ns.home = 'TBD' -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if team.team.displayName in al_teams -%}
                      {%- set ns.leag = 'AL' -%}
                      {%- set ns.away = team_name -%}
                    {%- elif team.team.displayName in nl_teams -%}
                      {%- set ns.leag = 'NL' -%}
                      {%- set ns.away = team_name -%}
                    {%- else -%}
                      {%- set ns.away = 'TBD' -%}
                    {%- endif -%}
                  {%- endif -%}
              {% endfor -%}

              {%- if (mlb_teams.index(ns.away) | int) < (mlb_teams.index(ns.home)  | int) -%}
                {%- set game_teams = ns.away + '-' + ns.home -%}
              {%- else -%}
                {%- set game_teams = ns.home + '-' + ns.away -%}
              {%- endif -%}

              {% if ns.results | selectattr('game_teams','eq',game_teams) | list | count == 0 -%}
                {%- if ns.leag == 'AL' -%}
                  {%- set gnum = ns.al_ctr-%}
                  {%- set ns.al_ctr = ns.al_ctr + 1  -%}
                {% elif ns.leag == 'NL'  %}
                  {%- set gnum = ns.nl_ctr -%}
                  {%- set ns.nl_ctr = ns.nl_ctr + 1 -%}
                {%- endif -%}

                {% set ns.results = ns.results + [{'seriesNumber': ns.series, 'league': ns.leag,
                'game_teams': game_teams, 'gameNumber': gnum }] -%}
              {%- endif -%}
            {%- endfor -%}
          {% endfor -%}
          {% set sort_po_teams_games = ns.results | sort(attribute="seriesNumber, league, gameNumber") -%}
          {{ sort_po_teams_games }}

Part 3.1 of 4 (again - dashboard will not fit in post AND I need to finish the template sensors)

MLB - Template Sensors - Part 2

###
### Playoffs - Games
###
- sensor:
    - name: MLB PO Games
      unique_id: sensor.mlb_po_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], game_day='', game_dte = '', gm_dte='', gtype= '', series='',
            seriesStatus='', leag='', gamesInSeries='', gameNumber='', seriesGameNumber='', winner='', loser='',
            home='', away='', home_wins='', home_loss='', away_wins='', away_loss='', home_score='', away_score='',
            odds='', weather='',win_num=0, gm_teams='',teams_chg=0,wc_al=1,wc_nl=1, home_advantage='') -%}
          {%- set po_schedule = state_attr("sensor.mlb_standings_postseason_2023", 'events') -%}
          {%- set po_sched_teams = po_schedule | selectattr('season.slug','eq','post-season') |
              sort(attribute='date') | list -%}
          {%- set tday = as_local(now()).strftime('%Y-%m-%d') -%}

          {%- set seeds = 'sensor.mlb_playoff_seeds' -%}
          {%- set po_teams = 'sensor.mlb_playoff_seeds' -%}

          {%- set al_teams =  expand('group.mlb_al_teams') | map(attribute='attributes.friendly_name') |
            list -%}
          {%- set nl_teams =  expand('group.mlb_nl_teams') | map(attribute='attributes.friendly_name') |
            list -%}
          {%- set mlb_teams =  expand('group.mlb_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set team_games = state_attr('sensor.mlb_po_team_games', 'entries') -%}
          {%- set tmp_teams = ['TBD','AL','NL'] -%}

          {%- set gamelvl = {
            'FINAL': 'World Series',
            'SEMI': 'Championship',
            'QTR': 'Divisional Playoffs',
            'RD16': 'Wild Card' } -%}

          {%- set gamelvlnum = {
            'FINAL': 4,
            'SEMI': 3,
            'QTR': 2,
            'RD16': 1 } -%}

          {%- for evt in po_sched_teams -%}
            {%- set gtype = evt.competitions[0].type.abbreviation -%}
            {%- set ns.gtype = gamelvl.get(gtype) -%}

            {%- set ns.series = gamelvlnum.get(gtype) -%}
            {%- set game_dte = '{}'.format(evt.competitions[0].date) | as_datetime | as_timestamp | timestamp_custom('%b %d at %I:%M %p') -%}
            {%- set game_day = as_local(as_datetime(evt.competitions[0].date)).strftime('%Y-%m-%d') -%}

            {%- if ns.gtype != ns.prior_lvl -%}
              {%- set ns.al_ctr = 1 -%}
              {%- set ns.nl_ctr = 1 -%}
              {%- set ns.prior_lvl = gtype -%}
            {%- endif %}

            {%- if evt.competitions[0].broadcasts | length != 0 -%}
              {%- set ns.tv = evt.competitions[0].broadcasts[0].names[0] -%}
            {%- else -%}
              {%- set ns.tv = 'N/A' -%}
            {%- endif -%}

            {%- for game in evt.competitions -%}
              {%- if game.odds is defined -%}
                {%- set ns.odds = game.odds[0].provider.name +": "+ game.odds[0].details +" OverUnder: "+
                  (game.odds[0].overUnder  | string) + " Spread: "+ (game.odds[0].spread | string) -%}
              {%- else -%}
                {%- set ns.odds = 'N/A' -%}
              {%- endif -%}

              {%- set ns.winner = '' -%}
              {%- set ns.ser_gm = game.notes[0].headline.split("Game ")[1] -%}

              {%- for team in game['competitors'] -%}
                  {%- set team_name = team.team.displayName -%}
                  {%- if team.homeAway == 'home' -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.home = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.home = team_name -%}
                      {%- set ns.hid = team.id -%}
                      {%- set ns.habbrev = team.team.abbreviation -%}
                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.home -%}
                      {%- endif -%}

                      {%- if team.score is defined -%}
                        {%- set ns.hscore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.hscore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.away = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.away = team_name -%}
                      {%- set ns.aid = team.id -%}
                      {%- set ns.aabbrev = team.team.abbreviation -%}

                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.away -%}
                      {%- endif -%}
                      {%- if team.score is defined -%}
                        {%- set ns.ascore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.ascore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- endif -%}
              {%- endfor -%}

              {%- set games_stat = game.series.summary.split(" ") -%}
              {%- set stats_len = games_stat | count -%}

              {% if games_stat[0] == 'Series' %}
                {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
              {% else -%}
                {% if games_stat[0] == ns.habbrev %}
                  {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% elif games_stat[0] == ns.aabbrev %}
                  {%- set awins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set hwins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% endif -%}
              {% endif -%}

              {%- if ns.winner != '' and ns.winner == ns.home -%}
                {%- set ns.loser = ns.away -%}
                {%- set ns.stat = 'Final' -%}
              {%- elif ns.winner != '' and ns.winner == ns.away -%}
                {%- set ns.loser = ns.home -%}
                {%- set ns.stat = 'Final' -%}
              {%- else -%}
                {%- set ns.stat = 'Ongoing' -%}
              {%- endif -%}

              {%- if ns.home in al_teams -%}
                {%- set ns.leag = 'AL' -%}
              {% elif ns.home in nl_teams %}
                {%- set ns.leag = 'NL' -%}
              {%- endif -%}

              {%- if (mlb_teams.index(ns.away) | int) < (mlb_teams.index(ns.home) | int) -%}
                {%- set game_teams = ns.away + '-' + ns.home -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- else -%}
                {%- set game_teams = ns.home + '-' + ns.away -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- endif -%}

              {% set ns.results = ns.results + [{'date': game_day,'dte': game_dte,'Game': ns.gtype,
                'seriesStatus': ns.stat,'league': ns.leag, 'winner': ns.winner,'loser': ns.loser,
                'home': ns.home,'away': ns.away, 'home_wins': hwins, 'away_wins': awins,
                'home_score': ns.hscore, 'away_score': ns.ascore, 'seriesNumber': ns.series,
                'gameNumber': ns.gctr, 'gamesInSeries': ns.ser_gm, 'seriesGameNumber':"1",'odds':ns.odds,'weather':ns.weather}] -%}
            {%- endfor -%}
          {% endfor -%}
          {%- set sort_po_teams_games = ns.results | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") -%}
          {{ sort_po_teams_games }}

- sensor:
    - name: MLB PO Amer Games
      unique_id: sensor.mlb_po_amer_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.mlb_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','AL') | list -%}
          {{ po_sched_teams }}

- sensor:
    - name: MLB PO Natl Games
      unique_id: sensor.mlb_po_natl_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.mlb_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','NL') | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Wildcard Games
###

- sensor:
    - name: MLB PO Amer WC Games
      unique_id: sensor.mlb_po_amer_wc_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.mlb_po_amer_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

- sensor:
    - name: MLB PO Natl WC Games
      unique_id: sensor.mlb_po_natl_wc_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.mlb_po_natl_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Division Games
###

- sensor:
    - name: MLB PO Amer Div Games
      unique_id: sensor.mlb_po_amer_div_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.mlb_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

- sensor:
    - name: MLB PO Natl Div Games
      unique_id: sensor.mlb_po_natl_div_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.mlb_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### Playoffs - League Games
###

- sensor:
    - name: MLB PO Amer Leag Games
      unique_id: sensor.mlb_po_amer_leag_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.mlb_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

- sensor:
    - name: MLB PO Natl Leag Games
      unique_id: sensor.mlb_po_natl_leag_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.mlb_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### MLB Playoffs - World Game
###

- sensor:
    - name: MLB PO World Game
      unique_id: sensor.mlb_po_world_game
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.mlb_po_games" , 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'World Series')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

MLB - Dashboard Code

type: custom:layout-card
layout_type: grid
layout:
  grid-template-columns: 25% 25% 25% 25%
  grid-template-rows: auto
  grid-template-areas: |
    "col1 col2 col3 col4"
  mediaquery:
    '(max-width: 450px)':
      grid-template-columns: 100%
      grid-template-areas: |
        "col1"
        "col2"
        "col3"
        "col4"
    '(max-width: 1200px)':
      grid-template-columns: 50% 50%
      grid-template-areas: |
        "col1 col2"
        "col3 col4"
cards:
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: MLB
          - po_level: Wild Card
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: American
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 1
              - game_num: 1
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 1
          - game_num: 1
          - attribute: po_amer_wc_seeds
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_amer_wc_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 1
              - game_num: 2
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 1
          - game_num: 2
          - attribute: po_amer_wc_seeds
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_amer_wc_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: National
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 1
              - game_num: 1
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 1
          - game_num: 1
          - attribute: po_natl_wc_seeds
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_natl_wc_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 1
              - game_num: 2
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 1
          - game_num: 2
          - attribute: po_natl_wc_seeds
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_natl_wc_games
          - tv_schedule: sensor.mlb_po_tv_coverage
    view_layout:
      grid-area: col1
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: MLB
          - po_level: Division
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: American
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 2
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_amer_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 2
          - game_num: 1
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_amer_div_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 2
              - game_num: 2
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_amer_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 2
          - game_num: 2
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_amer_div_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: National
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 2
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_natl_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 2
          - game_num: 1
          - playoff_teams: sensor.po_natl_wc_seeds
          - playoff_schedule: sensor.mlb_po_natl_div_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: MLB
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 2
              - game_num: 2
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_natl_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 2
          - game_num: 2
          - playoff_teams: sensor.po_natl_wc_seeds
          - playoff_schedule: sensor.mlb_po_natl_div_games
          - tv_schedule: sensor.mlb_po_tv_coverage
    view_layout:
      grid-area: col2
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: MLB
          - po_level: League
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: American
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 3
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_amer_leag_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 3
          - game_num: 1
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_amer_leag_games
          - tv_schedule: sensor.mlb_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: MLB
          - po_league: National
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 3
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_natl_leag_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 3
          - game_num: 1
          - playoff_teams: sensor.po_natl_wc_seeds
          - playoff_schedule: sensor.mlb_po_natl_leag_games
          - tv_schedule: sensor.mlb_po_tv_coverage
    view_layout:
      grid-area: col3
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: MLB
          - po_level: World Series
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: MLB
              - series_num: 4
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.mlb_playoff_seeds
              - playoff_schedule: sensor.mlb_po_world_game
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: MLB
          - series_num: 4
          - game_num: 1
          - playoff_teams: sensor.mlb_playoff_seeds
          - playoff_schedule: sensor.mlb_po_world_game
          - tv_schedule: sensor.mlb_po_tv_coverage
    view_layout:
      grid-area: col4
      show: always

Part 3.2 of 4

NHL

NHL - Groups

# ##################################  Teams  ###################################
## The Teams MUST be sorted here alphabetically BACKWARDS due to ESPN data

nhl_teams:
  name: nhl_teams
  entities:
    - sensor.anaheim_ducks
    - sensor.arizona_coyotes
    - sensor.boston_bruins
    - sensor.buffalo_sabres
    - sensor.calgary_flames
    - sensor.carolina_hurricanes
    - sensor.chicago_blackhawks
    - sensor.colorado_avalanche
    - sensor.columbus_blue_jackets
    - sensor.dallas_stars
    - sensor.detroit_red_wings
    - sensor.edmonton_oilers
    - sensor.florida_panthers
    - sensor.los_angeles_kings
    - sensor.minnesota_wild
    - sensor.montreal_canadians
    - sensor.nashville_predators
    - sensor.new_jersey_devils
    - sensor.new_york_islanders
    - sensor.new_york_rangers
    - sensor.ottawa_senators
    - sensor.philadelphia_flyers
    - sensor.pittsburg_penguins
    - sensor.san_jose_sharks
    - sensor.seattle_kraken
    - sensor.st_louis_blues
    - sensor.tampa_bay_lightning
    - sensor.toronto_maple_leafs
    - sensor.vancouver_canucks
    - sensor.vegas_golden_knights
    - sensor.washington_capitals
    - sensor.winnipeg_jets

nhl_al_teams:
  name: nhl_al_teams
  entities:
    - sensor.boston_bruins
    - sensor.buffalo_sabres
    - sensor.carolina_hurricanes
    - sensor.columbus_blue_jackets
    - sensor.detroit_red_wings
    - sensor.florida_panthers
    - sensor.montreal_canadians
    - sensor.new_jersey_devils
    - sensor.new_york_islanders
    - sensor.new_york_rangers
    - sensor.ottawa_senators
    - sensor.philadelphia_flyers
    - sensor.pittsburg_penguins
    - sensor.tampa_bay_lightning
    - sensor.toronto_maple_leafs
    - sensor.washington_capitals

nhl_nl_teams:
  name: nhl_nl_teams
  entities:
    - sensor.anaheim_ducks
    - sensor.arizona_coyotes
    - sensor.calgary_flames
    - sensor.chicago_blackhawks
    - sensor.colorado_avalanche
    - sensor.dallas_stars
    - sensor.edmonton_oilers
    - sensor.los_angeles_kings
    - sensor.minnesota_wild
    - sensor.nashville_predators
    - sensor.san_jose_sharks
    - sensor.seattle_kraken
    - sensor.st_louis_blues
    - sensor.vancouver_canucks
    - sensor.vegas_golden_knights
    - sensor.winnipeg_jets

NHL - REST sensors

##
## Wildcards
##
- resource: https://site.web.api.espn.com/apis/v2/sports/hockey/nhl/standings?region=us&lang=en&contentorigin=espn&type=3&level=2&sort=playoffseed%3Aasc%2Cpoints%3Adesc%2Cgamesplayed%3Aasc%2Crotwins%3Adesc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL Wildcard"
      unique_id: nhl_wildcard
      icon: mdi:hockey-puck
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"

##
## Playoff Standings
##
- resource: https://site.web.api.espn.com/apis/v2/sports/hockey/nhl/standings?region=us&lang=en&contentorigin=espn&type=3&level=3&sort=playoffseed:asc,points:desc,gamesplayed:asc,rotwins:desc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL PO Standings"
      unique_id: nhl_po_standings
      icon: mdi:hockey
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"
##
## Playoff Standings- Postseason
##
- resource_template: "https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard?limit=1000&dates={{ now().year }}"
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL Standings Postseason"
      unique_id: nhl_standings_postseason
      json_attributes:
        - leagues
        - events
      value_template: "{{ now() }}"

##
## Schedule
##
- resource: https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard
  # every 24 hours
  scan_interval: 86400
  sensor:
    - name: "NHL Schedule"
      unique_id: nhl_schedule
      json_attributes:
        - events
      value_template: "{{ now() }}"

NHL - Template Sensors

###
### TV Coverage
###
- sensor:
    - name: NHL PO TV Coverage
      unique_id: nhl_po_tv_coverage
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], tv_channels=[], game_ctr=0, ctr=0, home='', away='') -%}
          {%- set po_tv = state_attr("sensor.nhl_schedule", 'events') | list %}
          {% for po_tv_sched in po_tv %}
            {% for game in po_tv_sched['competitions'] %}
              {% set gm_dte = as_local(as_datetime(game.startDate)).strftime('%Y-%m-%d %H:%M:%S') %}
              {% set game_dte =  as_local(as_datetime(game.startDate)).strftime('%b %d') %}
              {% set game_time =  as_local(as_datetime(game.startDate)).strftime('%I:%M %p') %}
              {% for channel in game['broadcasts'] %}
                {%- set ns.tv_channels = ns.tv_channels + [channel.names[0]] -%}
              {% endfor -%}

              {%- set ns.ctr = 0 %}
              {% for team in game['competitors'] %}
                {%- if team.homeAway == 'home' %}
                  {%- set ns.home = team.team.displayName %}
                {% else -%}
                  {%- set ns.away = team.team.displayName %}
                {% endif -%}

                {%- if ns.ctr == 1 %}
                  {% set ns.results = ns.results + [{'date': game_dte, 'time': game_time, 'home': ns.home,
                  'away': ns.away, 'tv': ns.tv_channels, 'gm_dte': gm_dte}] %}
                {% endif -%}
                {%- set ns.ctr = ns.ctr + 1 %}
              {% endfor -%}
            {%- endfor -%}
          {%- endfor -%}
          {{ ns.results }}

###
### National Hockey League
###
###
### Obtain Playoff Seeds, Playoff Games by League, and Teams by "Bracket" (WildCard, Division, League, "World")
###

###
### Wildcards - Used in Playoffs Tab to Forecast until the Playoff season starts
###
- sensor:
    - 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: >
          {% set east_al_top =  state_attr('sensor.nhl_wildcard','overall')[0]['children'][0]['standings']['entries'] %}
          {% set east_metro_top = state_attr('sensor.nhl_wildcard','overall')[0]['children'][1]['standings']['entries'] %}
          {% set east_al_name = east_al_top[0].team.displayName %}
          {% set east_metro_name = east_metro_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', east_al_name) |
            rejectattr('team.displayName', 'eq', east_metro_name) | list  %}
          {{ amer_wc[:2] }}
        east_hunt: >
          {% set east_al_top =  state_attr('sensor.nhl_wildcard','overall')[0]['children'][0]['standings']['entries'] %}
          {% set east_metro_top = state_attr('sensor.nhl_wildcard','overall')[0]['children'][1]['standings']['entries'] %}
          {% set east_al_name = east_al_top[0].team.displayName %}
          {% set east_metro_name = east_metro_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', east_al_name) |
            rejectattr('team.displayName', 'eq', east_metro_name) | list  %}
          {% set wc = amer_wc[:2] %}
          {% set wc_east_al_name = wc[0].team.displayName %}
          {% set wc_east_metro_name = wc[1].team.displayName %}
          {% set amer_hunt = amer_all |
            rejectattr('team.displayName', 'eq', east_al_name) |
            rejectattr('team.displayName', 'eq', east_metro_name) |
            rejectattr('team.displayName', 'eq', wc_east_al_name) |
            rejectattr('team.displayName', 'eq', wc_east_metro_name) | list  %}
          {{ amer_hunt[:2] }}
        east_eliminated: >
          {%- set wc_teams = state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'] | sort(attribute="stats.playoffSeed") -%}
          {{ wc_teams[4:] }}
        west_central_top: "{{ state_attr('sensor.nhl_wildcard','overall')[1]['children'][0]['standings']['entries'] }}"
        west_pacific_top: "{{ state_attr('sensor.nhl_wildcard','overall')[1]['children'][1]['standings']['entries'] }}"
        west_wildcard: >
          {% set west_central_top =  state_attr('sensor.nhl_wildcard','overall')[1]['children'][0]['standings']['entries'] %}
          {% set west_pacific_top = state_attr('sensor.nhl_wildcard','overall')[1]['children'][1]['standings']['entries'] %}
          {% set west_central_name = west_central_top[0].team.displayName %}
          {% set west_pacific_name = west_pacific_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.nhl_wildcard','children')[1]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', west_central_name) |
            rejectattr('team.displayName', 'eq', west_pacific_name) | list  %}
          {{ amer_wc[:2] }}
        west_hunt: >
          {% set west_central_top =  state_attr('sensor.nhl_wildcard','overall')[1]['children'][0]['standings']['entries'] %}
          {% set west_pacific_top = state_attr('sensor.nhl_wildcard','overall')[1]['children'][1]['standings']['entries'] %}
          {% set west_central_name = west_central_top[0].team.displayName %}
          {% set west_pacific_name = west_pacific_top[0].team.displayName %}
          {% set amer_all = state_attr('sensor.nhl_wildcard','children')[1]['standings']['entries'] %}
          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', west_central_name) |
            rejectattr('team.displayName', 'eq', west_pacific_name) | list  %}
          {% set wc = amer_wc[:2] %}
          {% set wc_west_central_name = wc[0].team.displayName %}
          {% set wc_west_pacific_name = wc[1].team.displayName %}
          {% set amer_hunt = amer_all |
            rejectattr('team.displayName', 'eq', west_central_name) |
            rejectattr('team.displayName', 'eq', west_pacific_name) |
            rejectattr('team.displayName', 'eq', wc_west_central_name) |
            rejectattr('team.displayName', 'eq', wc_west_pacific_name) | list  %}
          {{ amer_hunt[:2] }}
        west_eliminated: >
          {%- set wc_teams = state_attr('sensor.nhl_wildcard','children')[1]['standings']['entries'] | sort(attribute="stats.playoffSeed") -%}
          {{ wc_teams[4:] }}
        entries: >
          {%- set ns = namespace(ateams=[],nteams=[],al_team=[],nl_team=[],results=[]) -%}
          {%- set elim_def = 'Eliminated from Playoff Contention' -%}
          {%- set al_dict = {'league':'AL'} -%}
          {%- set nl_dict = {'league':'NL'} -%}

          {%- set ns.ateams = ns.ateams + state_attr('sensor.nhl_standings','children')[0]['children'][0]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.nhl_standings','children')[0]['children'][1]['standings']['entries'] -%}
          {% set ns.nteams = ns.nteams + state_attr('sensor.nhl_standings','children')[1]['children'][0]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.nhl_standings','children')[1]['children'][1]['standings']['entries'] %}

          {%- for team in ns.ateams -%}
            {%- set po_stat = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- if po_stat[0] != elim_def -%}
              {%- set rec_dict = dict(team.items(), **al_dict) -%}
              {%- set ns.al_team = ns.al_team + [rec_dict] -%}
            {%- endif -%}
          {%- endfor -%}

          {%- for team in ns.nteams -%}
            {%- set po_stat = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- if po_stat[0] != elim_def -%}
              {%- set rec_dict = dict(team.items(), **nl_dict) -%}
              {%- set ns.nl_team = ns.nl_team + [rec_dict] -%}
            {%- endif %}
          {%- endfor %}
          {%- set tmp_teams = ns.al_team + ns.nl_team -%}
          {{ tmp_teams }}

# ###
# ### Playoffs Seeds
# ###
- sensor:
    - name: NHL Playoff Seeds
      unique_id: sensor.nhl_playoff_seeds
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], tmp_recs=[]) -%}
          {%- for team in state_attr('sensor.nhl_wildcard_standings', 'entries') -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','points') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}

            {%- if position | count == 0 %}
              {%- set position = [''] -%}
            {%- endif -%}

            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league':team.league, 'seed': seed,
              'po_status': position[0],'home_rec': home_rec[0], 'away_rec': away_rec[0], 'wins': wins, 'losses': losses,
              'winPercent':winPercent,'logo': logo}}] -%}
          {%- endfor -%}
          {%- set ns.tmp_recs = ns.results | sort(attribute='team.league,team.seed') -%}
          {{ ns.tmp_recs }}
        po_amer_wc_seeds: >
          {%- set ns = namespace(results=[], amer_result=[], ctr=0) -%}
          {%- for team in state_attr('sensor.nhl_wildcard_standings', 'entries') | selectattr('league','eq','AL') | list -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','winPercent') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}

            {%- if position | count == 0 %}
              {%- set position = [''] -%}
            {%- endif -%}

            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league': team.league,
              'seed': seed, 'po_status': position[0], 'home_rec': home_rec[0], 'away_rec': away_rec[0],
              'logo': logo}}] -%}
          {%- endfor -%}
          {% set ns.amer_result = ns.results | sort(attribute='team.seed') %}
          {{ ns.amer_result }}
        po_natl_wc_seeds: >
          {%- set ns = namespace(results=[], natl_result=[], ctr=0) -%}
          {%- for team in state_attr('sensor.nhl_wildcard_standings', 'entries') | selectattr('league','eq','NL') | list -%}
            {%- set position = team.stats | selectattr('name','eq','clincher') | map(attribute='description') | list -%}
            {%- set home_rec = team.stats | selectattr('name','eq','Home') | map(attribute='displayValue') | list -%}
            {%- set away_rec = team.stats | selectattr('name','eq','Road') | map(attribute='displayValue') | list -%}
            {%- set seed_val = team.stats | selectattr('name','eq','playoffSeed') | map(attribute='value') | list -%}
            {%- set seed = seed_val[0] | int  -%}
            {%- set logo = team.team.logos[0].href -%}
            {%- set winPercent = (team.stats | selectattr('name','eq','winPercent') | map(attribute='displayValue') | list)[0] -%}
            {%- set wins = (team.stats | selectattr('name','eq','wins') | map(attribute='value') | list)[0] -%}
            {%- set losses = (team.stats | selectattr('name','eq','losses') | map(attribute='value') | list)[0] -%}

            {%- if position | count == 0 %}
              {%- set position = [''] -%}
            {%- endif -%}

            {%- set ns.results = ns.results + [{ 'team': {'name': team.team.displayName, 'league': team.league,
              'seed': seed, 'po_status': position[0], 'home_rec': home_rec[0], 'away_rec': away_rec[0],
              'logo': logo}}] -%}
          {%- endfor -%}
          {% set ns.natl_result = ns.results | sort(attribute='team.seed') %}
          {{ ns.natl_result }}

###
### Playoffs - Games
###
### Need to set games as there are multiple games in a series
### NHL data does not have a good key to get the data directly
###
- sensor:
    - name: NHL PO Team Games
      unique_id: sensor.nhl_po_team_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[],leag='',series=1,ser_gm=1,al_ctr=1,nl_ctr=1,home='',away='',prior_lvl=0) -%}
          {%- set po_schedule = state_attr("sensor.nhl_standings_postseason_2023", 'events') -%}
          {%- set po_sched_teams = po_schedule | selectattr('season.slug','eq','post-season') | sort(attribute='date') | list -%}
          {%- set tday = as_local(now()).strftime('%Y-%m-%d') -%}
          {%- set al_teams =  expand('group.nhl_al_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nl_teams =  expand('group.nhl_nl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nhl_teams =  expand('group.nhl_teams') | map(attribute='attributes.friendly_name') | list -%}

          {%- set gamelvlnum = {
            'FINAL': 4,
            'SEMI': 3,
            'QTR': 2,
            'RD16': 1 } -%}

          {%- for evt in po_sched_teams -%}
            {%- set gtype = evt.competitions[0].type.abbreviation -%}
            {%- set ns.series = gamelvlnum.get(gtype) -%}

            {%- if ns.series != ns.prior_lvl -%}
              {%- set ns.al_ctr = 1 -%}
              {%- set ns.nl_ctr = 1 -%}
              {%- set ns.prior_lvl = ns.series -%}
            {%- endif %}

            {%- for game in evt.competitions -%}
              {%- set ns.ser_gm = game.notes[0].headline.split("Game ")[1] -%}
              {%- set game_teams = '' %}

              {%- for team in game['competitors'] -%}
                  {%- set team_name = team.team.displayName -%}
                  {%- if team.homeAway == 'home' -%}
                    {%- if team.team.displayName in al_teams -%}
                      {%- set ns.leag = 'AL' -%}
                      {%- set ns.home = team_name -%}
                    {%- elif team.team.displayName in nl_teams -%}
                      {%- set ns.leag = 'NL' -%}
                      {%- set ns.home = team_name -%}
                    {%- else -%}
                      {%- set ns.home = 'TBD' -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if team.team.displayName in al_teams -%}
                      {%- set ns.leag = 'AL' -%}
                      {%- set ns.away = team_name -%}
                    {%- elif team.team.displayName in nl_teams -%}
                      {%- set ns.leag = 'NL' -%}
                      {%- set ns.away = team_name -%}
                    {%- else -%}
                      {%- set ns.away = 'TBD' -%}
                    {%- endif -%}
                  {%- endif -%}
              {% endfor -%}

              {%- if (nhl_teams.index(ns.away) | int) < (nhl_teams.index(ns.home)  | int) -%}
                {%- set game_teams = ns.away + '-' + ns.home -%}
              {%- else -%}
                {%- set game_teams = ns.home + '-' + ns.away -%}
              {%- endif -%}

              {% if ns.results | selectattr('game_teams','eq',game_teams) | list | count == 0 -%}
                {%- if ns.leag == 'AL' -%}
                  {%- set gnum = ns.al_ctr-%}
                  {%- set ns.al_ctr = ns.al_ctr + 1  -%}
                {% elif ns.leag == 'NL'  %}
                  {%- set gnum = ns.nl_ctr -%}
                  {%- set ns.nl_ctr = ns.nl_ctr + 1 -%}
                {%- endif -%}

                {% set ns.results = ns.results + [{'seriesNumber': ns.series, 'league': ns.leag,
                'game_teams': game_teams, 'gameNumber': gnum }] -%}
              {%- endif -%}
            {%- endfor -%}
          {% endfor -%}
          {% set sort_po_teams_games = ns.results | sort(attribute="seriesNumber, league, gameNumber") -%}
          {{ sort_po_teams_games }}

Part 4.1 of 4

sorry for the super late response! I have team tracker set up, I get the values from the sensors (PRE, IN, POST) but I can’t get them to appear on the dashboard. I can see all the teams in the standings tab, but as soon as I click postgame, live, or pregame nothing shows up. That’s the same for all the sports.

NHL - Template Sensors - Part 2

###
### Playoffs - Games
###
- sensor:
    - name: NHL PO Games
      unique_id: sensor.nhl_po_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[],gtype='',prior_lvl='',leag='',series=1,al_ctr=1,nl_ctr=1,
            home='',away='',hid='',aid='',habbrev='',aabbrev='',gctr=1,ser_gm=1,hscore=0,ascore=0,
            winner='',loser='',tv='',weather='',odds='') -%}
          {%- set po_schedule = state_attr("sensor.nhl_standings_postseason_2023", 'events') -%}
          {%- set po_sched_teams = po_schedule | selectattr('season.slug','eq','post-season') | sort(attribute='date') | list -%}
          {%- set tday = as_local(now()).strftime('%Y-%m-%d') -%}
          {%- set seeds = 'sensor.nhl_playoff_seeds' -%}
          {%- set al_teams =  expand('group.nhl_al_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nl_teams =  expand('group.nhl_nl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nhl_teams =  expand('group.nhl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set team_games = state_attr('sensor.nhl_po_team_games', 'entries') -%}

          {%- set tmp_teams = ['TBD','AL','NL'] -%}
          {%- set gamelvl = {
            'FINAL': 'Stanley Cup',
            'SEMI': 'Championship',
            'QTR': 'Divisional Playoffs',
            'RD16': 'Wild Card' } -%}
          {%- set gamelvlnum = {
            'FINAL': 4,
            'SEMI': 3,
            'QTR': 2,
            'RD16': 1 } -%}

          {%- for evt in po_sched_teams -%}
            {%- set gtype = evt.competitions[0].type.abbreviation -%}
            {%- set ns.gtype = gamelvl.get(gtype) -%}

            {%- set ns.series = gamelvlnum.get(gtype) -%}
            {%- set game_dte = '{}'.format(evt.competitions[0].date) | as_datetime | as_timestamp | timestamp_custom('%b %d at %I:%M %p') -%}
            {%- set game_day = as_local(as_datetime(evt.competitions[0].date)).strftime('%Y-%m-%d') -%}

            {%- if ns.gtype != ns.prior_lvl -%}
              {%- set ns.al_ctr = 1 -%}
              {%- set ns.nl_ctr = 1 -%}
              {%- set ns.prior_lvl = gtype -%}
            {%- endif %}

            {%- if evt.competitions[0].broadcasts | length != 0 -%}
              {%- set ns.tv = evt.competitions[0].broadcasts[0].names[0] -%}
            {%- else -%}
              {%- set ns.tv = 'N/A' -%}
            {%- endif -%}

            {%- for game in evt.competitions -%}
              {%- if game.odds is defined -%}
                {%- set ns.odds = game.odds[0].provider.name +": "+ game.odds[0].details +" OverUnder: "+
                  (game.odds[0].overUnder  | string) + " Spread: "+ (game.odds[0].spread | string) -%}
              {%- else -%}
                {%- set ns.odds = 'N/A' -%}
              {%- endif -%}

              {%- set ns.winner = '' -%}
              {%- set ns.ser_gm = game.notes[0].headline.split("Game ")[1] -%}

              {%- for team in game['competitors'] -%}
                  {%- set team_name = team.team.displayName -%}
                  {%- if team.homeAway == 'home' -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.home = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.home = team_name -%}
                      {%- set ns.hid = team.id -%}
                      {%- set ns.habbrev = team.team.abbreviation -%}
                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.home -%}
                      {%- endif -%}

                      {%- if team.score is defined -%}
                        {%- set ns.hscore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.hscore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.away = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.away = team_name -%}
                      {%- set ns.aid = team.id -%}
                      {%- set ns.aabbrev = team.team.abbreviation -%}

                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.away -%}
                      {%- endif -%}
                      {%- if team.score is defined -%}
                        {%- set ns.ascore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.ascore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- endif -%}
              {%- endfor -%}

              {%- set games_stat = game.series.summary.split(" ") -%}
              {%- set stats_len = games_stat | count -%}

              {% if games_stat[0] == 'Series' %}
                {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
              {% else -%}
                {% if games_stat[0] == ns.habbrev %}
                  {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% elif games_stat[0] == ns.aabbrev %}
                  {%- set awins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set hwins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% endif -%}
              {% endif -%}

              {%- if ns.winner != '' and ns.winner == ns.home -%}
                {%- set ns.loser = ns.away -%}
                {%- set ns.stat = 'Final' -%}
              {%- elif ns.winner != '' and ns.winner == ns.away -%}
                {%- set ns.loser = ns.home -%}
                {%- set ns.stat = 'Final' -%}
              {%- else -%}
                {%- set ns.stat = 'Ongoing' -%}
              {%- endif -%}

              {%- if ns.home in al_teams -%}
                {%- set ns.leag = 'AL' -%}
              {% elif ns.home in nl_teams %}
                {%- set ns.leag = 'NL' -%}
              {%- endif -%}

              {%- if (nhl_teams.index(ns.away) | int) < (nhl_teams.index(ns.home) | int) -%}
                {%- set game_teams = ns.away + '-' + ns.home -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- else -%}
                {%- set game_teams = ns.home + '-' + ns.away -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- endif -%}

              {% set ns.results = ns.results + [{'date': game_day,'dte': game_dte,'Game': ns.gtype,
                'seriesStatus': ns.stat,'league': ns.leag, 'winner': ns.winner,'loser': ns.loser,
                'home': ns.home,'away': ns.away, 'home_wins': hwins, 'away_wins': awins,
                'home_score': ns.hscore, 'away_score': ns.ascore, 'seriesNumber': ns.series,
                'gameNumber': ns.gctr, 'gamesInSeries': ns.ser_gm, 'seriesGameNumber':"1",'odds':ns.odds,'weather':ns.weather}] -%}
            {%- endfor -%}
          {% endfor -%}
          {%- set sort_po_teams_games = ns.results | sort(attribute="seriesNumber, gameNumber, gamesInSeries") -%}
          {{ sort_po_teams_games }}

- sensor:
    - name: NHL PO Amer Games
      unique_id: sensor.nhl_po_amer_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','AL') | list -%}
          {{ po_sched_teams }}

- sensor:
    - name: NHL PO Natl Games
      unique_id: sensor.nhl_po_natl_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','NL') | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Wildcard Games
###
- sensor:
    - name: NHL PO Amer WC Games
      unique_id: sensor.nhl_po_amer_wc_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

- sensor:
    - name: NHL PO Natl WC Games
      unique_id: sensor.nhl_po_natl_wc_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Division Games
###
- sensor:
    - name: NHL PO Amer Div Games
      unique_id: sensor.nhl_po_amer_div_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

- sensor:
    - name: NHL PO Natl Div Games
      unique_id: sensor.nhl_po_natl_div_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### Playoffs - League Games
###
- sensor:
    - name: NHL PO Amer Leag Games
      unique_id: sensor.nhl_po_amer_leag_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

- sensor:
    - name: NHL PO Natl Leag Games
      unique_id: sensor.nhl_po_natl_leag_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### Playoffs - World Game
###
- sensor:
    - name: NHL PO World Game
      unique_id: sensor.nhl_po_world_game
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_games" , 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Stanley Cup')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

NHL - Dashboard Code

type: custom:layout-card
layout_type: grid
layout:
  grid-template-columns: 25% 25% 25% 25%
  grid-template-rows: auto
  grid-template-areas: |
    "col1 col2 col3 col4"
  mediaquery:
    '(max-width: 450px)':
      grid-template-columns: 100%
      grid-template-areas: |
        "col1"
        "col2"
        "col3"
        "col4"
    '(max-width: 1200px)':
      grid-template-columns: 50% 50%
      grid-template-areas: |
        "col1 col2"
        "col3 col4"
cards:
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: NHL
          - po_level: Wild Card
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: American
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - game_num: 1
              - series_num: 1
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 2
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 2
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 3
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 3
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 3
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 4
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 4
              - attribute: po_amer_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 4
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: National
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 1
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 2
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 2
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 3
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 3
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 3
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 4
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 1
              - game_num: 4
              - attribute: po_natl_wc_seeds
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_wc_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 1
          - game_num: 4
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_wc_games
          - tv_schedule: sensor.nhl_po_tv_coverage
    view_layout:
      grid-area: col1
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: NHL
          - po_level: Division
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: American
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 2
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 2
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_div_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 2
              - game_num: 2
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 2
          - game_num: 2
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_div_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: National
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 1
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 2
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 2
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_div_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_game_title
        variables:
          - sport: NHL
          - po_game: 2
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 2
              - game_num: 2
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_div_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 2
          - game_num: 2
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_div_games
          - tv_schedule: sensor.nhl_po_tv_coverage
    view_layout:
      grid-area: col2
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: NHL
          - po_level: League
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: American
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 3
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_amer_leag_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 3
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_amer_leag_games
          - tv_schedule: sensor.nhl_po_tv_coverage
      - type: custom:decluttering-card
        template: po_league_title
        variables:
          - sport: NHL
          - po_league: National
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 3
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_natl_leag_games
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 3
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_natl_leag_games
          - tv_schedule: sensor.nhl_po_tv_coverage
    view_layout:
      grid-area: col3
      show: always
  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: po_level_title
        variables:
          - sport: NHL
          - po_level: Stanley Cup
      - type: horizontal-stack
        cards:
          - type: custom:decluttering-card
            template: po_games
            variables:
              - sport: NHL
              - series_num: 4
              - game_num: 1
              - attribute: entries
              - playoff_teams: sensor.nhl_playoff_seeds
              - playoff_schedule: sensor.nhl_po_world_game
      - type: custom:decluttering-card
        template: po_game_info
        variables:
          - sport: NHL
          - series_num: 4
          - game_num: 1
          - playoff_teams: sensor.nhl_playoff_seeds
          - playoff_schedule: sensor.nhl_po_world_game
          - tv_schedule: sensor.nhl_po_tv_coverage
    view_layout:
      grid-area: col4
      show: always


Part 4.2 of 4

The END of the bracket code - Enjoy!

If anyone can simplify the REST/template sensors, please share.

Can you please show your code for the multi-line tooltip?

I did search your github repository and couldn’t find it.

I tried embedding the \n in the html name string and it either displayed the \n or it ignored everything after that. I also tried the html
without success.

Examples of failed attempts:

name: <div title="Vacuum Name" +  "\n" + "Chico">Vacuum</div>
name: <div title="Vacuum Name \n Chico">Vacuum</div>
name: <div title="Vacuum Name <br> Chico">Vacuum</div>

What’s the trick please?

Thanks

Your post:
image

        - name: >-
            <div title="Clinch Indicator:&#10; * : Clinched Best League
            Record&#10; z : Clinched Playoff Birth&#10; x : Clinched
            Division&#10; - : In The Hunt&#10; e : Eliminated">C</div>

See here:
Hypertext Markup Language - 2.0 - The HTML Coded Character Set (w3.org)

2 Likes

Thanks again @jeffcrum to the rescue. I had removed all that code because a previous release of flex-table (now fixed), broke because of this code. I never put it back in for myself because I know what they mean.

1 Like

Thanks!

It’s the yacs (yet another character set) that always gets me!

image

1 Like

Why doesn’t Harpo get capitalized? What do you have against Harpo? :rofl:

I grew up in the XML world, so that made it easier to understand.

hey @kbrown01, sorry I can’t figure this out. I can’t get anything to load under Postgame, Live, and Pregame. All of my sensors are working and if I check each one individually I can see their state is PRE or POST. I can also see all of the teams on the dashboard within standings. They’re all in the correct division as well. The only thing that doesn’t populate on the dashboard is Postgame, Live and Pregame.

I just replaced my dashboard yaml with the yaml from github and still get the same issue.

Are you able to point me in the right direction for troubleshooting?

DO you have the red zone sensor ? If you do not, that would cause the issue. You can either remove the test for the redzone or create the redzone sensor. It is only for NFL but since all scoring uses the same template, no other sport would trigger it. Post your game stats decluttering template, this is mine with redzone:

  game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: masonry
        width: 300px
        max-columns: 5
      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\n    color:  black; \n    background-color:  #ffcccc; \n    box-shadow: 0 0 10px 5px red;\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

See this posting thread above. If you do not want redzone, this shows how that is modified to remove it:

So it is likely your situation is the same, if you do not have this sensor sensor.nfl_red_zone then that whole template would fail. SInce that template drives PRE, IN and POST views, you would get nothing.

If you want Red Zone sensor for changing colors in the Teamtracker cards as wll as using them to trigger other things, then you need this:

  - name: NFL Red Zone
    unique_id: sensor.nfl_red_zone
    state: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if states(team) == "IN" and state_attr(team, "league") == "NFL" and state_attr(team, "team_homeaway") == "home" and 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') %}
            {% if state_attr(team,'down_distance_text') is not none %}
            {% 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 %}
            {% endfor %}
            {{ redzone.teams | count }}
    attributes:
        teams: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if states(team) == "IN" and state_attr(team, "league") == "NFL" and 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') %}
            {% if state_attr(team,'down_distance_text') is not none %}
            {% 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 %}
            {% endfor %}
            {{ redzone.teams }}

Can’t believe I missed that! Thank you so much, working perfectly now.

1 Like

Harpo doesn’t know he is being insulted by the lack of capitalization. He is old and has no wifi - so as long as no one tells him, what he doesn’t know won’t hurt him.

1 Like

does anybody know how to get soccer champions league standings?
many thanks for help

Great stuff. Many thanks. unfortunately all the standings with a “*” in the entity don’t work.
Do you any idea what I do wrong?
Cheers
Alex

Also looking for standings…

Anyone have an API url for?

  • College Basketball
  • 6 Nations Rugby

Thanks!

hey @mandolin

That looks interesting.

I have add the following to my template.yaml

###
### Playoffs - Games
###
    - name: NHL PO Games
      unique_id: sensor.nhl_po_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[],gtype='',prior_lvl='',leag='',series=1,al_ctr=1,nl_ctr=1,
            home='',away='',hid='',aid='',habbrev='',aabbrev='',gctr=1,ser_gm=1,hscore=0,ascore=0,
            winner='',loser='',tv='',weather='',odds='') -%}
          {%- set po_schedule = state_attr("sensor.nhl_standings_postseason_2023", 'events') -%}
          {%- set po_sched_teams = po_schedule | selectattr('season.slug','eq','post-season') | sort(attribute='date') | list -%}
          {%- set tday = as_local(now()).strftime('%Y-%m-%d') -%}
          {%- set seeds = 'sensor.nhl_playoff_seeds' -%}
          {%- set al_teams =  expand('group.nhl_al_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nl_teams =  expand('group.nhl_nl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nhl_teams =  expand('group.nhl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set team_games = state_attr('sensor.nhl_po_team_games', 'entries') -%}

          {%- set tmp_teams = ['TBD','AL','NL'] -%}
          {%- set gamelvl = {
            'FINAL': 'Stanley Cup',
            'SEMI': 'Championship',
            'QTR': 'Divisional Playoffs',
            'RD16': 'Wild Card' } -%}
          {%- set gamelvlnum = {
            'FINAL': 4,
            'SEMI': 3,
            'QTR': 2,
            'RD16': 1 } -%}

          {%- for evt in po_sched_teams -%}
            {%- set gtype = evt.competitions[0].type.abbreviation -%}
            {%- set ns.gtype = gamelvl.get(gtype) -%}

            {%- set ns.series = gamelvlnum.get(gtype) -%}
            {%- set game_dte = '{}'.format(evt.competitions[0].date) | as_datetime | as_timestamp | timestamp_custom('%b %d at %I:%M %p') -%}
            {%- set game_day = as_local(as_datetime(evt.competitions[0].date)).strftime('%Y-%m-%d') -%}

            {%- if ns.gtype != ns.prior_lvl -%}
              {%- set ns.al_ctr = 1 -%}
              {%- set ns.nl_ctr = 1 -%}
              {%- set ns.prior_lvl = gtype -%}
            {%- endif %}

            {%- if evt.competitions[0].broadcasts | length != 0 -%}
              {%- set ns.tv = evt.competitions[0].broadcasts[0].names[0] -%}
            {%- else -%}
              {%- set ns.tv = 'N/A' -%}
            {%- endif -%}

            {%- for game in evt.competitions -%}
              {%- if game.odds is defined -%}
                {%- set ns.odds = game.odds[0].provider.name +": "+ game.odds[0].details +" OverUnder: "+
                  (game.odds[0].overUnder  | string) + " Spread: "+ (game.odds[0].spread | string) -%}
              {%- else -%}
                {%- set ns.odds = 'N/A' -%}
              {%- endif -%}

              {%- set ns.winner = '' -%}
              {%- set ns.ser_gm = game.notes[0].headline.split("Game ")[1] -%}

              {%- for team in game['competitors'] -%}
                  {%- set team_name = team.team.displayName -%}
                  {%- if team.homeAway == 'home' -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.home = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.home = team_name -%}
                      {%- set ns.hid = team.id -%}
                      {%- set ns.habbrev = team.team.abbreviation -%}
                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.home -%}
                      {%- endif -%}

                      {%- if team.score is defined -%}
                        {%- set ns.hscore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.hscore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if team_name in tmp_teams -%}
                      {%- set ns.away = 'TBD' -%}
                    {%- else -%}
                      {%- set ns.away = team_name -%}
                      {%- set ns.aid = team.id -%}
                      {%- set ns.aabbrev = team.team.abbreviation -%}

                      {%- if team.winner is defined and team.winner == True -%}
                        {%- set ns.winner = ns.away -%}
                      {%- endif -%}
                      {%- if team.score is defined -%}
                        {%- set ns.ascore = team.score | int -%}
                      {%- else -%}
                        {%- set ns.ascore = 0 -%}
                      {%- endif -%}
                    {%- endif -%}
                  {%- endif -%}
              {%- endfor -%}

              {%- set games_stat = game.series.summary.split(" ") -%}
              {%- set stats_len = games_stat | count -%}

              {% if games_stat[0] == 'Series' %}
                {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
              {% else -%}
                {% if games_stat[0] == ns.habbrev %}
                  {%- set hwins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set awins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% elif games_stat[0] == ns.aabbrev %}
                  {%- set awins = games_stat[stats_len-1].split("-")[0] | int -%}
                  {%- set hwins = games_stat[stats_len-1].split("-")[1] | int -%}
                {% endif -%}
              {% endif -%}

              {%- if ns.winner != '' and ns.winner == ns.home -%}
                {%- set ns.loser = ns.away -%}
                {%- set ns.stat = 'Final' -%}
              {%- elif ns.winner != '' and ns.winner == ns.away -%}
                {%- set ns.loser = ns.home -%}
                {%- set ns.stat = 'Final' -%}
              {%- else -%}
                {%- set ns.stat = 'Ongoing' -%}
              {%- endif -%}

              {%- if ns.home in al_teams -%}
                {%- set ns.leag = 'AL' -%}
              {% elif ns.home in nl_teams %}
                {%- set ns.leag = 'NL' -%}
              {%- endif -%}

              {%- if (nhl_teams.index(ns.away) | int) < (nhl_teams.index(ns.home) | int) -%}
                {%- set game_teams = ns.away + '-' + ns.home -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- else -%}
                {%- set game_teams = ns.home + '-' + ns.away -%}
                {%- set ns.gctr = (team_games | selectattr('game_teams','eq', game_teams) |
                  map(attribute='gameNumber') | list)[0] | int -%}
              {%- endif -%}

              {% set ns.results = ns.results + [{'date': game_day,'dte': game_dte,'Game': ns.gtype,
                'seriesStatus': ns.stat,'league': ns.leag, 'winner': ns.winner,'loser': ns.loser,
                'home': ns.home,'away': ns.away, 'home_wins': hwins, 'away_wins': awins,
                'home_score': ns.hscore, 'away_score': ns.ascore, 'seriesNumber': ns.series,
                'gameNumber': ns.gctr, 'gamesInSeries': ns.ser_gm, 'seriesGameNumber':"1",'odds':ns.odds,'weather':ns.weather}] -%}
            {%- endfor -%}
          {% endfor -%}
          {%- set sort_po_teams_games = ns.results | sort(attribute="seriesNumber, gameNumber, gamesInSeries") -%}
          {{ sort_po_teams_games }}

    - name: NHL PO Amer Games
      unique_id: sensor.nhl_po_amer_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','AL') | list -%}
          {{ po_sched_teams }}

    - name: NHL PO Natl Games
      unique_id: sensor.nhl_po_natl_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','NL') | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Wildcard Games
###
    - name: NHL PO Amer WC Games
      unique_id: sensor.nhl_po_amer_wc_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

    - name: NHL PO Natl WC Games
      unique_id: sensor.nhl_po_natl_wc_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('Game','eq','Wild Card')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ po_sched_teams }}

###
### Playoffs - Division Games
###
    - name: NHL PO Amer Div Games
      unique_id: sensor.nhl_po_amer_div_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

    - name: NHL PO Natl Div Games
      unique_id: sensor.nhl_po_natl_div_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### Playoffs - League Games
###
    - name: NHL PO Amer Leag Games
      unique_id: sensor.nhl_po_amer_leag_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

    - name: NHL PO Natl Leag Games
      unique_id: sensor.nhl_po_natl_leag_games
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }}

###
### Playoffs - World Game
###
    - name: NHL PO World Game
      unique_id: sensor.nhl_po_world_game
      device_class: timestamp
      icon: mdi:hockey
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nhl_po_games" , 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Stanley Cup')
            | sort(attribute="seriesNumber, gameNumber, seriesGameNumber") | list -%}
          {{ results }} 

Edit:
I have now include this to my rest.yaml:

##
## Wildcards
##
- resource: https://site.web.api.espn.com/apis/v2/sports/hockey/nhl/standings?region=us&lang=en&contentorigin=espn&type=3&level=2&sort=playoffseed%3Aasc%2Cpoints%3Adesc%2Cgamesplayed%3Aasc%2Crotwins%3Adesc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL Wildcard"
      unique_id: nhl_wildcard
      icon: mdi:hockey-puck
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"

##
## Playoff Standings
##
- resource: https://site.web.api.espn.com/apis/v2/sports/hockey/nhl/standings?region=us&lang=en&contentorigin=espn&type=3&level=3&sort=playoffseed:asc,points:desc,gamesplayed:asc,rotwins:desc&seasontype=2
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL PO Standings"
      unique_id: nhl_po_standings
      icon: mdi:hockey
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"
##
## Playoff Standings- Postseason
##
- resource_template: "https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard?limit=1000&dates={{ now().year }}"
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NHL Standings Postseason"
      unique_id: nhl_standings_postseason
      json_attributes:
        - leagues
        - events
      value_template: "{{ now() }}"

##
## Schedule
##
- resource: https://site.api.espn.com/apis/site/v2/sports/hockey/nhl/scoreboard
  # every 24 hours
  scan_interval: 86400
  sensor:
    - name: "NHL Schedule"
      unique_id: nhl_schedule
      json_attributes:
        - events
      value_template: "{{ now() }}"

But now if I add to my dashboard I got this:

Maybe someone can help me.

Do you have a declutter template named po_level_title?