Giter VIP home page Giter VIP logo

ha-nfl's Introduction

NFL game data in Home Assistant

This integration fetches data for an NFL team's current/future game, and creates a sensor with attributes for the details of the game.

You can find examples of interesting automations in the wiki (please add your own examples!). There is also a great custom card that leverages this sensor, built by @D34DC3N73R.

The integration is a shameless fork of the excellent NWS alerts custom component by @finity69x2.Thank you for the starting place!

Sensor Data

State

The sensor is pretty simple: the main state is PRE, IN, POST, BYE or NOT_FOUND, but there are attributes for pretty much all aspects of the game, when available. State definitions are as you'd expect:

  • PRE: The game is in pre-game state. This happens on the first day of the game week, which seems to be Tuesday evenings around midnight Eastern time (once all the games through the Monday Night Football game are wrapped up).
  • IN: The game is in progress.
  • POST: The game has completed.
  • BYE: Your given team has a bye week this week. Note that attributes available are limited in this case (only abreviation, name, logo, and last updated time will be available).
  • NOT_FOUND: There is no game found for your team, nor is there a bye. This should only happen at the end of the season, and once your team is eliminated from postseason play.

Attributes

The attributes available will change based on the sensor's state, a small number are always available (team abbreviation, team name, and logo), but otherwise the attributes only populate when in the current state. The table below lists which attributes are available in which states.

Name Value Relevant States
date Date and time of the game PRE IN POST
kickoff_in Human-readable string for how far away the game is (eg. "in 30 minutes" or "tomorrow") PRE IN POST
quarter The current quarter of gameplay IN
clock The clock value within the quarter (should never be higher than 15:00) IN
venue The name of the stadium where the game is being played (eg. "Arrowhead Stadium") PRE IN POST
location The city and state where the game is being played (eg. "Pittsburgh, PA") PRE IN POST
tv_network The TV network where you can watch the game (eg. "NBC" or "NFL"). Note that if there is a national feed, it will be listed here, otherwise the local affiliate will be listed. PRE IN POST
odds The betting odds for the game (eg. "PIT -5.0") PRE
overunder The over/under betting line for the total points scored in the game (eg. "42.5"). PRE
possession The ID of the team in possession of the ball. This will correlate to team_id or opponent_id below. Note that this value will be null in between posessions (after a score, etc). IN
last_play Sentence describing the most recent play, usually including the participants from both offense and defense, and the resulting yards. Note this can be null on posession changes or in between quarters. IN
down_distance_text String for the down and yards to go (eg. "2nd and 7"). IN
team_abbr The abbreviation for your team (ie. SEA for the Seahawks). PRE IN POST BYE
team_id A numeric ID for your team, used to match possession above. PRE IN POST
team_name Your team's name (eg. "Seahawks"). Note this does not include the city name. PRE IN POST BYE
team_record Your team's current record (eg. "2-3"). PRE IN POST
team_homeaway Your team's home/away status. Either home or away. PRE IN POST
team_logo A URL for a 500px wide PNG logo for the team. PRE IN POST BYE
team_colors An array with two hex colors. The first is your team's primary color, and the second is their secondary color. Unless you're the Browns, in which case they are the same. PRE IN POST
team_score Your team's score. An integer. IN POST
team_win_probability The real-time chance your team has to win, according to ESPN. A percentage, but presented as a float. Note that this value can become null in between posession changes. IN
team_timeouts The number of remaining timeouts your team has. PRE IN POST
opponent_abbr The abbreviation for your opponent (ie. SEA for the Seahawks). PRE IN POST BYE
opponent_id A numeric ID for your opponent, used to match possession above. PRE IN POST
opponent_name Your opponent's name (eg. "Seahawks"). Note this does not include the city name. PRE IN POST BYE
opponent_record Your opponent's current record (eg. "2-3"). PRE IN POST
opponent_homeaway Your opponent's home/away status. Either home or away. PRE IN POST
opponent_logo A URL for a 500px wide PNG logo for the opponent. PRE IN POST BYE
opponent_colors An array with two hex colors. The first is your opponent's primary color, and the second is their secondary color. PRE IN POST
opponent_score Your opponent's score. An integer. IN POST
opponent_win_probability The real-time chance your opponent has to win, according to ESPN. A percentage, but presented as a float. Note that this value can become null in between posession changes. IN
opponent_timeouts The number of remaining timeouts your opponent has. PRE IN POST
last_update A timestamp for the last time data was fetched for the game. If you watch this in real-time, you should notice it updating every 10 minutes, except for during the game (and for the ~20 minutes pre-game) when it updates every 5 seconds. PRE IN POST BYE

Installation

Manually

