Sports Standings and Scores

Gotcha. Would be useful, at least for myself, to have the current playoff week as a compact card.

Thanks. Go Lions!

You could do current playoff week by extracting data available in the TeamTracker entities for the PRE settings. This is how mine looks now:

But looking at one of those teams like the Lions, you can get this information:

attribution: Data provided by ESPN
sport: football
league: NFL
league_logo: https://a.espncdn.com/i/teamlogos/leagues/500/nfl.png
team_abbr: DET
opponent_abbr: TB
event_name: TB @ DET
date: 2024-01-21T20:00Z
kickoff_in: in 2 days
venue: Ford Field
location: Detroit, MI
tv_network: NBC
odds: DET -6.5
overunder: 49.5
team_name: Lions
team_id: "8"
team_record: 12-5
team_rank: null
team_homeaway: home
team_logo: https://a.espncdn.com/i/teamlogos/nfl/500/scoreboard/det.png
team_colors:
  - "#0076b6"
  - "#bbbbbb"
team_score: "0"
team_win_probability: null
team_winner: null
team_timeouts: null
opponent_name: Buccaneers
opponent_id: "27"
opponent_record: 9-8
opponent_rank: null
opponent_homeaway: away
opponent_logo: https://a.espncdn.com/i/teamlogos/nfl/500/scoreboard/tb.png
opponent_colors:
  - "#bd1c36"
  - "#3e3a35"
opponent_score: "0"
opponent_win_probability: null
opponent_winner: null
opponent_timeouts: null
quarter: 0
clock: 1/21 - 3:00 PM EST
possession: null
last_play: null
down_distance_text: null
outs: null
balls: null
strikes: null
on_first: null
on_second: null
on_third: null
team_shots_on_target: null
team_total_shots: null
opponent_shots_on_target: null
opponent_total_shots: null
team_sets_won: null
opponent_sets_won: null
last_update: "2024-01-18 13:54:49-08:00"
api_message: Cached data
icon: mdi:football
friendly_name: Detroit Lions

So you could extract that information into whatever you like to draw something you like. Of course that is not giving you past games, just the current upcoming games. It would also only work after ESPN updates the stats so like Monday it could draw these games.

I have a working MLB and NFL playoff bracket, but I need to finish testing and then document how people can add to their rest/template/dashboards. I hope to share it soon.

Thanks for the option! My dashboard has limited space and the team tracker cards don’t quite fit in, so I’m looking for a compact solution

Amazing looking forward to seeing that :smiley:

Define a “compact” solution … you cannot want a bracket -style layout and want a compact solution.

If you only want a simple list/table like:

A Team B Team
C Team D Team

Then you have everything to build that with what I posted and using a simple markdown card.

This is my first time sharing with the community. Here are my REST sensors, template sensors, decluttering templates, button card templates, groups, and dashboard cards for the Playoff Brackets - NFL, MLB, and NHL. I use a Home Assistant split configuration, so if you do not, you may need to modify code to match your setup. I used kbrown01’s code as a basis and then added/modified for my family’s benefit (only NHL, MLB, and NFL), so I will not post my entire configuration here. I am also not currently a github user, so I will split the information into 3 separate posts by sport. This is all based on ESPN feeds, which are subject to change.

There are additional dependencies I use for the playoff brackets - mushroom-title-card (piitaya) and button-card (RomRider). Both are available in HACS. If you do not have HACS due to your Home Assistant setup, set it up following their instructions. As part of the dashboard layout-cards, I have used mediaquery for displaying on phones and tablets. It is generic, so if it does not suit your devices, please consult thomasloven’s layout-card instructions in HACs.

I was able to find some MLB and NHL playoff data from last year and test it. It should work next year unless ESPN changes the format of their feeds.

Here is the generic code that currently works for the NFL, NHL, and MLB data for the REST/template sensors and groups I will post for the 3 sports. You need to add this to your lovelace dashboard card(s), according to your setup.

General - Shared across NFL, MLB, and NHL

Button Card Templates

button_card_templates:
  game_winner_btn:
    show_state: false
    show_name: true
    styles:
      card:
        - border: 3px solid green
  nostat_btn:
    show_state: false
    show_name: true
  playing_btn:
    show_state: false
    show_label: true
    show_name: true
    styles:
      card:
        - border: 3px solid yellow
  wip_btn:
    show_state: false
    show_name: true
    show_label: true
    styles:
      card:
        - padding: 10px
        - font-size: 20px
  live_btn:
    show_state: false
    show_name: true
    show_label: true
    styles:
      card:
        - border: 3px solid yellow
        - padding: 10px!important
  tbd_btn:
    show_state: false
    show_name: true
    show_label: true
    styles:
      card:
        - padding: 10px
  live_tv_btn:
    show_state: false
    show_name: true
    show_label: false
    styles:
      card:
        - border: 3px solid yellow
        - padding: 10px
        - font-size: 20px
  tv_btn:
    show_state: false
    show_name: true
    show_label: true
    styles:
      card:
        - border: 1px solid red
        - padding: 10px
        - font-size: 20px
  final_score_btn:
    show_state: false
    show_name: true
    show_label: true
    styles:
      card:
        - border: 3px solid green

