Skip to content

Instantly share code, notes, and snippets.

@jlongman
Created January 12, 2025 21:06
Show Gist options
  • Save jlongman/fe1a276a7c087a8962abcb5334803cdb to your computer and use it in GitHub Desktop.
Save jlongman/fe1a276a7c087a8962abcb5334803cdb to your computer and use it in GitHub Desktop.
Team Tracker NHL Intermission Timers
---
alias: Canadiens 1st Intermission Timer Trigger
description: "Trigger the Canadiens Timer when the 1st period ends"
triggers:
- trigger: template
value_template: >-
{{ is_state_attr('sensor.team_tracker_canadiens', 'clock', 'End of 1st') }}
conditions: []
actions:
- action: timer.start
metadata: {}
data:
duration: "00:17:30"
target:
entity_id: timer.canadiens_timer
mode: single
---
alias: Canadiens 2nd Intermission Timer Trigger
description: "Trigger the Canadiens Timer when the 1st period ends"
triggers:
- trigger: template
value_template: >-
{{ is_state_attr('sensor.team_tracker_canadiens', 'clock', 'End of 2nd') }}
conditions: []
actions:
- action: timer.start
metadata: {}
data:
duration: "00:17:30"
target:
entity_id: timer.canadiens_timer
mode: single
type: entities
entities:
- entity: sensor.team_tracker_canadiens
- entity: timer.canadiens_timer
secondary_info: last-changed
- entity: timer.senators_timer
secondary_info: last-changed
- entity: sensor.team_tracker_senators
alias: Canadiens Overtime Timer Trigger
description: "Trigger the Canadiens Timer when the 3rd period ends and the score is tied"
triggers:
- trigger: template
value_template: >-
{% set tracker = 'sensor.team_tracker_canadiens' %}
{{ is_state_attr(tracker, 'clock', 'End of 3rd') and state_attr(tracker, 'team_score') != state_attr(tracker, 'opponent_score') }}
conditions: []
actions:
- action: timer.start
metadata: {}
data:
duration: "00:1:30"
target:
entity_id: timer.canadiens_timer
mode: single

NHL Team Tracker Intermission Timer Trigger

This detects an NHL hockey intermission using the Team Tracker/ESPN components. The example starts a Timer which can be used to expose time until the next period starts. Besides just showing time until the period starts, when the timer expires automations can be triggered.

image

Tip

I've found setting the timer between the 1st to 3rd period to 17:30 - 17 minutes and 30 seconds - works pretty well with the inherent delay in the original API, the inherent refresh delay of Home Assistant and the latency with my television channel. You may need to tune this to your use case.

Detecting intermission start is done by using the clock field, which says End of 1st for 1st intermission, End of 2nd for 2nd intermission and when the score is tied and End of 3rd it can start an intermission timer.

Why

Years ago I'd built an Arduino box for a local bar to get the audio back when the intermissions were done by sending IR codes to the amp. The box would have to listen for a signal from a human using a special purpose IR remote to start the intermission. During intermission the audio would switch to music and the bar staff would get too busy to switch it back to the game, the box ensured the music switched back to game audio on time, or close enough. There was even a 90s button for commercials. None of this would be necessary with this automation, but it wasn't reliably avialable at the time.

With this we could switch to music or mute the non-game audio. We could also use the timer to resume the audio but I might use the clock advancing as an alternative unmute - maybe both?

Requirements

Note the team ID can be found by nagivating to the ESPN site and visiting your team's stats, e.g. The Oilers are edm which is taken from after name in their team URL: https://www.espn.com/nhl/team/_/name/edm/edmonton-oilers

Install

You'll create three automations, one for each (regular season) intermission.

Note

Post-season multiple overtimes is not yet supported. Support would be trivial but we'd need the correct trigger string.

  • configure the team you're interested in tracking
    • I recommend re/naming it appropriately for the team to keep multiple teams distinct
  • create a timer for the team intermissions
    • I recommend naming the timer appropriately as well
  • go to automations and create a new automation
  • change to YAML mode and paste the relevant code below
  • you can switch back to the visual editor after

Repeat configuring automations for the 2nd and overtime intermissions.

Next steps

  • multiple overtime support for the post-season
  • using templates to reduce the automation to a single, more complex template
    • or not

Useful additions

@jlongman
Copy link
Author

If you use an Awtrix display I've also forked and then integrated this into the https://github.com/jlongman/Homeassistant_blueprints/blob/main/Awtrix%20NFL%20Team%20Scoreboard/awtrix_nfl_team_scoreboard.yaml - I should rename that to "sports team scoreboard.". You still need to create the timer separately.

I've also got code to create an Awtrix app which shows an intermission timer but from what I understand of blueprints, you need 2 separate blueprints, a separate automation (or blueprint if it makes sense to package that way) and the separate timer from above to get it going...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment