NFL game sensor (scores, possession, etc)

2021 edit: This has now been upgraded to a custom component, so I’m removing the unworking binary sensor I’d posted earlier.

I wanted to be able to set some light scenes around my house as a subtle reminder that my NFL team’s game had started, so I built this custom component. After some folks in this thread found a new feed, it was easy to add all the details about a game.

Please see installation instructions in the github README.

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

Some attributes are always available, while others are null until the sensor goes into a specific state. See the README for details.

Find a Bug?

If you have found a bug in the component, please don’t hesitate to post here (and tag me) or to file an issue here: https://github.com/zacs/ha-nfl/issues/new.

Default sensor:

@D34DC3N73R has also built a wonderful lovelace card showing the details for a game in a very nice made-for-TV type of way. The card relies on the custom component above.

Example:

13 Likes

Is there a way to make this work for the NBA and MLB as well?

OFF TOPIC- sort of.

Where did you get the resource information? I have a medical device that I would like to monitor in Home Assistant that shares data over IP with my wife’s phone and an Alexa skill. Basically, instead of depending on an alarm on my phone that I sometimes sleep through, I want Home Assistant to turn on the light in the room.

How should I structure the question to ask the maker of the equipment?

@kingozone it should be possible, I can take a look and post a different binary sensor if possible.

@stevemann ask your device make if they offer an API, that would be the right way to go about it. If it’s sinple enough I’d be happy to put something super basic (and likely breaking-in-the-future) together.

That would be awesome!

Hey, apologies for not getting back to you sooner. I just wrote this binary sensor to check and see if an MLB team is playing. Can’t really check NBA now as it’s the off-season. Obviously replace “Braves” with whichever team you care about. The specific names can be seen in the URL for the resource in case you need to figure that out.

- platform: rest
  resource: "https://statsapi.mlb.com/api/v1/schedule?sportId=1&gameTypes=R&hydrate=team,linescore,flags,liveLookin,review,game(content(summary,media(epg)),tickets),seriesStatus(useOverride=true),broadcasts(all)&useLatestGames=false&language=en&leagueId=103,104"
  name: Braves Playing
  value_template: >
    {% for game in value_json.dates[0].games %}
      {% if game.teams.away.team.teamName == 'Braves' or game.teams.home.team.teamName == 'Braves' %}
        {% if game.status.abstractGameState == 'Live' %}
          True
        {% else %}
          False
        {% endif %}
      {% endif %}
    {% endfor %}
  scan_interval: 120
2 Likes

Hi zacs. This looks like almost exactly what myself and a lot of folks on reddit have been wanting to do, just unsure how to get real-time updated score info. I’d love to adapt this to flash a quick 10-15 second automation every time a given team scores. Did you have to check on that page to get those values during a game? I’m a complete n00b unfortunately, but I can’t find reference to those values anywhere.

Yah, I just took a couple snapshots at various times on Sundays to get a complete picture of possible states. Actually ended up with a few edge cases when games went to OT, ended in a tie, or got delayed due to weather! I lurk on the HA subreddit, so feel free to point me to a thread there to respond, or ask here. The feed is 100% undoc’d but I should be able to fill in any blanks you have.

Hi zacs. I did a bunch of searching to see if anyone had done it. A lot of what I found were older threads that were archived, like this one:

Or this one:

There were a few with no answers. Some also about MLB or NHL, which seems easily accomplished by https://goalfeed.ca/home-assistant which unfortunatley doesn’t work for the NFL.

There’s this thread from the hue subreddit where someone mentioned using Tasker and scoring notifications from a sports app… But I also know that notification timeliness is an issue with higher versions of Android. The NFL.(com) ticker is quite up-to-date, so it seems like the perfect solution.

Yah, it should be fairly straightforward to create a sensor with both a primary state (like inprogress) and then a bunch of properties for things like the score, time left, etc. Then you could write an automation to do something whenever the score property changes.

I want to have an automation that does something when ever my team scores how would I do that

You would change the value_template to find the score of your team instead of the existence of a game, and then trigger an automation off of any changes to that. Couldn’t tell you off-hand since there are no games going on right now to look at, though obviously tomorrow that’ll be different :). If you can remember to copy the JSON and paste it back here, I can tell you what the value_template should be.

Thanks I got it working before super bowl but didn’t do any good my team lost anyway. But now it’s time for NBA basketball

Any new urls feeds.nfl.com no longer works has been deprecated

I took a brief look at nfl.com and they are certainly trying hard to obfuscate it now. It’s possible they’re generating rotating URLs for their web page, or other obscurity-based ways to keep folks from accessing the data. I will dig a little bit (need to turn my lights green and blue for Hawks games after all!) but digging for 15 minutes didn’t yield anything yet.

Thanks zacs for looking into this

Could The Sports DB an option?

https://www.thesportsdb.com/

I hadn’t heard of this service, thanks! I can probably pivot to use this instead for sure. It looks like the right feed (for NFL) is at https://www.thesportsdb.com/api/v1/json/1/eventsnextleague.php?id=4391, though I will need to paw through it to figure out which attributes mean “the game is currently active.”

Also, given that this feed is a flat bunch of properties, I will be able to shove all of the properties into the binary_sensor as attributes (things like score, etc). I will try and test tonight during MNF.

1 Like

Have you checked out http://static.nfl.com/liveupdate/scores/scores.json ?

The schema has changed and I am having some trouble parsing out the data I need. Do you think you can have a look?

1 Like

Nice, that’s what I need. Where’d you find reference to it? I only sniffed the main nfl.com landing page but didn’t see that file get loaded! Will update my template today.