NHL API Custom Component - Track your favorite hockey team in Home Assistant!

Can you please post your config and automation?

Sorry!

Configuration:

input_number:
away_score:
min: 0
max: 100
home_score:
min: 0
max: 100

Automation:

  • id: reset_score
    alias: reset_score
    initial_state: true
    trigger:
    platform: state
    entity_id: sensor.nhl_hockey
    from: Scheduled
    to: Pre-Game
    action:
    • service: input_number.set_value
      entity_id: input_number.home_score
      data:
      value: 0
    • service: input_number.set_value
      entity_id: input_number.away_score
      data:
      value: 0
  • id: away_scores
    alias: away_scores
    initial_state: true
    trigger:
    • platform: template
      value_template: ‘{{ states.sensor.away_team.state | int > states(’‘numeric_input.away_score’’)
      | int }}’
      action:
    • service: input_number.set_value
      entity_id: numeric_input.away_score
      data_template:
      value: ‘{{ states.sensor.away_team.state |int }}’
    • service: notify.alexa_media_living_room
      data:
      message: ‘{{ state_attr( ‘‘sensor.away_team’’, ‘‘friendly_name’’) }} score!’
      data:
      type: tts
  • id: home_scores
    alias: home_scores
    initial_state: true
    trigger:
    • platform: template
      value_template: ‘{{ states.sensor.home_team.state | int > states(’‘numeric_input.home_score’’)
      | int }}’
      action:
    • service: input_number.set_value
      entity_id: numeric_input.home_score
      data_template:
      value: ‘{{ states.sensor.home_team.state |int }}’
    • service: notify.alexa_media_living_room
      data:
      message: ‘{{ state_attr( ‘‘sensor.home_team’’, ‘‘friendly_name’’) }} score!’
      data:
      type: tts
  • id: jets_score
    alias: jets_score
    trigger:
    • platform: template
      value_template: ‘{{ states.sensor.away_team.state |int > states.numeric_input.away_score
      |int or states.sensor.home_team.state |int > states.numeric_input.home_score
      |int }}’
      condition:
    • condition: template
      value_template: ‘{{ state_attr(’‘sensor.nhl_sensor’’, ‘‘goal_tracked_team’’) }}’
      action:
    • data:
      delay: 00:00:00
      home_entity: media_player.living_room
      wave: /local/Goal-horn-sound-effect.mp3
      service: script.home_wave
      initial_state: true
  • id: final_score
    alias: final_score
    initial_state: true
    trigger:
    platform: state
    entity_id: sensor.nhl_hockey
    from: In Progress
    to: Final
    action:
    • service: notify.alexa_media_living_room
      data:
      message: ‘Final Score: {{ state_attr( ‘‘sensor.away_team’’, ‘‘friendly_name’’)
      }} {{ states(’‘sensor.away_team’’) }}, {{ state_attr( ‘‘sensor.home_team’’,
      ‘‘friendly_name’’) }}{{ states(’‘sensor.home_team’’) }} !’
      data:
      type: tts
  • id: Winnipeg_Goal_Announcement
    alias: Winnipeg Goal Announcement
    trigger:
    platform: event
    event_type: nhl_goal
    event_data:
    team_id: ‘52’
    action:
    service: tts.google_say
    entity_id: media_player.living_room_speaker
    data:
    message: The Jets scored!

Sensor:

  • platform: nhl_api
    team_id: 52
  • platform: template
    sensors:
    away_team:
    friendly_name_template: ‘{{ states.sensor.nhl_sensor.attributes.away_name }}’
    value_template: ‘{{ states.sensor.nhl_sensor.attributes.away_score }}’
    entity_picture_template: ‘{{ states.sensor.nhl_sensor.attributes.away_logo }}’
    home_team:
    friendly_name_template: ‘{{ states.sensor.nhl_sensor.attributes.home_name }}’
    value_template: ‘{{ states.sensor.nhl_sensor.attributes.home_score }}’
    entity_picture_template: ‘{{ states.sensor.nhl_sensor.attributes.home_logo }}’

No worries! You combined the old method with the new method (see the docs).

You should scrap those automations and instead only use this.

