Skip to content

Standings REST Sensor

David edited this page Feb 25, 2023 · 3 revisions

To create a sensor to pull back standings, use the following as a template to create a REST sensor

  - platform: rest
    name: {SENSOR_NAME}
    scan_interval: {SCAN_INTERVAL}
    resource: https://site.web.api.espn.com/apis/v2/sports/{SPORT_PATH}/{LEAGUE_PATH}/standings?type={STANDINGS_TYPE}&level={STANDINGS_LEVEL}
    value_template: "{{ now() }}"
    json_attributes_path: "{JSON_PATH}['standings']"
    json_attributes:
      - entries

How to replace the values in the template:

  • {SENSOR_NAME} - The name of your sensor
  • {SCAN_INTERVAL} - The interval between API calls in seconds. Do not call the API more frequently than once per hour, which is 3600 seconds.
  • {SPORT_PATH} - The sport_path used for the API call in the TeamTracker sensor.
  • {LEAGUE_PATH} - The league_path used for the API call in the TeamTracker sensor.
  • {STANDINGS_TYPE} - The type of standings returned by the API.
  • 0 - Overall Standings
  • 1 - Varies based on league
  • 2 - Varies based on league
  • 3 - Varies based on league
  • {STANDINGS_LEVEL} - Indicates the level of standings to return when in addition to league standings, there may also be Conference, Division, and other levels of standings. Values and meaning vary by league.
  • To return a single top to bottom list of standings for all teams in the league, you will generally use a value of 0 or 1
  • To return multiple sets of sub-standings going one level down (i.e. Conference level), you will generally use a value of 1 or 2
  • To return multiple sets of sub-standings going two levels down (i.e. Division level), you will generally use a value of 2 or 3
  • {JSON_PATH} - The JSON path to the standings. Varies based on league and {STANDINGS_LEVEL}
  • If the {STANDINGS_LEVEL} is 0, use the value may be $
  • If the {STANDINGS_LEVEL} is 0 or 1, the the value may be $['children'][x],where x is the index to the standings you want to use.
  • If the {STANDINGS_LEVEL} is 1 or 2, the the value may be $['children'][x]['children'][y],where x and y are the indices to the standings you want to use.

Because of variances between leagues, you must inspect the JSON returned by the API to determine the correct values to use.

Working example - EPL Standings

  - platform: rest
    name: EPL Standings
    scan_interval: 3600
    resource: https://site.web.api.espn.com/apis/v2/sports/soccer/eng.1/standings?type=0&level=0
    value_template: "{{ now() }}"
    json_attributes_path: "$['children'][0]['standings']"
    json_attributes:
      - entries

Working Example - NHL Metro Div Standings

  - platform: rest
    name: NHL Standings
    scan_interval: 3600
    resource: https://site.web.api.espn.com/apis/v2/sports/hockey/nhl/standings?type=0&level=3
    value_template: "{{ now() }}"
    json_attributes_path: "$['children'][0]['children'][1]['standings']"
    json_attributes:
      - entries