Decluttering Templates - po_game_info corrected for Live Scores (1/29/2024)

  forecast_title:
    card:
      type: custom:mushroom-title-card
      title: '[[forecast_label]]'
      card_mod:
        style: |
          ha-card {
            .title {
              font-size: 24px;
              color: #6CB4EE;
              font-weight: bold;
              border: 1px solid white;
              padding: 3px;
              padding-bottom: -16px!important;
            }
          }
  po_level_title:
    card:
      type: custom:mushroom-title-card
      title: '[[po_level]]'
      card_mod:
        style: |
          ha-card {
            .title {
                font-size: 20px;
                color: #6CB4EE;
                background-color: #505050;
                font-weight: bold;
                border: 1px solid white;
                padding: 3px;
                text-align: center;
            }
  po_league_title:
    card:
      type: custom:mushroom-title-card
      title: '[[po_league]]'
      card_mod:
        style: |
          ha-card {
            .title {
                font-size: 20px;
                color: #6CB4EE;
                font-weight: bold;
                border-bottom: 1px solid white;
                padding: 3px;
                margin: 1px;
            }
            border-radius: 5px!important;
            padding: 3px!important;
            margin: 1px!important;
          }
  po_game_title:
    card:
      type: custom:mushroom-title-card
      title: Game [[po_game]]
      alignment: center
      card_mod:
        style: |
          ha-card {
            .title {
                font-size: 20px;
                color: #6CB4EE;
                font-weight: bold;
            }
            padding: 3px!important;
            margin: 1px!important;
          }

  po_games:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:stack-in-card
        mode: horizontal
      card_param: cards
      filter:
        template: >
          {% set ns = namespace(results=[], winner='', logo='', tmpl= '',
          name_info='',
            game_info='', tv_tmpl= '',dt_tm='', tv='TBD', weather='', ag='',odds='',
            winner_txt='',score_txt='',teams_txt='',wip_txt='') -%}

          {%- set po_teams = "[[playoff_teams]]" -%} {%- set po_schedule =
          "[[playoff_schedule]]" -%} {%- set gnum = "[[game_num]]" | int %} {%-
          set snum = "[[series_num]]" | int %} {%- set attr = "[[attribute]]"
          -%} {%- set sport = "[[sport]]" -%}

          {% set games = ['away', 'home'] -%}

          {% if sport == 'NFL' %}
            {%- set div_games = (state_attr(po_schedule, 'entries') |
              selectattr('seriesNumber','eq', snum) |  selectattr('gameNumber','eq',
              gnum) | list)[0] -%}
          {% else -%}
            {% set tmp_games = (state_attr(po_schedule, 'entries') | selectattr('seriesNumber','eq', snum) |
              selectattr('gameNumber','eq', gnum) | list) %}
            {% set last =  (tmp_games | count) - 1 %}
            {% set div_games = tmp_games[last] %}

            {% if div_games['home'] != div_games.home_advantage %}
              {% set games = ['home', 'away'] -%}
            {% endif %}
          {% endif %}

          {%- if div_games.seriesStatus == 'Final' -%}
              {%- set ns.winner = div_games.winner -%}
          {% endif -%}

          {% for team in games %}
            {%- set tday = as_local(now() ).strftime('%Y-%m-%d') %}
            {%- set time_now = as_local(now() ).strftime('%Y-%m-%d %H:%M:%S') %}
            {%- set game_day = div_games.date -%}
            {%- set game_time = div_games.gm_dte -%}
            {%- set team_name = div_games[team] -%}
            {%- set sense_nm = 'sensor.' + team_name | lower | replace(' ','_') -%}
            {%- set ns.logo = (state_attr(po_teams, attr) | selectattr('team.name','eq', team_name) |
              map(attribute='team.logo') | list)[0] -%}

            {%- if team_name == ns.winner -%}
              {%- set ns.tmpl = 'game_winner_btn' -%}
            {%- elif team_name == 'TBD' -%}
              {%- set sense_nm = po_teams -%}
              {%- set ns.logo = '/local/icons/sports/nfl.svg' %}
              {%- set ns.tmpl = 'nostat_btn' -%}
            {%- elif tday > game_day -%}
              {%- set ns.tmpl = 'nostat_btn' -%}
            {%- elif game_time < time_now -%}
              {%- set ns.tmpl = 'playing_btn' -%}
            {% else %}
            {%- endif -%}

            {%- set ns.results = ns.results + [{
                "type": "custom:button-card",
                "name": team_name,
                "entity": sense_nm,
                "layout": "name_state",
                "show_entity_picture": true,
                "entity_picture": ns.logo,
                "template": ns.tmpl,
                }]
              %}
          {%- endfor -%} {{ ns.results }}
   po_game_info:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: true
      card:
        type: custom:stack-in-card
        mode: vertical
      card_param: cards
      filter:
        template: >
          {% set ns = namespace(results=[], winner='', logo='', tmpl= '',
            name_info='', game_info='', tv_tmpl= '',dt_tm='', tv='TBD',
            weather='', odds='', winner_txt='',score_txt='',teams_txt='',
            wip_txt='') -%}
          {%- set po_schedule = "[[playoff_schedule]]" -%}  {%- set tv_schedule
          = "[[tv_schedule]]" -%}

          {%- set gnum = "[[game_num]]" | int %}  {%- set snum =
          "[[series_num]]" | int %}           {%- set po_teams =
          "[[playoff_teams]]" -%} {%- set sport = "[[sport]]" -%}

          {%- set tv_games = state_attr(tv_schedule, 'entries') | list -%}

          {% if sport == 'NFL' %}
            {%- set div_games = (state_attr(po_schedule, 'entries') |
              selectattr('seriesNumber','eq', snum) |  selectattr('gameNumber','eq',
              gnum) | list)[0] -%}
          {% else -%}
            {% set tmp_games = (state_attr(po_schedule, 'entries') | selectattr('seriesNumber','eq', snum) |
              selectattr('gameNumber','eq', gnum) | list) %}
            {% set last =  (tmp_games | count) - 1 %}
            {% set div_games = tmp_games[last] %}
          {% endif %}

          {%- if div_games.seriesStatus == 'Final' -%}
              {%- set ns.winner = div_games.winner -%}
          {% endif -%}

          {%- set home_team = div_games.home -%}  {%- set away_team =
          div_games.away -%} {%- set tdaytm = as_local(now()
          ).strftime('%Y-%m-%d %H:%M:%S') %} {%- set tday = as_local(now()
          ).strftime('%Y-%m-%d') %}

          {%- if sport == 'NFL' -%}
            {%- set ns.winner_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{win}</span>" -%}
            {%- set ns.score_txt = "<br />Score: <span style='color: cyan; font-weight: bold;font-size:20px;'>{ascore}</span> vs <span style='color: cyan; font-weight: bold;font-size:20px;'>{home_score}</span>" -%}
            {%- set ns.teams_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{ateam} vs {hteam}</span>" -%}
            {%- set ns.wip_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{arec}</span>&nbsp;&nbsp; Regular Season &nbsp;&nbsp;<span style='color: cyan; font-weight: bold;font-size:20px;'>{hrec}</span><br />" -%}

            {%- if ns.winner == home_team or ns.winner == away_team -%}
              {%- set away_score = (div_games.away_score | string) -%}
              {%- set home_score = (div_games.home_score | string) -%}
              {%- set ns.name_info = ns.winner_txt.format(win=ns.winner) -%}
              {%- set ns.game_info = ns.score_txt.format(ascore=away_score, home_score=home_score) -%}
              {%- set ns.tmpl = "final_score_btn" -%}
            {%- elif home_team == 'TBD' and away_team == 'TBD' -%}
              {%- set ns.tmpl = "tbd_btn" -%}
            {%- elif home_team == 'TBD' or away_team == 'TBD' -%}
              {%- if home_team != 'TBD' -%}
                {%- set home_rec = (state_attr(po_teams, 'entries') |
                  selectattr('team.name','eq', home_team) | map(attribute='team.home_rec') | list)[0] -%}
                {%- set away_rec = 'TBD' -%}
              {% endif -%}
              {%- if away_team != 'TBD' -%}
                {%- set away_rec = (state_attr(po_teams, 'entries') |
                  selectattr('team.name','eq', away_team) | map(attribute='team.away_rec') | list)[0] -%}
                {%- set home_rec = 'TBD' -%}
              {% endif -%}

              {%- set ns.name_info = ns.teams_txt.format(ateam=away_team, hteam=home_team) -%}
              {%- set ns.game_info = ns.wip_txt.format(arec=away_rec,hrec=home_rec) -%}
              {%- set ns.tmpl = "tbd_btn" -%}
            {%- else -%}
              {%- set game_time = div_games.gm_dte -%}
              {%- set away_score = (div_games.away_score | string) -%}
              {%- set home_score = (div_games.home_score | string) -%}
              {%- set home_rec = (state_attr(po_teams, 'entries') |
                selectattr('team.name','eq', home_team) | map(attribute='team.home_rec') | list)[0] -%}
              {%- set away_rec = (state_attr(po_teams, 'entries') |
                selectattr('team.name','eq', away_team) | map(attribute='team.away_rec') | list)[0] -%}
              {%- set ns.name_info = ns.wip_txt.format(arec=away_rec,hrec=home_rec) -%}

              {% if (tday == div_games.date) and (game_time < tdaytm) -%}
                {% set ns.tmpl = "live_btn" -%}
                {%- set away_id = 'sensor.' + away_team | lower | replace(' ','_') -%}
                {%- set home_id = 'sensor.' + home_team | lower | replace(' ','_') -%}
                {%- set away_score = state_attr(away_id, 'team_score') -%}
                {%- set home_score = state_attr(home_id, 'team_score') -%}
                {%- set ns.game_info = ns.score_txt.format(ascore=away_score, home_score=home_score) -%}
              {%- else -%}
                {%- set ns.tmpl = "wip_btn" -%}
              {%- endif -%}
            {%- endif -%}
          {%- else -%}
            {%- set game_time = div_games.gm_dte -%}
            {%- set ns.winner_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{win}</span>" -%}
            {%- set ns.win_games_txt = "<br /><span style='color: cyan; font-weight: bold;font-size:20px;'>{agames}</span>&nbsp;&nbsp; games to &nbsp;&nbsp;<span style='color: cyan; font-weight: bold;font-size:20px;'>{hgames}</span>" -%}
            {%- set ns.score_txt = "<br />Live Score: <span style='color: cyan; font-weight: bold;font-size:20px;'>{ascore}</span>&nbsp;&nbsp;<span style='color: yellow; font-weight: bold;font-size:20px;'>Live</span>&nbsp;&nbsp;<span style='color: cyan; font-weight: bold;font-size:20px;'>{home_score}</span>" -%}
            {%- set ns.wip_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{arec}</span>&nbsp;&nbsp; Regular Season &nbsp;&nbsp;<span style='color: cyan; font-weight: bold;font-size:20px;'>{hrec}</span><br />" -%}

            {%- set ns.teams_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{ateam} vs {hteam}</span>" -%}

            {%- set away_score = (div_games.away_score | string) -%}
            {%- set home_score = (div_games.home_score | string) -%}
            {%- set home_rec = (state_attr(po_teams, 'entries') |
              selectattr('team.name','eq', home_team) | map(attribute='team.home_rec') | list)[0] -%}
            {%- set away_rec = (state_attr(po_teams, 'entries') |
              selectattr('team.name','eq', away_team) | map(attribute='team.away_rec') | list)[0] -%}
            {%- set ns.name_info = ns.wip_txt.format(arec=away_rec,hrec=home_rec) -%}
            {%- set away_wins = (div_games.away_wins | string) -%}
            {%- set home_wins = (div_games.home_wins | string) -%}
            {%- set ns.game_info = ns.win_games_txt.format(agames=away_wins, hgames=home_wins) -%}

            {%- if ns.winner != '' -%}
              {%- set ns.name_info = ns.winner_txt.format(win=ns.winner) -%}
              {%- set ns.tmpl = "final_score_btn" -%}
            {%- else -%}
              {% if (tday == div_games.date) and (game_time < tdaytm) -%}
                {% set ns.tmpl = "live_btn" -%}
                {%- set away_id = 'sensor.' + away_team | lower | replace(' ','_') -%}
                {%- set home_id = 'sensor.' + home_team | lower | replace(' ','_') -%}
                {%- set away_score = state_attr(away_id, 'team_score') -%}
                {%- set home_score = state_attr(home_id, 'team_score') -%}
                {%- set ns.game_info = ns.game_info + ns.score_txt.format(ascore=away_score, home_score=home_score) -%}
              {%- else -%}
                {%- set ns.tmpl = "wip_btn" -%}
              {%- endif -%}
            {%- endif -%}
          {%- endif -%}

          {%- if ns.tmpl == 'tbd_btn' -%}
            {%- set ns.results = ns.results + [{
                "type": "custom:button-card",
                "layout": "name_state",
                "label": ns.game_info,
                "template": ns.tmpl,
                }]
            -%}
          {%- elif ns.tmpl == 'wip_btn' -%}
            {%- set ns.results = ns.results + [{
                "type": "custom:button-card",
                "layout": "name_state",
                "name": ns.name_info,
                "label": ns.game_info,
                "template": ns.tmpl,
                }]
            -%}
          {%- else -%}
            {%- set ns.results = ns.results + [{
                "type": "custom:button-card",
                "layout": "name_state",
                "name": ns.name_info,
                "label": ns.game_info,
                "template": ns.tmpl,
                }]
            -%}
          {%- endif -%}

          {%- if ns.winner == '' -%}
            {%- set tv_txt = "<span style='color: cyan; font-weight: bold;font-size:20px;'>{tv} {dte}</span><br /><br />" -%}
            {%- set odds_txt = "<span style='color: cyan; font-weight: bold;font-size:16px;'>{odds}</span><br /><br />" -%}
            {%- set weather_txt = "<span style='color: orange; font-weight: bold; font-size:18px;'>Forecast: {weather}</span>" -%}
            {%- set game_time = div_games.gm_dte -%}

            {% if (tday == div_games.date) and (game_time < tdaytm) -%}
              {%- set ns.tmpl = "live_tv_btn" -%}
            {%- else -%}
              {%- set ns.tmpl = "tv_btn" -%}
            {%- endif -%}

            {%- set ns.dt_tm = " on " + div_games.dte -%}

            {% if div_games is search(home_team) -%}
              {%- set ns.odds = odds_txt.format(odds=div_games.odds) -%}
              {%- set ns.weather = weather_txt.format(weather=div_games.weather) -%}
            {%- endif -%}

            {% if tv_games is search(home_team) -%}
              {% set tmp_tv = (tv_games | selectattr('home','eq', home_team) |
                selectattr('gm_dte','eq', game_time) | map(attribute='tv') | list)[0] -%}
              {%- if tmp_tv is defined -%}
                {%- if tmp_tv is list -%}
                  {%- if tmp_tv | count != 0 -%}
                    {%- set ns.tv = tmp_tv[0] -%}
                  {%- endif -%}
                {%- else -%}
                  {%- set ns.tv = tmp_tv -%}
                {%- endif -%}
              {%- endif -%}
            {%- endif -%}

            {%- set tv_name = tv_txt.format(tv=ns.tv,dte=ns.dt_tm) -%}
            {%- set tv_label = ns.odds + ns.weather -%}

            {%- set ns.results = ns.results + [{
                "type": "custom:button-card",
                "layout": "name_state",
                "name": tv_name,
                "label": tv_label,
                "template": ns.tmpl,
                }]
            -%}
          {%- endif -%} {{ ns.results }}

Part 1 of 4

NFL

NFL - Groups

nfl_teams:
  name: nfl_teams
  entities:
    - sensor.arizona_cardinals
    - sensor.atlanta_falcons
    - sensor.baltimore_ravens
    - sensor.buffalo_bills
    - sensor.carolina_panthers
    - sensor.chicago_bears
    - sensor.cincinnati_bengals
    - sensor.cleveland_browns
    - sensor.dallas_cowboys
    - sensor.denver_broncos
    - sensor.detroit_lions
    - sensor.green_bay_packers
    - sensor.houston_texans
    - sensor.indianapolis_colts
    - sensor.jacksonville_jaguars
    - sensor.kansas_city_chiefs
    - sensor.las_vegas_raiders
    - sensor.los_angeles_chargers
    - sensor.los_angeles_rams
    - sensor.miami_dolphins
    - sensor.minnesota_vikings
    - sensor.new_england_patriots
    - sensor.new_orleans_saints
    - sensor.new_york_giants
    - sensor.new_york_jets
    - sensor.philadelphia_eagles
    - sensor.pittsburg_steelers
    - sensor.san_francisco_49ers
    - sensor.seattle_seahawks
    - sensor.tampa_bay_buccaneers
    - sensor.tennessee_titans
    - sensor.washington_commanders

nfl_al_teams:
  name: nfl_al_teams
  entities:
    - sensor.baltimore_ravens
    - sensor.buffalo_bills
    - sensor.cincinnati_bengals
    - sensor.cleveland_browns
    - sensor.denver_broncos
    - sensor.houston_texans
    - sensor.indianapolis_colts
    - sensor.jacksonville_jaguars
    - sensor.kansas_city_chiefs
    - sensor.las_vegas_raiders
    - sensor.los_angeles_chargers
    - sensor.miami_dolphins
    - sensor.new_england_patriots
    - sensor.new_york_jets
    - sensor.pittsburg_steelers
    - sensor.tennessee_titans

nfl_nl_teams:
  name: nfl_nl_teams
  entities:
    - sensor.arizona_cardinals
    - sensor.atlanta_falcons
    - sensor.carolina_panthers
    - sensor.chicago_bears
    - sensor.dallas_cowboys
    - sensor.detroit_lions
    - sensor.green_bay_packers
    - sensor.los_angeles_rams
    - sensor.minnesota_vikings
    - sensor.new_orleans_saints
    - sensor.new_york_giants
    - sensor.philadelphia_eagles
    - sensor.san_francisco_49ers
    - sensor.seattle_seahawks
    - sensor.tampa_bay_buccaneers
    - sensor.washington_commanders

NFL - REST sensors

##
## Wildcards
##
- resource: https://site.web.api.espn.com/apis/v2/sports/football/nfl/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: "NFL Wildcard"
      unique_id: nfl_wildcard
      icon: mdi:baseball
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"

##
## Playoff Standings
##
- resource: https://site.web.api.espn.com/apis/v2/sports/football/nfl/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: "NFL PO Standings"
      unique_id: nfl_po_standings
      icon: mdi:football
      json_attributes:
        - children
        - overall
      value_template: "{{ now() }}"
##
## Playoff Standings- Postseason
##
- resource_template: "https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?limit=1000&dates={{ now().year }}"
  # every 10 hours
  scan_interval: 36000
  sensor:
    - name: "NFL Standings Postseason"
      unique_id: nfl_standings_postseason
      json_attributes:
        - leagues
        - events
      value_template: "{{ now() }}"

##
## Schedule
##
- resource: https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard
  # every 24 hours
  scan_interval: 86400
  sensor:
    - name: "NFL Schedule"
      unique_id: nfl_schedule
      icon: mdi:football
      json_attributes:
        - events
      value_template: "{{ now() }}"

NFL - Template Sensors

###
### TV Coverage
###
- sensor:
    - name: NFL PO TV Coverage
      unique_id: nfl_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_tv = state_attr("sensor.nfl_schedule", 'events') | list %}
          {% for po_tv_sched in po_tv %}
            {%- set ns.tv_channels = [] -%}
            {% 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 -%}
            {%- set ns.game_ctr = ns.game_ctr + 1 %}
            {%- endfor -%}
          {%- endfor -%}
          {{ ns.results }}

###
### National Football 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: NFL Wildcard Standings
      unique_id: sensor.nfl_wildcard_standings
      state: "{{ now() }}"
      attributes:
        nfl_afc_east_top: "{{ state_attr('sensor.nfl_po_standings','children')[0]['standings']['entries'][:1] }}"
        nfl_afc_north_top: "{{ state_attr('sensor.nfl_po_standings','children')[0]['children'][1]['standings']['entries'][:1] }}"
        nfl_afc_south_top: "{{ state_attr('sensor.nfl_po_standings','children')[0]['children'][2]['standings']['entries'][:1] }}"
        nfl_afc_west_top: "{{ state_attr('sensor.nfl_po_standings','children')[0]['children'][3]['standings']['entries'][:1] }}"
        nfl_afc_wc: >
          {% set afc_east_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][0]['standings']['entries'] %}
          {% set afc_north_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][1]['standings']['entries'] %}
          {% set afc_south_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][2]['standings']['entries'] %}
          {% set afc_west_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][3]['standings']['entries'] %}
          {% set afc_east_name = afc_east_top[:1][0].team.displayName %}
          {% set afc_north_name = afc_north_top[:1][0].team.displayName %}
          {% set afc_south_name = afc_south_top[:1][0].team.displayName %}
          {% set afc_west_name = afc_west_top[:1][0].team.displayName %}
          {% set amer_all = state_attr('sensor.nfl_wildcard','children')[0]['standings']['entries'] %}
          {% set afc_wc = amer_all |
            rejectattr('team.displayName', 'eq', afc_east_name) |
            rejectattr('team.displayName', 'eq', afc_north_name) |
            rejectattr('team.displayName', 'eq', afc_south_name) |
            rejectattr('team.displayName', 'eq', afc_west_name) | list  %}
          {{ afc_wc[:3] }}
        nfl_afc_hunt: >
          {% set afc_east_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][0]['standings']['entries'] %}
          {% set afc_north_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][1]['standings']['entries'] %}
          {% set afc_south_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][2]['standings']['entries'] %}
          {% set afc_west_top = state_attr('sensor.nfl_po_standings','children')[0]['children'][3]['standings']['entries'] %}
          {% set afc_east_name = afc_east_top[:1][0].team.displayName %}
          {% set afc_north_name = afc_north_top[:1][0].team.displayName %}
          {% set afc_south_name = afc_south_top[:1][0].team.displayName %}
          {% set afc_west_name = afc_west_top[:1][0].team.displayName %}
          {% set amer_all = state_attr('sensor.nfl_wildcard','children')[0]['standings']['entries'] %}

          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', afc_east_name) |
            rejectattr('team.displayName', 'eq', afc_north_name) |
            rejectattr('team.displayName', 'eq', afc_south_name) |
            rejectattr('team.displayName', 'eq', afc_west_name) | list  %}
          {% set wc = amer_wc[:3] %}
          {% set wc_east_one_name = wc[0].team.displayName %}
          {% set wc_east_two_name = wc[1].team.displayName %}
          {% set wc_east_three_name = wc[2].team.displayName %}
          {% set amer_hunt = amer_all |
            rejectattr('team.displayName', 'eq', afc_east_name) |
            rejectattr('team.displayName', 'eq', afc_north_name) |
            rejectattr('team.displayName', 'eq', afc_south_name) |
            rejectattr('team.displayName', 'eq', afc_west_name) |
            rejectattr('team.displayName', 'eq', wc_east_one_name) |
            rejectattr('team.displayName', 'eq', wc_east_two_name) |
            rejectattr('team.displayName', 'eq', wc_east_three_name) | list  %}
          {{ amer_hunt[:2] }}
        nfl_afc_eliminated: >
          {%- set wc_teams = state_attr('sensor.nfl_wildcard','children')[0]['standings']['entries'] |
              sort(attribute="stats.playoffSeed") -%}
          {{ wc_teams[9:] }}
        nfl_nfc_east_top: "{{ state_attr('sensor.nfl_po_standings','children')[1]['children'][0]['standings']['entries'][:1] }}"
        nfl_nfc_north_top: "{{ state_attr('sensor.nfl_po_standings','children')[1]['children'][1]['standings']['entries'][:1] }}"
        nfl_nfc_south_top: "{{ state_attr('sensor.nfl_po_standings','children')[1]['children'][2]['standings']['entries'][:1] }}"
        nfl_nfc_west_top: "{{ state_attr('sensor.nfl_po_standings','children')[1]['children'][3]['standings']['entries'][:1] }}"
        nfl_nfc_wc: >
          {% set nfc_east_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][0]['standings']['entries'] %}
          {% set nfc_north_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][1]['standings']['entries'] %}
          {% set nfc_south_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][2]['standings']['entries'] %}
          {% set nfc_west_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][3]['standings']['entries'] %}
          {% set nfc_east_name = nfc_east_top[:1][0].team.displayName %}
          {% set nfc_north_name = nfc_north_top[:1][0].team.displayName %}
          {% set nfc_south_name = nfc_south_top[:1][0].team.displayName %}
          {% set nfc_west_name = nfc_west_top[:1][0].team.displayName %}
          {% set amer_all = state_attr('sensor.nfl_wildcard','children')[1]['standings']['entries'] %}
          {% set nfc_wc = amer_all |
            rejectattr('team.displayName', 'eq', nfc_east_name) |
            rejectattr('team.displayName', 'eq', nfc_north_name) |
            rejectattr('team.displayName', 'eq', nfc_south_name) |
            rejectattr('team.displayName', 'eq', nfc_west_name) | list  %}
          {{ nfc_wc[:3] }}
        nfl_nfc_hunt: >
          {% set nfc_east_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][0]['standings']['entries'] %}
          {% set nfc_north_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][1]['standings']['entries'] %}
          {% set nfc_south_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][2]['standings']['entries'] %}
          {% set nfc_west_top = state_attr('sensor.nfl_po_standings','children')[1]['children'][3]['standings']['entries'] %}
          {% set nfc_east_name = nfc_east_top[:1][0].team.displayName %}
          {% set nfc_north_name = nfc_north_top[:1][0].team.displayName %}
          {% set nfc_south_name = nfc_south_top[:1][0].team.displayName %}
          {% set nfc_west_name = nfc_west_top[:1][0].team.displayName %}
          {% set amer_all = state_attr('sensor.nfl_wildcard','children')[1]['standings']['entries'] %}

          {% set amer_wc = amer_all |
            rejectattr('team.displayName', 'eq', nfc_east_name) |
            rejectattr('team.displayName', 'eq', nfc_north_name) |
            rejectattr('team.displayName', 'eq', nfc_south_name) |
            rejectattr('team.displayName', 'eq', nfc_west_name) | list  %}
          {% set wc = amer_wc[:3] %}
          {% set wc_east_one_name = wc[0].team.displayName %}
          {% set wc_east_two_name = wc[1].team.displayName %}
          {% set wc_east_three_name = wc[2].team.displayName %}
          {% set amer_hunt = amer_all |
            rejectattr('team.displayName', 'eq', nfc_east_name) |
            rejectattr('team.displayName', 'eq', nfc_north_name) |
            rejectattr('team.displayName', 'eq', nfc_south_name) |
            rejectattr('team.displayName', 'eq', nfc_west_name) |
            rejectattr('team.displayName', 'eq', wc_east_one_name) |
            rejectattr('team.displayName', 'eq', wc_east_two_name) |
            rejectattr('team.displayName', 'eq', wc_east_three_name) | list  %}
          {{ amer_hunt[:2] }}
        nfl_nfc_eliminated: >
          {%- set wc_teams = state_attr('sensor.nfl_wildcard','children')[1]['standings']['entries'] |
              sort(attribute="stats.playoffSeed") -%}
          {{ wc_teams[9:] }}
        entries: >
          {%- set ns = namespace(ateams=[],nteams=[],afce_team=[],nfce_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.nfl_standings','children')[0]['children'][0]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.nfl_standings','children')[0]['children'][1]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.nfl_standings','children')[0]['children'][2]['standings']['entries'] -%}
          {%- set ns.ateams = ns.ateams + state_attr('sensor.nfl_standings','children')[0]['children'][3]['standings']['entries'] -%}

          {% set ns.nteams = ns.nteams + state_attr('sensor.nfl_standings','children')[1]['children'][0]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.nfl_standings','children')[1]['children'][1]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.nfl_standings','children')[1]['children'][2]['standings']['entries'] %}
          {% set ns.nteams = ns.nteams + state_attr('sensor.nfl_standings','children')[1]['children'][3]['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.afce_team = ns.afce_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.nfce_team = ns.nfce_team + [rec_dict] -%}
            {%- endif %}
          {%- endfor %}
          {%- set tmp_teams = ns.afce_team + ns.nfce_team -%}
          {{ tmp_teams }}

# ###
# ### Playoffs Seeds
# ###
- sensor:
    - name: NFL Playoff Seeds
      unique_id: sensor.nfl_playoff_seeds
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[], tmp_recs=[]) -%}
          {%- for team in state_attr('sensor.nfl_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 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.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.nfl_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 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.nfl_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 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
###
- sensor:
    - name: NFL PO Games
      unique_id: sensor.nfl_po_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set ns = namespace(results=[],sorted=[],gtype='',leag='',agctr=1,nlctr=1,gctr=1,ser_gm=1,tv='',weather='',odds='',hscore=0,ascore=0,winner='') -%}
          {%- set po_schedule = state_attr("sensor.nfl_standings_postseason", '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.nfl_playoff_seeds' -%}
          {%- set al_teams =  expand('group.nfl_al_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set nl_teams =  expand('group.nfl_nl_teams') | map(attribute='attributes.friendly_name') | list -%}
          {%- set tmp_teams = ['TBD','AFC','NFC'] -%}

          {% for evt in po_sched_teams -%}
            {% if evt.competitions[0].notes[0].headline is search('Pro Bowl') %}
              {%- continue -%}
            {%- else -%}
              {%- 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') -%}
              {%- set gm_dte = as_local(as_datetime(evt.competitions[0].date)).strftime('%Y-%m-%d %H:%M:%S') -%}
              {% if evt.competitions[0].notes[0].headline is search('Super Bowl') %}
                {%- set ns.gtype = 'Super Bowl' -%}
                {%- set ns.series = 4 -%}
              {%- elif evt.competitions[0].notes[0].headline is search('Championship') -%}
                {%- set ns.gtype = 'Championship' -%}
                {%- set ns.series = 3 -%}
              {%- elif evt.competitions[0].notes[0].headline is search('Divisional Playoffs') -%}
                {%- set ns.gtype = 'Divisional Playoffs' -%}
                {%- set ns.series = 2 -%}
              {%- else -%}
                {%- set ns.gtype = 'Wild Card' -%}
                {%- set ns.series = 1 -%}
              {%- 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 -%}

              {%- if game_day == tday %}
                {%- set ns.stat = 'Ongoing' -%}
              {%- elif game_day <= tday %}
                {%- set ns.stat = 'Final' -%}
              {%- else -%}
                {%- set ns.stat = 'Ongoing' -%}
              {% endif %}

              {% if evt.weather is defined %}
                {%- set ns.weather = evt.weather.displayValue + " " + (evt.weather.temperature | string) -%}
              {%- else -%}
                {%- set ns.weather = '' -%}
              {% 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 = '' -%}
                {%- 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 -%}

                        {%- if ns.stat == 'Final' and 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 -%}

                        {%- if ns.stat == 'Final' and team.score is defined -%}
                          {%- set ns.ascore = team.score | int -%}
                        {%- else -%}
                          {%- set ns.ascore = 0 -%}
                        {%- endif -%}
                      {%- endif -%}
                    {%- endif -%}

                    {%- if team_name in tmp_teams and evt.competitions[0].notes[0].headline is search('AFC Championship') %}
                        {%- set ns.leag = 'AL' -%}
                    {% elif  team_name in tmp_teams and evt.competitions[0].notes[0].headline is search('NFC Championship') %}
                        {%- set ns.leag = 'NL' -%}
                    {%- else -%}
                      {%- if team_name in al_teams -%}
                        {%- set ns.leag = 'AL' -%}
                      {%- elif team_name in nl_teams -%}
                        {%- set ns.leag = 'NL' -%}
                      {%- else -%}
                        {%- continue -%}
                      {%- endif -%}
                    {%- endif -%}
                {% endfor -%}

                {%- if ns.stat == 'Final' -%}
                  {%- if ns.hscore > ns.ascore -%}
                    {%- set ns.winner = ns.home -%}
                    {%- set ns.loser = ns.away -%}
                  {%- else -%}
                    {%- set ns.winner = ns.away -%}
                    {%- set ns.loser = ns.home -%}
                  {%- endif -%}
                {%- else -%}
                  {%- set ns.winner = '' -%}
                  {%- set ns.loser = '' -%}
                {%- endif -%}

                {%- if ns.leag == 'AL' -%}
                  {%- set ns.gctr = ns.agctr -%}
                  {%- set ns.agctr = ns.agctr + 1 -%}
                {%- elif ns.leag == 'NL' -%}
                  {%- set ns.gctr = ns.nlctr -%}
                  {%- set ns.nlctr = ns.nlctr + 1 -%}
                {%- else -%}
                  {%- continue -%}
                {%- endif -%}

                {%- set ns.results = ns.results + [{'date': game_day,'dte': game_dte,'Game': ns.gtype,'seriesStatus': ns.stat,'league': ns.leag,
                  'gm_dte': gm_dte, 'winner': ns.winner,'loser': ns.loser,'home': ns.home,'away': ns.away,'home_score': ns.hscore,'away_score': ns.ascore,
                  'seriesNumber': ns.series, 'gameNumber': ns.gctr, 'gamesInSeries': "1", 'seriesGameNumber':"1",'odds':ns.odds,'weather':ns.weather}] -%}
              {%- endfor -%}
            {%- endif -%}
          {% endfor -%}
          {{ ns.results }}

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

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

###
### Playoffs - Wildcard Games
###
- sensor:
    - name: NFL PO Amer WC Games
      unique_id: sensor.nfl_po_amer_wc_games
      device_class: timestamp
      icon: mdi:baseball
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_schedule = state_attr("sensor.nfl_po_amer_games", 'entries') -%}
          {%- set po_sched_teams = po_schedule | selectattr('league','eq','AL') | list -%}
          {{ po_sched_teams }}

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

###
### Playoffs - Division Games
###
- sensor:
    - name: NFL PO Amer Div Games
      unique_id: sensor.nfl_po_amer_div_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nfl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs') | list %}
          {{ results }}

- sensor:
    - name: NFL PO Natl Div Games
      unique_id: sensor.nfl_po_natl_div_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nfl_po_natl_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Divisional Playoffs') | list %}
          {{ results }}

###
### Playoffs - League Games
###
- sensor:
    - name: NFL PO Amer Leag Games
      unique_id: nfl_po_amer_leag_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nfl_po_amer_games", 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship') | list %}
          {{ results }}

- sensor:
    - name: NFL PO Natl Leag Games
      unique_id: nfl_po_natl_leag_games
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nfl_po_natl_games" , 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Championship') | list %}
          {{ results }}

###
### Playoffs - World Game
###
- sensor:
    - name: NFL PO World Game
      unique_id: nfl_po_world_game
      device_class: timestamp
      icon: mdi:football
      state: "{{ now() }}"
      attributes:
        entries: >
          {%- set po_sched_teams = state_attr("sensor.nfl_po_games" , 'entries') -%}
          {%- set results = po_sched_teams | selectattr('Game','eq', 'Super Bowl') | list %}
          {{ results }}

Part 2.1 of 4 (dashboard would not fit)

NFL - 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: NFL
            - po_level: Wild Card
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: American
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 1
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 1
                - series_num: 1
                - attribute: po_amer_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 1
            - series_num: 1
            - attribute: po_amer_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 2
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 2
                - series_num: 1
                - attribute: po_amer_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 2
            - series_num: 1
            - attribute: po_amer_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 3
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 3
                - series_num: 1
                - attribute: po_amer_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 3
            - series_num: 1
            - attribute: po_amer_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: National
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 1
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 1
                - series_num: 1
                - attribute: po_natl_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 1
            - series_num: 1
            - attribute: po_natl_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 2
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 2
                - series_num: 1
                - attribute: po_natl_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 2
            - series_num: 1
            - attribute: po_natl_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 3
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 3
                - series_num: 1
                - attribute: po_natl_wc_seeds
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_wc_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 3
            - series_num: 1
            - attribute: po_natl_wc_seeds
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_wc_games
            - tv_schedule: sensor.nfl_po_tv_coverage
    view_layout:
        grid-area: col1
        show: always
    - type: vertical-stack
    cards:
        - type: custom:decluttering-card
        template: po_level_title
        variables:
            - sport: NFL
            - po_level: Division
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: American
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 1
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 4
                - series_num: 2
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_div_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 4
            - series_num: 2
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_div_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 2
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 5
                - series_num: 2
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_div_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 5
            - series_num: 2
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_div_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: National
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 1
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 4
                - series_num: 2
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_div_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 4
            - series_num: 2
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_div_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_game_title
        variables:
            - sport: NFL
            - po_game: 2
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 5
                - series_num: 2
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_div_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 5
            - series_num: 2
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_div_games
            - tv_schedule: sensor.nfl_po_tv_coverage
    view_layout:
        grid-area: col2
        show: always
    - type: vertical-stack
    cards:
        - type: custom:decluttering-card
        template: po_level_title
        variables:
            - sport: NFL
            - po_level: League
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: American
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: AL
                - game_num: 6
                - series_num: 3
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_amer_leag_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: AL
            - game_num: 6
            - series_num: 3
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_amer_leag_games
            - tv_schedule: sensor.nfl_po_tv_coverage
        - type: custom:decluttering-card
        template: po_league_title
        variables:
            - sport: NFL
            - po_league: National
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - league: NL
                - game_num: 6
                - series_num: 3
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_natl_leag_games
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - league: NL
            - game_num: 6
            - series_num: 3
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_natl_leag_games
            - tv_schedule: sensor.nfl_po_tv_coverage
    view_layout:
        grid-area: col3
        show: always
    - type: vertical-stack
    cards:
        - type: custom:decluttering-card
        template: po_level_title
        variables:
            - sport: NFL
            - po_level: Super Bowl
        - type: horizontal-stack
        cards:
            - type: custom:decluttering-card
            template: po_games
            variables:
                - sport: NFL
                - game_num: 7
                - series_num: 4
                - attribute: entries
                - playoff_teams: sensor.nfl_playoff_seeds
                - playoff_schedule: sensor.nfl_po_world_game
        - type: custom:decluttering-card
        template: po_game_info
        variables:
            - sport: NFL
            - game_num: 7
            - series_num: 4
            - playoff_teams: sensor.nfl_playoff_seeds
            - playoff_schedule: sensor.nfl_po_world_game
            - tv_schedule: sensor.nfl_po_tv_coverage
    view_layout:
        grid-area: col4
        show: always

Part 2.2 of 4

Can’t add MLB right now. The forum software says I need to wait for someone to reply.

Be happy to reply. Send us a picture too. Afterall they are worth 1000 words!

@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: