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

Great! Glad you like it.

Thatā€™s what Iā€™m doing now. Just trying to dial in a sweet spot. I know I canā€™t get it 100% accurate every time as the delay is always going to be different with the latency from the streams but I can probably get it close enough. All in all though this is a great component and Iā€™ve managed to do some neat things with the information provided by it.

1 Like

Funny, i have the opposite problem. My Direct TV broadcast is ahead of the API by around 4-5 seconds.

The 4-5 seconds probably accounts for the time it takes for the NHL to update the stats API. Nothing really I can do for you there!

1 Like

Makes sense, unless you can make a button that makes the Stars score on commandā€¦ :slight_smile:

2 Likes

With that line up, if Montgomery canā€™t do it, I donā€™t think Iā€™ll be able toā€¦

Came across this after doing some in depth searching for NFL and NCAA. All I can say is thank you for this add-on. I have begun implementing it into HA and will be adding my lights this week.
Keep up the good work. :+1: :+1:

1 Like

I would be very appreciative if you could share your lights configuration. I have been struggling getting this to work for hours. Strangely enough I have some lights flashing, all tasmota based firmware, including 2 x Teckin SB50 light bulbs - yet one light bulb flashes at the speed I desire, exactly 2x as much as the other one. The light is part of a light group I am commanding 1 entity only!

Thanks!

Tollbringer

I am almost there! I got rate limited by Github- I followed the docs to check my ratings limit apparently I am unauthenticated even after doing basic authentication,I only get 60/h requests. How do I authenticate to get the 5000/hr?

I set up according the git hub repro with the exception of doing TEAMNAME_ in front of the sensor names as I would like to have multiple teams do some custom announcements

The automatons never fire even though they come back as ā€œTrueā€ in the template any help would be greatly appreciated

configuration.yaml

sensor:
  - platform: nhl_api
    team_id: 10
    name: Leafs NHL Sensor
  - platform: template
    sensors:
      leafs_away_team:
        friendly_name_template: '{{ states.sensor.leafs_nhl_sensor.attributes.away_name }}'
        value_template: '{{ states.sensor.leafs_nhl_sensor.attributes.away_score }}'
        entity_picture_template: '{{ states.sensor.leafs_nhl_sensor.attributes.away_logo }}'
      leafs_home_team:
        friendly_name_template: '{{ states.sensor.leafs_nhl_sensor.attributes.home_name }}'
        value_template: '{{ states.sensor.leafs_nhl_sensor.attributes.home_score }}'
        entity_picture_template: '{{ states.sensor.leafs_nhl_sensor.attributes.home_logo }}'
input_number:
  leafs_away_score:
    min: 0
    max: 100
    step: 1
  leafs_home_score:
    min: 0
    max: 100
    step: 1

automations.yaml

- id: leafs_home_score_announce
  alias: leafs_home_score_announce
  initial_state: true
  trigger:
  - platform: template
    value_template: "{{ states.sensor.leafs_home_team.state  | int > states('numeric_input.leafs_home_score') | int }}"
  action:
  - service: input_number.increment
    entity_id: numeric_input.leafs_home_score
  - service: notify.alexa_media
    data:
      target: 
        - "Livingroom Echo"
        - "Tim's Echo Show"
      message: "{{ state_attr( 'sensor.leafs_home_team', 'friendly_name') }} score!"
      data: 
        type: "tts"    

so I ran into two issues last night (Hallelujah hockey is back!). At the start of the game, my game stream (NBC Sports app on AppleTV) was actually ahead by 2-3 seconds, then in sync towards the middle of the first period, then up to 60 seconds behind the API alert by the end of the game. I donā€™t know if it was a constant time drift or if it fluctuated in the middle of the game (no goals scored in the second and most of the third period).

The second issue is the API incorrectly updated with another goal for my team within seconds of the previous goal, though that did not actually happen and was corrected at the end of the game. When the game went final, they removed the additional goal which triggered my goal horn automation. The quick fix is to change my automation trigger to be based on my team sensor goal total and have a condition that looks at the trigger state to is greater than the trigger state from. Instead of using the goal event for my tracked team. However, I then have to look at both the home and away team goal sensors (unless thereā€™s a way to look at just goals for my tracked team).

One other addition to my goal horn automation Iā€™d like to make (but is currently a separate automation) is when the game goes final, and my team sensor goal total is greater than the opponent team goal sensor, sound the goal horn. I just need to figure out how to roll this into the standard goal horn automation.

Praise the hockey gods for the start of the season!

There are multiple factors that can affect syncing. The NHLā€™s update frequency itself, the requests module, your internet connection (although that shouldnā€™t be an issue unless youā€™re running on dial-in from 2001) and obviously, my component. Iā€™ll look into it on my end but no promises.

Your second issue sounds like it originated from the NHLā€™s API data, not my component. They tag each goal with a unique event ID and my component will not fire the goal_event twice for the same ID. It looks like they tagged the same event twice with different IDs which caused the issue. Iā€™ll look at the data if you can tell me which of the 3 games you are referring to.

As for an event firing at the end of the game, thatā€™s an interesting feature I will look into adding.

Thanks for using the component and especially for the feedback!

Honestly, I suspect the time drift/sync is occurring on the AppleTV and in the app on the stream. A family member was watching the same game, but on live broadcast over cable in a different state and by the end of the game they were texting me spoilers 30-60 seconds before I saw them happen. And for that, thereā€™s nothing you or even I, can do about that.

I was watching the Blackhawks/Lightning game. In the late third period, the Blackhawks scored (finally), but within 60 seconds after that goal, the API updated to say they scored twice (and now I know ESPN uses the NHL API because I got a notification from the ESPN app too). My automation defaults to single mode, and I donā€™t see a warning in my log for an additional trigger while the automation was already running. This tells me it was the same ā€œeventā€ just incorrect data. But when they corrected the data, they submitted it as a new event which triggered my automation even though it was removing a goal.

The problem Iā€™m running into with triggering based on only positive goals or if my team wins is I have to know if my team is home or away. Unless thereā€™s a way (or sensor) to look at goals per team ID regardless if they are home or away.

I love that this is out there, but Iā€™m having issues with it triggering in my HA instance. So far all I want to do is trigger it as a goal light. If I trigger that automation alone (Input Boolean into Node Red to trigger and WLED strip) it works, but I canā€™t seem to get the data across. This is code in my automations.yaml to trigger the input boolean. Any thoughts?

- alias: 'Habs Goal'
  trigger:
    platform: event
    event_type: nhl_goal
    event_data:
      team_id: "8"
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.habs_goal

Did a full uninstall and reinstall and itā€™s working now. Only issue is it triggers about 45 second after the goal. Probably just the delay from NHL updating their side.

It shouldnā€™t take that long for it to update. Did you define a custom scan_interval in your config or is it defaulting to the 5 second scan? Also, what are you watching on?

I did set the default scan to 1. Watching it on Bell ExpressVu satellite in Canada.

Yeah, you should be getting a near instantaneous feed via satellite, I think. You definitely will see some delay while the NHL updates the data but Iā€™m wondering if Node Red is causing some additional delay while it works through your automation logic.

Yeah I guess that is possible. Just got to figure a way to write in the automation to load the specific preset. Iā€™ll give that a go. I know my other automations that use an input boolean to toggle a flow in node red are pretty much instantaneous. Iā€™ll try it to eliminate it though.

I built my instance based on the GitHub page. Alexa announces the first goal per team but none of the subsequent goals. Any idea what I should be looking for in the code?