Make sure to substitute with the entity ID of your Alexa and make sure to have TTS enabled in your config.

- alias: 'Winnipeg Goal Announcement'
  trigger:
    platform: event
    event_type: nhl_goal
    event_data:
      team_id: "52"
  action:
    service: tts.google_translate_say
    entity_id: media_player.living_room_speaker
    data:
      message: 'The Jets scored!'

hey, I go your sensor set up and it worked great for the first two NYR games.

However, right now my lovelace card has the next scheduled game 1/22) but home and away team are reading “unavailable” and it is displaying “home team” and “away team” rather than the team names.

Seems to have happened with the most recent HA update. Any ideas? Just got some LEDs to do my goal light for this.

Thanks for using it!

I haven’t experienced this and I am on 2021.1.4.
Do you have any error messages in the log? Did you try restarting your HA server?

I’ve had this issue since I installed it in 2019, I believe

I did restart HA, which didn’t resolve it.

What did resolve it, was updating HACS, and clearing cache.

Thanks for your work!

1 Like

Hi everyone,

I wanted to announce a few new highly requested features:

  • Dynamic polling: the sensor will update every 10 mins while no game is live, every 10 seconds in pregame and every second during a live game (unless the user defines their own scan_interval)
  • New attributes: the sensor will now expose shots on goal, current period and time remaining in the period.

Make sure to update to version 0.7.0 via HACS!

1 Like

Is there any way to shrink the logo size so it fits in the circle?

That is a function of the lovelace card, not the component. You would need to look up a custom card (or create one) that accomplishes this.

I’d be willing to work with a frontend dev that’s interested in creating a custom card for this component.

This is amazing! Thank you! I have the Bruins goal horn play on my speakers whenever they score. Is there a way to create a trigger when your team wins the game? Is there a way to have a State for an Opponent Score?

Hi what would a config file look like if it was possible to populate a card with updated standings?

NHL API v0.8.1
Home Assistant version 2021.3.4

I’m having a weird problem with my sensor for Vegas, but I’m not sure if it’s an integration issue, an HA issue, or something dumb I’ve done. I have not changed it in months, but the last week or so it keeps getting “stuck” during the game and does not finish. I have to restart HA to get it to update again.

Right now (Sunday morning) it reports:

ENTITY                                     DESCRIPTION           STATE        CHANGED
sensor.nhl_vegas_golden_knights            Vegas Golden Knights  In Progress  2021-03-14T01:06:50.426690+00:00
sensor.nhl_vegas_golden_knights_away_team  Vegas Golden Knights  3            2021-03-14T15:54:46.918340+00:00
sensor.nhl_vegas_golden_knights_home_team  St. Louis Blues       1            2021-03-14T15:54:46.919072+00:00

Lots of info below, but I guess I’m asking if anybody else is seeing this happen?

My sensors:

homeassistant:

#################################################################
#                                                               #
#                           Sensors                             #
#                                                               #
#################################################################

sensor:

  - platform: nhl_api
    team_id: 54
    name: 'NHL Vegas Golden Knights'

#################################################################
#                                                               #
#                       Template Sensors                        #
#                                                               #
#################################################################

  - platform: template
    sensors:
      nhl_vegas_golden_knights_away_team:
        friendly_name_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.away_name }}'
        value_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.away_score }}'
        entity_picture_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.away_logo }}'
      nhl_vegas_golden_knights_home_team:
        friendly_name_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.home_name }}'
        value_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.home_score }}'
        entity_picture_template: '{{ states.sensor.nhl_vegas_golden_knights.attributes.home_logo }}'

They are exactly the same for each team, I generate them from a template, and all the other ones seem fine.

I do get a log entries that it has trouble updating:

