NHL Stats API Integration Into Home Assistant: Bring live score updates into Home Assistant and fire automations when your team scores!
The sensor will only fetch data every 10 minutes when the game is not live and will then update at the user defined frequency (or every second if undefined) once the game is live. Credit goes to @mastermc0.
Note: The NHL updates their endpoints every 15 seconds.
- Copy the
nhl_apifolder to thecustom_componentsfolder in your Home Assistant configuration directory. - From the teams.md file in this repository, find the team_abbrev of the team you would like to track.
- Restart Home Assistant to allow the required packages to be installed.
- Add the following minimum code in your
configuration.yamlfile. See Configuration for more advanced options:
sensor:
- platform: nhl_api
team_abbrev: [TEAM ABBREV FOUND IN STEP 2]
- Restart Home Assistant one final time.
This method assumes you have HACS already installed.
- In the HACS Store, search for
NHLand find theNHL APIintegration and install it. - From the teams.md file in this repository, find the team_abbrev of the team you would like to track.
- Restart Home Assistant to allow the required packages to be installed.
- Add the following code in your
configuration.yamlfile. See Configuration for more advanced options:
sensor:
- platform: nhl_api
team_abbrev: [TEAM ABBREV FOUND IN STEP 2]
- Restart Home Assistant one final time.
| key | required | type | usage |
|---|---|---|---|
| platform | true | string | nhl_api |
| team_abbrev | true | string | Identifies the team to be tracked by the sensor. See teams.md. |
| name | false | string | Friendly name of the sensor. If not defined, defaults to: 'NHL Sensor'. |
| scan_interval | false | integer | Number of seconds until the sensor updates its state when the game is live. If not defined, defaults to 1 second. |
Warning! Setting your scan_interval to a low number leads to more writes to your disk. It is recommended to not set the scan interval to less than 5 if running Home Assistant on a Raspberry Pi. Also, each time the sensor updates (i.e. at each scan interval), anywhere from ~300B to ~25KB of data is consumed. Keep this in mind if you have a low internet data cap.
sensor:
- platform: nhl_api
team_abbrev: mtl
name: Canadiens
scan_interval: 30
The sensor will expose the status of the tracked team's scheduled game for the day. The state can be:
| state | description |
|---|---|
| Next Game Date & Time | The next game is not yet close to starting. Will return date and time of the next game. |
| PRE | The scheduled game is with 30 minutes of its scheduled start. |
| LIVE | The scheduled game is live. |
| CRIT | The scheduled game is within 5 minutes of the 3rd period's end. |
| OVER | The scheduled game has recently ended. |
| FINAL | The scheduled game is over and the score is final. |
| OFF | The scheduled game is over and the score is official |
| No Game Scheduled | There are no scheduled games upcoming. |
The sensor will return the following state attributes whether or not a game is in progress:
| attribute | type | usage |
|---|---|---|
| national_broadcasts | list | The national broadcast stations for the current/upcoming game. |
| away_broadcasts | list | The away team's broadcast stations for the current/upcoming game. |
| home_broadcasts | list | The home team's broadcast stations for the current/upcoming game. |
| away_id | integer | Identifies the away team by team id as found in teams.md. |
| home_id | integer | Identifies the home team by team id as found in teams.md. |
| away_name | string | The name of the away team. |
| home_name | string | The name of the home team. |
| away_record | string | The record of the away team. |
| home_record | string | The record of the home team. |
| away_logo | string | The url to the away team's logo. |
| home_logo | string | The url to the home team's logo. |
| away_logo_dark | string | The url to the away team's logo for dark mode. |
| home_logo_dark | string | The url to the home team's logo for dark mode. |
| next_game_date | string | The date of the next game. |
| next_game_time | string | The time of the next game. This will be localized based on your Home Assistant configured timezone. |
| next_game_datetime | string | The date and time of the next game. This will be localized based on your Home Assistant configured timezone. |
The sensor will also return the following state attributes when a game is in progress:
| attribute | type | usage |
|---|---|---|
| goal_type | string | At what strength the goal was scored such as EVEN, PPG, SHG, etc. |
| goal_team_id | integer | The id of the team that scored the last goal. |
| goal_event_id | integer | The event id of the goal generated by the API. |
| goal_team_name | string | The name of the team that scored the last goal. |
| scoring_player_name | string | The name of the player who scored the last goal. |
| scoring_player_total | integer | The number of goals recorded by the scoring player this season. |
| scoring_player_number | integer | The jersey number of the player who scored the last goal. |
| assist1_player_name | string | The name of the player who had the primary assist for the last goal. |
| assist1_player_total | integer | The number of assists recorded by the primary assist player this season. |
| assist1_player_number | integer | The jersey number of the player who had the primary assist for the last goal. |
| assist2_player_name | string | The name of the player who had the secondary assist for the last goal. |
| assist2_player_total | integer | The number of assists recorded by the secondary assist player this season. |
| assist2_player_number | integer | The jersey number of the player who had the secondary assist for the last goal. |
| away_score | integer | The number of goals scored by the away team. |
| home_score | integer | The number of goals scored by the home team. |
| away_sog | integer | The number of shots on goal by the away team. |
| home_sog | integer | The number of shots on goal by the home team. |
| current_period | string | The current period. |
| current_period_type | string | The current period type. Returns one of REG, OT or SO. |
| is_intermission | boolean | Returns true if it is currently between periods. |
| time_remaining | string | The time remaining in the current period. |
| goal_tracked_team | boolean | Returns true if the last goal was scored by the team being tracked. Otherwise, returns false. Can be useful for goal alerts. |
Display info in the front end: frontend.md
Sample automations: automations.md
- Consume undocumented NHL Stats API locally with the least amount of resources possible.
- Pass information to Home Assistant as sensor data. (ex. Next game scheduled, live scores, goal description, etc.)
- Create a "goal" event platform to use as a trigger for automations.
- Display the information in the front-end in its own Lovelace card.
- Add support for
HACS.
The Undocumented NHL Stats API
Drew Hynes' Unofficial Documentation