Clone or download this repository and copy the "nfl" directory to your "custom_components" directory in your config directory

<config directory>/custom_components/nfl/...

HACS

  1. Open the HACS section of Home Assistant.
  2. Click the "..." button in the top right corner and select "Custom Repositories."
  3. In the window that opens paste this Github URL.
  4. In the window that opens when you select it click om "Install This Repository in HACS"

Configuration

You'll need to know your team ID, which is a 2- or 3-letter acronym (eg. "SEA" for Seattle or "NE" for New England). You can find yours at https://espn.com/nfl in the top scores UI.

Via the "Configuration->Integrations" section of the Home Assistant UI

Look for the integration labeled "NFL" and enter your team's acronym in the UI prompt. You can also enter a friendly name. If you keep the default, your sensor will be sensor.nfl, otherwise it will be sensor.friendly_name_you_picked.

Manually in your configuration.yaml file

To create a sensor instance add the following configuration to your sensor definitions using the team_id found above:

- platform: nfl
  team_id: 'SEA'

After you restart Home Assistant then you should have a new sensor called sensor.nfl in your system.

You can overide the sensor default name (sensor.nfl) to one of your choosing by setting the name option:

- platform: nfl
  team_id: 'SEA'
  name: Seahawks

Using the configuration example above the sensor will then be called "sensor.seahawks".

ha-nfl's People

Contributors

conorsham avatar d34dc3n73r avatar eracknaphobia avatar finity69x2 avatar firstof9 avatar gonzotek avatar zacs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ha-nfl's Issues

Kickoff In time is wrong

The day of the week and time game starts is correct .. however on the card in the bottom left.. it says kick off in two days. IT should read 3. I have this integration with three different cards. Only one of them is saying "3 Days" which is correct. Any advice on how to fix this please.

Super Bowl support?

Hi :)

Just stumbled across your integration and installed it directly. Unfortunately the entity stays empty. Is this because of the Super Bowl? I'm fan of the Rams so I'd love to see the upcoming Super Bowl on my HA.

Am I to stupid or are you just don't grab the data for the sb?

Cheers and thank you in advance,
Sven

Opponent Colors

It looks like the 2/4 commit started using [team_index] instead of [oppo_index] to set the opponent's colors.

Pro Bowl AFC/NFC teams unavailable.

I left a message in the Home Assistant forums, but thought it might help to also put an issue in here with the JSON.
I tried both NFC and AFC as a team acronym, but Home Assistant reports the state of these entities as unavailable. Attached is a capture of the JSON from about 3:30pm today, Thursday 2/3/22.
scoreboard.json.txt

Sensor unavailable during delayed start of 2022 JAX vs LAR Preseason game

I managed to capture the json during the game delay last night. I didn't have the chance to watch live, but this morning all of the sensor data looks as correct as can be (allowing for the expected nulls for the in-game-only attributes).

Anyway, I think the relevant issue with the unavailable during the delay is in the event status fields. The state was "in", but several others showed as delayed:
"status": { "clock": 900.0, "displayClock": "15:00", "period": 1, "type": { "id": "7", "name": "STATUS_DELAYED", "state": "in", "completed": false, "description": "Delayed", "detail": "Delayed", "shortDetail": "Delayed" } }
I think I could probably work out a fix, but I won't have a chance to dig into the code to troubleshoot further for at least a few weeks due to work commitments, so wanted to open the issue in case anyone else ran across this as well and wanted to pick it up.

scoreboard.json.txt

Home Assistant Error loading NFL

Following error in HA. Any thoughts?

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
File "/config/custom_components/nfl/init.py", line 66, in async_setup_entry
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
AttributeError: 'ConfigEntries' object has no attribute 'async_setup_platforms'

Integration Update Speed

Hi there - I have noticed this year that when in PRE status (especially when getting close to the game like under an hour), that the card doesn't seem to update very fast (updates every 20 minutes or so). I have some super sweet lighting automations tied to when the status of the game switches from PRE to IN and today for example, the integration didn't update until about 4 minutes after kick off. Is there anyway to increase the update frequency when it gets close to the start of the game? Thanks!

Error with YAML Configuration with HA 2024.05

HA made a change in HA 2024.05 and config.entry_id is no longer valid in the async_setup_platform() method. This results in an error when using YAML to configure a sensor. I ended up hacking together an ugly workaround. If you have a better way to address it, I'd love to copy it.

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:356
integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 6:17:27 PM (1 occurrences)
Last logged: 6:17:27 PM

Error while setting up nfl platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/nfl/sensor.py", line 40, in async_setup_platform
    config.entry_id = slugify(f"{config.get(CONF_TEAM_ID)}")
    ^^^^^^^^^^^^^^^
