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