vasqued2 / ha-teamtracker

Home Assistant integration that provides real-time scores in multiple professional (NBA, NFL, NHL, MLB, MLS, and more), college (NCAA), and international (soccer, golf, tennis, mma, racing) sports using ESPN APIs.
168 stars 20 forks source link

Adding sensors automatically #167

Closed PHI34Halladay closed 1 month ago

PHI34Halladay commented 1 month ago

Hi,

I was wondering if there's some kind of automation that adds team sensors from a specific league to my yaml.

For example: There are a lot of college football realignments for the new season with loads of teams changing conferences or the new UEFA Champions League (soccer) will feature different teams every year and so on.

I don't really want to write down the platform, league_id, team_id, name part for every new team every once in a while...

Is there any chance to get those information without manually writing everything down?

vasqued2 commented 1 month ago

Theoretically it's possible but it's probably more bother than it's worth.

There are ESPN APIs that provide a list of teams in a league. You could theoretically use that response to generate the YAML to create the sensors for all of the teams and then paste it into the sensor.yaml file.

To get you started, here is the API that returns the teams in the NFL. I haven't tried but I assume you get other team lists by changing the sport and the league in the URL. It should give you a sense of the data that comes back and what you would have to do to parse it to generate the YAML. If you do, feel free to post it in the Wiki so others can use it.

https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams

The Wiki has an entry that provides links to several pages that provide details to other ESPN APIs.

PHI34Halladay commented 1 month ago

Thanks for the response. I'll stick to the manual updates ahead of each new season ;)

vasqued2 commented 1 month ago

Here is a project has an xsl file that they use to generate the yaml. You might want to look at it to see what they are doing and see if it will work for you.

https://github.com/kbrown01/SportStandingsScores

vasqued2 commented 1 month ago

I was playing around today and ChatGPT did a remarkably good job at generating the YAML.

If you give it the YAML for one team and then ask it to generate the YAML for all of the teams in a league or conference, it does a remarkably good job of doing so. I would try it. It will at least give you a good place to start and you might have to make minor corrections.