2021-03-13 12:09:51 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_boston_bruins is taking over 10 seconds
2021-03-13 18:50:48 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds
2021-03-13 18:50:55 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_new_york_islanders is taking over 10 seconds
2021-03-13 18:51:04 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_tampa_bay_lightning is taking over 10 seconds
2021-03-13 18:51:08 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds
2021-03-13 18:51:12 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_new_york_islanders is taking over 10 seconds
2021-03-13 18:51:15 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_calgary_flames is taking over 10 seconds
2021-03-13 18:51:18 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_tampa_bay_lightning is taking over 10 seconds
2021-03-13 18:51:23 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_pittsburgh_penguins is taking over 10 seconds
2021-03-13 19:35:39 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_new_york_islanders is taking over 10 seconds
2021-03-13 19:35:39 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_pittsburgh_penguins is taking over 10 seconds
2021-03-13 19:35:40 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_calgary_flames is taking over 10 seconds
2021-03-13 19:35:40 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_tampa_bay_lightning is taking over 10 seconds
2021-03-13 19:35:49 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds
2021-03-13 19:35:51 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_pittsburgh_penguins is taking over 10 seconds
2021-03-13 19:35:55 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_new_york_islanders is taking over 10 seconds
2021-03-13 20:08:39 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_tampa_bay_lightning is taking over 10 seconds
2021-03-13 20:08:42 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_calgary_flames is taking over 10 seconds
2021-03-13 20:08:43 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds
2021-03-13 20:08:45 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_new_york_islanders is taking over 10 seconds
2021-03-13 20:08:45 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_pittsburgh_penguins is taking over 10 seconds
2021-03-13 20:09:10 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds
2021-03-13 20:09:15 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_tampa_bay_lightning is taking over 10 seconds
2021-03-13 20:09:21 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_pittsburgh_penguins is taking over 10 seconds
2021-03-13 20:09:29 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_calgary_flames is taking over 10 seconds
2021-03-13 21:12:11 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_vegas_golden_knights is taking over 10 seconds

The log entries aren’t unusual to happen sometimes.

Thanks for this integration, it is fantastic!

If you use Node-RED, I’ve been working on one recently:

1 Like

My NHL sensor has worked fine the last two nights, but I’m only tracking one team.

Thanks. It is weird. The Los Angeles and Colorado game just ended and the sensors worked just fine. Guess I need to find some debug to turn on.

Thanks to dennyreiter for the amazing node-red hockey stats!. Finally have it working. Now off to get the Goal horn working but somehow have to incorporate my Alexa devices first!

So I have an idea for how to create an automation that will fire when your team wins, however seem to be doing something wrong in my conditions. Any insights into what’s wrong with my conditions?

- id: '1615076248901'
  alias: 'NHL: Game over! Bruins win!'
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.nhl_sensor
    to: Game Over
    attribute: game_state
    from: In Progress - Critical
  condition:
  - condition: or
    conditions:
    - condition: and
      conditions:
      - condition: template
        value_template: '{{ (state(''sensor.home_team'')|int) > (state(''sensor.away_team'')|int)
          }}'
      - condition: template
        value_template: '{{ is_state_attr(''sensor.nhl'', ''home_id'', 6) }}'
    - condition: and
      conditions:
      - condition: template
        value_template: '{{ (state(''sensor.away_team'')|int) > (state(''sensor.home_team'')|int)
          }}'
      - condition: template
        value_template: '{{ is_state_attr(''sensor.nhl'', ''away_id'', 6) }}'
  action:
  - service: media_player.volume_set
    data:
      volume_level: 0.3
    entity_id: media_player.downstairs
  - service: media_player.play_media
    data:
      media_content_id: media-source://media_source/local/dirtywater.mp3
      media_content_type: music
    entity_id: media_player.downstairs
  initial_state: true
  mode: single

You’ve got double single quotes around your sensors and attributes rather than a single double quote. also it’s states('sensor.home_team') not state(. and you don’t need the enclosing parentheses around the states statement. and lastly, a change in a recent version means all templates render as the base sensor’s type, so in this case, the template will be of type number, so there’s no need to type cast to an int. just do a straight compare.

example:

value_template: '{{ (state(''sensor.home_team'')|int) > (state(''sensor.away_team'')|int)
          }}'

should be:

value_template: "{{ states('sensor.home_team') > states('sensor.away_team') }}"

otherwise, the rest of your logic of ors and ands looks correct. just fix the single vs double quotes and change state to states(and everything should be ok.

Thanks!!! Fixing this up and will report back…