OK, so lets start with NFL. Now … I use includes for most all my sensors. How do you do your YAML? Are they just one large configuration.yaml or includes?
If you use includes, then in configuration.yaml you would have:
template: !include template.yaml
sensor: !include sensor.yaml
and in sensor.yaml you need:
##
## NFL Standings
##
- platform: rest
scan_interval: 36000
name: NFL Standings
unique_id: sensor.nfl_standings
resource: https://site.web.api.espn.com/apis/v2/sports/football/nfl/standings?seasontype=2&type=0&level=3
value_template: "{{ now() }}"
json_attributes:
- children
and in template.yaml you need:
sensor:
###
### NFL Divisions
###
- name: NFL AFC East
unique_id: sensor.nfl_afc_east
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[0]['children'][0]['standings']['entries'] }}"
- name: NFL AFC North
unique_id: sensor.nfl_afc_north
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[0]['children'][1]['standings']['entries'] }}"
- name: NFL AFC South
unique_id: sensor.nfl_afc_south
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[0]['children'][2]['standings']['entries'] }}"
- name: NFL AFC West
unique_id: sensor.nfl_afc_west
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[0]['children'][3]['standings']['entries'] }}"
- name: NFL NFC East
unique_id: sensor.nfl_nfc_east
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[1]['children'][0]['standings']['entries'] }}"
- name: NFL NFC North
unique_id: sensor.nfl_nfc_north
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[1]['children'][1]['standings']['entries'] }}"
- name: NFL NFC South
unique_id: sensor.nfl_nfc_south
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[1]['children'][2]['standings']['entries'] }}"
- name: NFL NFC West
unique_id: sensor.nfl_nfc_west
state: "{{ now() }}"
attributes:
entries: "{{ state_attr('sensor.nfl_standings','children')[1]['children'][3]['standings']['entries'] }}"
- name: NFL Red Zone
unique_id: sensor.nfl_red_zone
state: |
{% set redzone = namespace(teams=[]) %}
{%- for team in integration_entities("teamtracker") -%}
{%- if states(team) == "IN" and state_attr(team, "league") == "NFL" and state_attr(team, "team_homeaway") == "home" and state_attr(team,'possession') is not none -%}
{% set possession = state_attr(team,'possession') %}
{% set team_id = state_attr(team,'team_id') %}
{% set opponent_id = state_attr(team,'opponent_id') %}
{% set team_abbr = state_attr(team,'team_abbr') %}
{% set opponent_abbr = state_attr(team,'opponent_abbr') %}
{% if state_attr(team,'down_distance_text') is not none %}
{% set down_distance_text = state_attr(team,'down_distance_text') %}
{% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
{% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
{% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
{% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
{%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
{% set redzone.teams = redzone.teams + [team] %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ redzone.teams | count }}
attributes:
teams: |
{% set redzone = namespace(teams=[]) %}
{%- for team in integration_entities("teamtracker") -%}
{%- if states(team) == "IN" and state_attr(team, "league") == "NFL" and state_attr(team,'possession') is not none -%}
{% set possession = state_attr(team,'possession') %}
{% set team_id = state_attr(team,'team_id') %}
{% set opponent_id = state_attr(team,'opponent_id') %}
{% set team_abbr = state_attr(team,'team_abbr') %}
{% set opponent_abbr = state_attr(team,'opponent_abbr') %}
{% if state_attr(team,'down_distance_text') is not none %}
{% set down_distance_text = state_attr(team,'down_distance_text') %}
{% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
{% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
{% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
{% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
{%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
{% set redzone.teams = redzone.teams + [team] %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ redzone.teams }}
These will create a REST sensor called sensor.nfl_standings
and the template sensors then will break that into the AFC and NFC divisions.
If you don’t have any includes yet, you create those files at the same level as the configuration.yaml (although you can place them elsewhere and organize differently). This is just my way of doing it.
The last template is a specialized one that maintains a sensor with teams in the red zone that is used to colorize the teamtracker cards.
Of course, once you have this setup you can reload the REST and then the Template Entities or just restart HA.
Once you get this, circle back and we’ll set up the flex-table cards for standings