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

+1 to show the league logo as the entity picture!

Has anyone been able to get it working with multiple teams since the update? I have one team working fine, but before i could track multiple teams. My config is below. Thanks in advance

    #NHL Sensor#
sensor:
  - platform: nhl_api
    name: nhl_sensor_mtl
    team_id: 8

  - platform: nhl_api
    name: nhl_sensor_tor
    team_id: 10

template:

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

  - sensor:
      - unique_id: mtl_home_team
        name: >
          {{state_attr('sensor.nhl_sensor_mtl','home_name')}}
        state: >
          {{state_attr('sensor.nhl_sensor_mtl','home_score')}}
        picture: >
          {{state_attr('sensor.nhl_sensor_mtl','home_logo')}}

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

  - sensor:
      - unique_id: tor_home_team
        name: >
          {{state_attr('sensor.nhl_sensor_tor','home_name')}}
        state: >
          {{state_attr('sensor.nhl_sensor_tor','home_score')}}
        picture: >
          {{state_attr('sensor.nhl_sensor_tor','home_logo')}}

Whatā€™s not working? Do the 2 sensors render?

Try this:

template:
  - sensor:
    - unique_id: away_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("away_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("away_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("away_logo", "") }}'
  - sensor:
    - unique_id: home_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("home_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("home_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("home_logo", "") }}'

Sorry shouldā€™ve been more clear. The trackers for montreal work great but the toronto ones do not show up as entities. Ill give your solution a try

@michaeldooley97 I just set mine up for two teams today with the Kings and Ducks using your code and it seems to be working fine for both teams. For whatever reason, my instance isnā€™t liking @jayblackedoutā€™s template code (99% sure itā€™s a user error). But both teams and the respective visitors for the scheduled games this week are showing up fine.

Good to know, thanks for testing! I might just start over and set it up again

1 Like

@michaeldooley97 absolutely! Itā€™s worked great for both games (Ducks and Kings) the last two nights for how you have it formatted. The challenge, like what youā€™ve already raised, is that when it clears from the previous game it sets the sensors to ā€œunknownā€ rather than ā€˜0ā€™ or a ā€˜-ā€™. So, those I set the state manually for today because Iā€™m in and out of it. Iā€™m not too experienced with templates, so Iā€™m using this to play around and learn it as well.

I also added ā€œPeriodā€ and ā€œTime Remainingā€ (which is for the period, not the whole game) to the card/sensor line up:

template:
  - sensor:
    - unique_id: 'ducks_cur_period'
      state: >
        {{state_attr('sensor.nhl_ducks', 'current_period')}}
    - unique_id: 'ducks_time_remain'
      state: >
        {{state_attr('sensor.nhl_ducks','time_remaining')}}

Notes for reference on the card:
o Period icon is: mdi:hockey-puck and the timer is mdi:timer-outline to save people time in looking for them. I set those on the card itself since those donā€™t need to change.

o The time and period will automatically set (what you see on my Ducks card) when it recognized that the game is today and then update live when the game is going so that if I check it, itā€™ll reflect whatā€™s going on.

o For my Kings card, I entered the ā€˜-ā€™ for time/period and the ā€˜0ā€™ for score manually in Developer Tools just to clean it up as I was bouncing in and out of it earlier, otherwise it reads ā€œunknownā€ for all four. Iā€™ll play with it later to see how to change the default to the ā€˜-ā€™ (time/period) and ā€˜0ā€™ (team scores) when the game isnā€™t going.

Hope that helps!

Added: just for clarity and for whoever sees this later, the Ducks are playing the Wild on 10/15/21 and then the Kings are playing them on 10/16/21. Just to avoid confusion, I didnā€™t do anything special, thatā€™s @jayblackedoutā€™s integration that pulled that data automatically, so that side is definitely functioning right.

To get rid of the ā€œunknownā€ state in your template sensors, change:

state: >
        {{state_attr('sensor.nhl_ducks', 'current_period')}}

to

state: >
        {{ states.sensor.nhl_ducks.attributes.get("current_period", "-") }}

Replicate for your other template sensors using the correct attribute and substitute the dash for whatever you want to use as a default state instead of unknown.

@jayblackedout, thanks. I tried that code for setting the defaults when I first set it up and again today with your example. It returns the sensor output on the card as ā€œunavailableā€.

Not sure why that isā€¦ Well at least itā€™s somewhat working the way you want.

I am encountering an issue where the sensor stops updating its attributes. It will say itā€™s end of the first, but itā€™s actually already 3/4 into the second period. The home assistant log has warnings about the sensor taking over 10 seconds, so Iā€™m not sure if itā€™s just become hung and stopped updating or if the sensor update would actually timeout and be retried successfully without a log entry. Restarting home assistant will cause the sensor to be updated correctly.

2021-10-18 20:36:50 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.nhl_mtl is taking over 10 seconds

I just set this up the other day. On my setup the logos stopped showing. My team is playing tonight so Iā€™ll check back and see if everything else is still in order.

Yea I donā€™t think itā€™s working correctly. Iā€™ll have to do some digging but the main card just says a game is in progress but no score or time and no logo. Iā€™m not sure what is supposed to be showing and will look above to check other screenshots when Iā€™m off mobile.

Check out the GitHub repository linked in the original post.

What am I checking out? No open issues and the last update was 14 days ago. Which means having installed it only a couple days ago I must be on current version.

You mentioned you were looking for screenshots. I have a section on the frontend with template examples.

Ah cool Iā€™ll look thx

Would be cool to get some other events like penalties and be able to track if your team is on the PK or PP.

Agreed. I would also love this and some more enhancements.
Iā€™d love for ALL sports to have something.

Iā€™ll see what the NHLā€™s API offers and put it on the backlog. Iā€™m limiting the scope of my project to the NHL though. Iā€™m only one person and it is already difficult to find time to update this component.

1 Like