AttributeError: 'NodeDictClass' object has no attribute 'entry_id'

error when testing

I wanted to test my living room lights with this blueprint. I got an error, is that normal due to the game is not actually playing yet?
image

Error fetching Browns data: list index out of range

The API apparently changed from last season. I have three NFL integrations installed and they worked very well last season. This week, the Steelers-Seahawks game is showing up on one card, but I’m getting an error for the other 2 integrations I have installed:

Error fetching Ravens data: list index out of range
Error fetching Browns data: list index out of range

There’s no hurry in taking a look, it’s only pre-season 😉
Thanks!

API returning not found

Ever since this monday, my NFL integration is returning 'NOT FOUND' (entity state) and 'null' for all attributes. I installed a fresh integration on a new HA instance and the problem still persisted.

The queries for BAL and HOU both came back with NOT FOUND, so I do not believe this is isolated to a team.

Wrong text

The text in HA hasn't been changed from the weather forked edition.

request

Can team_record attribute be made available in BYE state?

Support for additional sports leagues?

You probably already considered this but I figured it doesn't hurt to ask.

Over the past year or so, I've created a bunch of one-off variations to support several of the different ESPN scoreboard APIs. To simplify the maintenance, I finally combined them all together into a single sensor that should be reasonably easy to maintain. I wanted to see if there was any interest in pulling the changes into this repository.

The changes basically allow a league (i.e. NFL, MLB, MLS, etc.) to be specified when a sensor is configured and changes the API based on it, adds several try/excepts to the retrieval of some values from the JSON string that don't exist for some of the new sports (i.e. timeouts, odds, etc.), and adds some new values to the sensor for some new sports (i.e. balls, strikes, outs, etc.).

The big caveat. I don't have a ton of experience w/ python, creating custom components, or git so I have no idea if my coding style is aligned to expectations or is a mess or what's needed to merge the code even if you wanted to. Feel free to take a look at my fork and see if there is any interest in pulling it in or not If not, no offense taken and I will just continue to pull in your updates as they come in.

Thanks

Integration Requires internet acces to 104.16.125.175 on client.

I have this integration in my home assistant and it works really well. However I have some devices, samsung tablets, that have no access to the internet and connect to home assistant internally only. When I try to access the dashboard that is configured in home assistant, which has internet access, the entity: sensor.nfl reports as "custom element does not exist" on the tablet dashboard. I have validated this by allowing internet access, then working backward by allowing only certain IP addresses.

This IP address is used by Cloudfare, and I have attached a screenshot of the error! Thank you!
Screenshot_20221109-145229_Home Assistant

For discussion: Packages directory and some other contributions

I was thinking of submitting a PR to remove the packages directory...it's a remnant of the NWS alerts component, and doesn't seem to have anything worth salvaging for NFL.

On somewhat a related topic, I was also thinking of contributing the mobile_app notification blueprint I built to the NFL repo as well. Feel like it really belongs here rather than on it's own page.

I also have a few more personal automations I could probably develop into either blueprints or cleaned-up automations for sharing on the wiki. Btw, besides opening an issue - how would I contribute to the wiki? It doesn't seem to be editable if you're not a project collaborator.

(not gonna lie...I'm trying to get to 4 PRs for Hacktoberfest lol...but I do want to make them all count for something!)

London game not working

It seems there is an issue with the game in London this week. I have tried setting my sensor to Vikings and New Orleans and both return errors. Other teams work fine (tried GB and ATL).

Log Details (ERROR)
This error originated from a custom integration.
Logger: custom_components.nfl
Source: helpers/update_coordinator.py:182
Integration: NFL (documentation, issues)
First occurred: 11:05:04 AM (5 occurrences)
Last logged: 11:18:31 AM

Error fetching Vikings data: 'state'

adding several tournaments to team

Following a team in europe they can play in several tournaments. Fx. MNC plays in the Premier league, champions league and the FA cup [local cup tournamant]. it could be nice to add several tournaments fx like"" EPL, CL" so you dont need a card for each tournament your team plays in. :) thanks for the great work on this so far.

Error fetching NFL data: module 'arrow' has no attribute 'FORMAT_W3C'

This error originated from a custom integration.

Logger: custom_components.nfl
Source: helpers/update_coordinator.py:182
Integration: NFL (documentation, issues)
First occurred: 8:10:58 PM (1 occurrences)
Last logged: 8:10:58 PM

Error fetching NFL data: module 'arrow' has no attribute 'FORMAT_W3C'

Home Assistant 2022.9.4
Supervisor 2022.08.6
Operating System 9.0
Frontend 20220907.2 - latest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.