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

Hey @JoeF
Glad you figured it out. I’m not super familiar with node red so couldn’t really help you out. If only using HASS automations then the following should have worked (substituting the action for your own):

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

Hopefully, you’ll have many chances to test it out tonight! (team_id 8 only…). Go Habs Go!

Thank you @jayblackedout really appreciate your work and my 3 year old daughter loves it as well… :wink: …she starts dancing when she hears the horn and the strobe light goes on …

Any chance you have in the works something similar for soccer? I would love to have this work for the European Championship of soccer.
Thanks.

If they provide an API, I would be happy to collaborate on it with someone else. I no longer have the free time I did to be able to fully take on a new project.

Hi,
First of all, thanks for this integration :slight_smile:
I wanted to know, how do you test it before a game while you are developping it, to make sure it will fire the event during a goal.
Thanks

Happy you like it! There’s unfortunately no real way to test it other than in real-time during a game. I can guarantee that the event will fire as soon as the NHL updates their API data with a goal though. You can test the “action” part of your automation by triggering it in the UI.

So it will fire if this is my yaml in a script?


alias: Montreal scores
description: ''
trigger:
  - platform: event
    event_type: nhl_goal
    event_data:
      team_id: '8'

I’ve only used it in an automation, not a script so I can’t tell you for sure if that will work. The YAML is correct for the trigger of an automation though.

Thanks :slight_smile: I appreciate it.

I am not sure what is going on, but over the past couple of weeks, my scores card has gone on the fritz. It was displaying the upcoming first game of the season, but now, I’m getting the game date/time, but the away and home teams are showing as ‘unknown’.
I can see that my sensor has the away_name and home_name correctly attributed. I can also pull the template out of my configuration and put it in the templates page in the developer tools and see that it reads the team names as expected.

Is this typical for pre-season functionality? I’m confused because it was working fine a couple of weeks ago.

Here the snippet of my configuration:

sensor:
  #nhl sensors
  - platform: nhl_api
    team_id: 54
    name: VGK NHL
#    scan_interval: 1
  - platform: template
    sensors:
      vgk_away_team:
        friendly_name_template: '{{ states.sensor.vgk_nhl.attributes.away_name }}'
        value_template: '{{ states.sensor.vgk_nhl.attributes.away_score }}'
        entity_picture_template: '{{ states.sensor.vgk_nhl.attributes.away_logo }}'
      vgk_home_team:
        friendly_name_template: '{{ states.sensor.vgk_nhl.attributes.home_name }}'
        value_template: '{{ states.sensor.vgk_nhl.attributes.home_score }}'
        entity_picture_template: '{{ states.sensor.vgk_nhl.attributes.home_logo }}'

I had this issue too. It has to do with the template sensors being rendered or initialized before the NHL integration is initialized. It also has to do with the way the template gathers its data. If you go to the configuration panel from the frontend and under server controls/general you reload the template section you’ll see the sensors update and show correctly, but the next time HA gets restarted you have the same issue. The fix is to change the templates to use the other way of getting the state of an object instead of direct. The other way cleanly handles if a state is invalid or unknown. Instead of using {{ states.sensor.blah.attribute.state }} it gets changed to {{ state_attr('sensor.blah', 'attribute') }}

I had a hunch that was what was causing it. I was unaware of the other method of checking the attribute. This worked like a charm! Thank you!

Has anyone transitioned this from the legacy template to new template config? friendly_name_template is no longer accepted so I’m not sure what to do with those lines.

There’s a discussion here. I haven’t tried the solution mentioned in the thread but maybe it can point you in the right direction.

in the migration you can simply use the new name: field, and keep the old template there.

so

sensor:

  - platform: template
    sensors:
      vgk_away_team:
        friendly_name_template: '{{ states.sensor.vgk_nhl.attributes.away_name }}'
        value_template: '{{ states.sensor.vgk_nhl.attributes.away_score }}'
        entity_picture_template: '{{ states.sensor.vgk_nhl.attributes.away_logo }}'

will become:

template:

  - sensor:
      - unique_id: vgk_away_team
        name: '{{ states.sensor.vgk_nhl.attributes.away_name }}'
        state: '{{ states.sensor.vgk_nhl.attributes.away_score }}'
        picture: '{{ states.sensor.vgk_nhl.attributes.away_logo }}'

you’d need to check the object_id of this sensor after reloading, because it will be using the return of the name template, and you’d probably want it to use the ‘old’ object_id, which I’ve set as unique_id

Id recommend wring that as:

template:

  - sensor:
      - unique_id: vgk_away_team
        name: >
          {{state_attr('sensor.vgk_nhl','away_name')}}
        state: >
          {{state_attr('sensor.vgk_nhl','away_score')}}
        picture: >
          {{state_attr('sensor.vgk_nhl','away_logo')}}

because of these considerations

1 Like

Thanks so much for this! I was on the right track but missing the second part of this to fix the name template itself.

Thanks @Mariusthvdb !

I updated the documentation in the repository to address this issue.

Would any of you like the sensor to show the league logo as the entity picture instead of the material design hockey-sticks icon?

Would look something like this:
image

Also, I’d love to collaborate with a frontend dev to create a dedicated scorecard lovelace card for this. Hit me up if interested.

5 Likes

I’d be glad to help test! Thanks for your efforts!

I’d definitely like the NHL logo and I definitely like a Lovelace card but I have zero to contribute.

I created a sensor for the official game time that grabs from the attribute data. Could probably use that for creating a scoreboard.

official_time:
  friendly_name: "Official Time"
  value_template: "{{ state_attr('sensor.nhl_sensor', 'time_remaining') }} - {{ state_attr('sensor.nhl_sensor', 'current_period') }}"
  icon_template: mdi:clock-outline
1 Like