Real-Time Sports Scores w/ TeamTracker and TeamTracker-Card (Beta)

No worries mate, Not done anything on the notifications,

But you could probably do something in the automations based on a triggers, i.e
Entity team_mfc
Attribute team score
from 0
to 1
then base an action to create an alert , alexa , sms etc.

then repeat the entity
from 1
to 2

and so on.

probably not the most efficient way but might get you by.

Here’s a sample using one single team. As an automation …

alias: Sport Scoring
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.detroit_lions
    attribute: opponent_score
  - platform: state
    entity_id:
      - sensor.detroit_lions
    attribute: team_score
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_id: air_horn_03
      media_content_type: sound
    target:
      entity_id:
        - media_player.deck_alexa
  - service: notify.alexa_media_deck_alexa
    data:
      message: >
        Score update! {{state_attr('sensor.detroit_lions', 'team_name')}}
        {{state_attr('sensor.detroit_lions','team_score')}}, 
        {{state_attr('sensor.detroit_lions', 'opponent_name')}} 
        {{state_attr('sensor.detroit_lions','opponent_score')}}
mode: single
1 Like

What a legend, all setup ready to test at 12.30, thank you

I listened to mine during the Lions game yesterday and one score was announced well after (at least 3 mins) after it happened and one was announced then changed back then announced again. Not sure anything can be done there.

Yeah mine did that today, like it lost the connection. It went back to 0 - 0 after it was 0 - 1

Right. We are at the mercy of ESPN there. I have an automation for my wife for homeruns in MLB that sometimes just doesn’t get called.

I would suppose I could template this too, not sure … but my full NFL announcement is:

alias: NFL Sport Scoring
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.minnesota_vikings
      - sensor.philadelphia_eagles
      - sensor.washington_commanders
      - sensor.new_york_jets
      - sensor.tampa_bay_buccaneers
      - sensor.houston_texans
      - sensor.tennessee_titans
      - sensor.dallas_cowboys
      - sensor.chicago_bears
      - sensor.los_angeles_rams
      - sensor.carolina_panthers
      - sensor.new_york_giants
      - sensor.kansas_city_chiefs
      - sensor.buffalo_bills
      - sensor.denver_broncos
      - sensor.arizona_cardinals
      - sensor.pittsburg_steelers
      - sensor.atlanta_falcons
      - sensor.san_francisco_49ers
      - sensor.cincinnati_bengals
      - sensor.baltimore_ravens
      - sensor.detroit_lions
      - sensor.miami_dolphins
      - sensor.jacksonville_jaguars
      - sensor.cleveland_browns
      - sensor.los_angeles_chargers
      - sensor.new_orleans_saints
      - sensor.green_bay
      - sensor.indianapolis_colts
      - sensor.new_england_patriots
      - sensor.las_vegas_raiders
      - sensor.seattle_seahawks
    attribute: opponent_score
  - platform: state
    entity_id:
      - sensor.minnesota_vikings
      - sensor.philadelphia_eagles
      - sensor.washington_commanders
      - sensor.new_york_jets
      - sensor.tampa_bay_buccaneers
      - sensor.houston_texans
      - sensor.tennessee_titans
      - sensor.dallas_cowboys
      - sensor.chicago_bears
      - sensor.los_angeles_rams
      - sensor.carolina_panthers
      - sensor.new_york_giants
      - sensor.kansas_city_chiefs
      - sensor.buffalo_bills
      - sensor.denver_broncos
      - sensor.arizona_cardinals
      - sensor.pittsburg_steelers
      - sensor.atlanta_falcons
      - sensor.san_francisco_49ers
      - sensor.cincinnati_bengals
      - sensor.baltimore_ravens
      - sensor.detroit_lions
      - sensor.miami_dolphins
      - sensor.jacksonville_jaguars
      - sensor.cleveland_browns
      - sensor.los_angeles_chargers
      - sensor.new_orleans_saints
      - sensor.green_bay
      - sensor.indianapolis_colts
      - sensor.new_england_patriots
      - sensor.las_vegas_raiders
      - sensor.seattle_seahawks
    attribute: team_score
condition:
  - condition: template
    value_template: "{{ state_attr(trigger.entity_id,'team_homeaway') == 'home'}}"
action:
  - service: media_player.play_media
    data:
      media_content_id: air_horn_03
      media_content_type: sound
    target:
      entity_id:
        - media_player.deck_alexa
  - service: notify.alexa_media_deck_alexa
    data:
      message: >
        Score update! {{state_attr(trigger.entity_id, 'team_name')}}
        {{state_attr(trigger.entity_id,'team_score')}}, 
        {{state_attr(trigger.entity_id, 'opponent_name')}} 
        {{state_attr(trigger.entity_id,'opponent_score')}}
mode: parallel

So when any of the teams score, an announcement happens but the condition will make it trigger only for the home team so you do not get repeated announcements.

And if anyone wants to play … I think this works and could be used to create a “Red Zone” view for NFL:

{% set team = 'sensor.san_francisco_49ers' %}
{% set possession = state_attr(team,'possession') %}
{% set team_id = state_attr(team,'team_id') %}
{% set opponent_id = state_attr(team,'opponent_id') %}
{% set team_abbr = state_attr(team,'team_abbr') %}
{% set opponent_abbr = state_attr(team,'opponent_abbr') %}
{% set down_distance_text = state_attr(team,'down_distance_text') %}
{% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
{% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
{% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
{% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
{{ team }} is the team entity
{{ possession_abbr}} has the ball, {{ down_distance_text }}
{{ possession_abbr }} has ball closer to {{ down_distance_endzone}} endzone at {{ down_distance_yardline }} yard line
{%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
REDZONE!!!!!!
{% else %}
Not in REDZONE
{% endif %}

Just have it iterate all teams and flag Red Zone and isolate a set of cards that would appear in that tab or something. Not sure how I will use it … open to suggestions!

Wow.

Let me play during a game and see what I can come up with.

1 Like

Of course that can be seriously shortened. That was my debug version in developer tab so I could watch during the 9ers game.

Absolutely.

Not sure I’ll get to it the next NFL game. But, I’ll certainly play with it when I can.

It will be fun that the wife won’t understand :rofl:

Example Homerun notification … just in case anyone wants it:

alias: Notify Homerun
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.rangers
    attribute: last_play
condition:
  - condition: and
    conditions:
      - condition: template
        value_template: "{{ 'homered' in trigger.to_state.attributes.last_play }}"
      - condition: template
        value_template: >-
          {{ trigger.to_state.attributes.team_id ==
          trigger.to_state.attributes.possession }}
        enabled: true
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: notify.all_phones
    data:
      title: Run the bases!
      message: >
        {{ trigger.to_state.attributes.team_name }} got a {% if num_of_scores ==
        1 %}homer {% elif num_of_scores == 4 %}grand slam {% else %} {{
        num_of_scores | int }} run homer {% endif %}. {{ trigger.to_state.attributes.last_play }}
mode: queued
variables:
  num_of_scores: >-
    {{ ((((trigger.to_state.attributes.last_play | length) -
    (trigger.to_state.attributes.last_play | replace("scored","") | length)) /
    6) + 1) | int }}

The delay is so she can watch it before getting notified :slight_smile:
You can certainly adjust the delay based on how you watch it. We are watching on MLBtv on ROKU. This works for us. Adjust as necessary.

The ‘Run the bases’ notification is a family joke. Ya gotta run around the living room!!!

- platform: teamtracker
  league_id: XXX
  team_id: CAY
  sport_path: soccer
  league_path: tur.1
  name: caykur-rizespor

you can change team_id and name with your team.

but this only shows your team’s matches in the turkish league.
If your team plays in many leagues at the same time (eg Turkish league, champions league), I don’t know how it will be displayed on the same card.

I was able to get responses in logs that it was grabbing info but it showed No competitions, even thou when I send the same query in postman I get the match info.

2023-08-20 17:43:30.544 DEBUG (MainThread) [custom_components.teamtracker] team_newcarlos: Data returned for 'C. ALCARAZ' from http://site.api.espn.com/apis/site/v2/sports/tennis/atp/scoreboard?lang=en&limit=25
2023-08-20 17:43:30.545 DEBUG (MainThread) [custom_components.teamtracker] team_newcarlos: Num_events '2' from http://site.api.espn.com/apis/site/v2/sports/tennis/atp/scoreboard?lang=en&limit=25
2023-08-20 17:43:30.545 DEBUG (MainThread) [custom_components.teamtracker] team_newcarlos: Data returned for 'C. ALCARAZ' from http://site.api.espn.com/apis/site/v2/sports/tennis/atp/scoreboard?lang=en&limit=25
2023-08-20 17:43:30.545 DEBUG (MainThread) [custom_components.teamtracker] team_newcarlos: Num_events '2' from http://site.api.espn.com/apis/site/v2/sports/tennis/atp/scoreboard?lang=en&limit=25
2023-08-20 17:43:30.546 DEBUG (MainThread) [custom_components.teamtracker.event] team_newcarlos: async_process_event() No competitions for this event: Western & Southern Open
2023-08-20 17:43:30.546 DEBUG (MainThread) [custom_components.teamtracker.event] team_newcarlos: async_process_event() No competitions for this event: Winston-Salem Open
2023-08-20 17:43:30.546 DEBUG (MainThread) [custom_components.teamtracker.event] team_newcarlos: No competitor information 'C. ALCARAZ' returned by API
2023-08-20 17:43:30.550 DEBUG (MainThread) [custom_components.teamtracker] Finished fetching team_newcarlos data in 8.941 seconds (success: True)
"groupings": [
                {
                    "grouping": {
                        "id": "1",
                        "slug": "mens-singles",
                        "displayName": "Mens Singles"
                    },
                    "competitions": [
                        {
                            "id": "136757",
                            "uid": "s:850~l:851~e:718-2023~c:136757",
                            "date": "2023-08-20T20:45Z",
                            "startDate": "2023-08-20T20:45Z",
                            "timeValid": true,
                            "recent": true,
                            "status": {
                                "period": 3,
                                "type": {
                                    "id": "2",
                                    "name": "STATUS_IN_PROGRESS",
                                    "state": "in",
                                    "completed": false,
                                    "description": "In Progress",
                                    "detail": "3rd Set",
                                    "shortDetail": "3rd"
                                }
                            },
                            "venue": {
                                "fullName": "Cincinnati, USA",
                                "court": "Center Court"
                            },
                            "format": {
                                "regulation": {
                                    "periods": 5
                                }
                            },
                            "notes": [
                                {
                                    "text": "(1) Carlos Alcaraz (ESP) leads (2) Novak Djokovic (Srb) 7-5 6-7 (7-9) 5-5",
                                    "type": "event"
                                }
                            ],
                            "geoBroadcasts": [],
                            "broadcasts": [],
                            "competitors": [
                                {
                                    "id": "3782",
                                    "uid": "s:850~l:851~a:3782",
                                    "type": "athlete",
                                    "order": 1,
                                    "homeAway": "home",
                                    "possession": true,
                                    "curatedRank": {
                                        "current": 1
                                    },
                                    "linescores": [
                                        {
                                            "value": 7.0,
                                            "winner": true
                                        },
                                        {
                                            "value": 6.0,
                                            "tiebreak": 7,
                                            "winner": false
                                        },
                                        {
                                            "value": 5.0
                                        }
                                    ],
                                    "athlete": {
                                        "guid": "07843754-8bdf-63b0-5983-24252738169e",
                                        "displayName": "Carlos Alcaraz",
                                        "shortName": "C. Alcaraz",
                                        "fullName": "Carlos Alcaraz",
                                        "flag": {
                                            "href": "https://a.espncdn.com/i/teamlogos/countries/500/esp.png",
                                            "alt": "Spain",
                                            "rel": [
                                                "country-flag"
                                            ]
                                        },

Is there an automation for when I watch the game on my direct tv. when my football team scores a touchdown, my light turn to my team’s color? Can that be automated? But only active when I’m home and I’m actually watching the game?

Here’s a new one for NFL folks that was fun to put together.
I created a template sensor that basically contains all teams in an NFL game in which either team has entered the red zone. The “state” is the count of games in the “Red Zone” (likely not needed but so be it).
The attribute “teams” contains the entity_id’s of all teams in the games in which are considered “Red Zone” … ball at 20 or closer to the opponents end zone:

  - name: NFL Red Zone
    unique_id: sensor.nfl_red_zone
    state: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "NFL" -%}
            {%- if states(team) == "IN" -%}
            {%- if state_attr(team, "team_homeaway") == "home" -%}
            {%- if state_attr(team,'possession') is not none -%}
            {% set possession = state_attr(team,'possession') %}
            {% set team_id = state_attr(team,'team_id') %}
            {% set opponent_id = state_attr(team,'opponent_id') %}
            {% set team_abbr = state_attr(team,'team_abbr') %}
            {% set opponent_abbr = state_attr(team,'opponent_abbr') %}
            {% set down_distance_text = state_attr(team,'down_distance_text') %}
            {% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
            {% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
            {% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
            {% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
            {%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
            {% set redzone.teams = redzone.teams + [team] %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endfor %}
            {{ redzone.teams | count }}
    attributes:
        teams: |
            {% set redzone = namespace(teams=[]) %}
            {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "NFL" -%}
            {%- if states(team) == "IN" -%}
            {%- if state_attr(team,'possession') is not none -%}
            {% set possession = state_attr(team,'possession') %}
            {% set team_id = state_attr(team,'team_id') %}
            {% set opponent_id = state_attr(team,'opponent_id') %}
            {% set team_abbr = state_attr(team,'team_abbr') %}
            {% set opponent_abbr = state_attr(team,'opponent_abbr') %}
            {% set down_distance_text = state_attr(team,'down_distance_text') %}
            {% set down_distance_endzone = state_attr(team,'down_distance_text').split(' ')[4] %}
            {% set down_distance_yardline = state_attr(team,'down_distance_text').split(' ')[5] %}
            {% set possession_abbr = opponent_abbr if opponent_id == possession else team_abbr %}
            {% set non_possession_abbr = opponent_abbr if opponent_id != possession else team_abbr %}
            {%- if (possession_abbr != down_distance_endzone) and (down_distance_yardline | int) <= 20 %}
            {% set redzone.teams = redzone.teams + [team] %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endif %}
            {% endfor %}
            {{ redzone.teams }}

Then in my system I have a tab the displays all “IN” games (but only home teams as to not double the games). I use decluttering templates but you could yank out the code and do as you wish in yur own view. The key here is that is adds card-mod to set the card background-color and border to emphasize red zone. This is the decluttering template and if you need more information on using such a thing you can ask here or in the other thread … Sports Standings and Scores - #258 by kbrown01

  game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: masonry
      card_param: cards
      filter:
        template: |
          {%- for team in integration_entities("teamtracker") -%}
            {%- if state_attr(team, "league") == "[[sport]]" -%}
            {%- if states(team) == "[[status]]" -%}
            {%- if state_attr(team, "team_homeaway") == "home" -%}
            {%- if team in state_attr('sensor.nfl_red_zone','teams') -%}
              {{{"type": "custom:teamtracker-card",
                "entity": team,
                "card_mod": {"style": "ha-card {\n    background-color:  #ffcccc; \n    box-shadow: 0 0 10px 5px red;\n}\n"},
                "home_side": "right"}}},
            {%- else -%}
              {{{"type": "custom:teamtracker-card",
                "entity": team, 
                "home_side": "right"}}},
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
            {%- endif -%}
          {%- endfor -%}
        exclude:
          - entity_id: '*team_tracker*'
      sort:
        method: attribute
        attribute: date

What happens? As this is a masonry grid of cards, it draws all the games but if a team enters the Red Zone, it is “emphasized”. This is only a mockup testing the card-mod against existing cards as no games are on now. But I tested with titles and background-color on Monday night and it worked perfectly.

image

1 Like

You will not be watching many games on DirecTV this year (except your local ones or NFL Network). All out of market are YouTubeTV now (yuck).

But you could easily take that automation I posted above, cut it back to only your teams and change the action from announcing something on Alexa to your specific light (adding the condition only of you are home).

And I can’t help you with the “watching the game part” … no one likely can. You would need to know broadcast/channel info at least and I would guess if you fell asleep or went to the bathroom!

1 Like

Love it @kbrown01. Great job!

Once tested, I’ll follow with the template for those not watching all teams in case anyone wants/needs it.

Thank you, new to writing jinga and template script. I would just want it to turn my lights my team color when they score. I would just make the condition be when my TV is on the direct TV source. May I ask what would i change on your automation for my own? @kbrown01

This much more than you need and doesn’t have anything to do with scores.

You just need an automation. Do it in the front end. State trigger would be your team sensor with the attribute of Team score.

The action would be to call the service you need to change your lights, a pause of time, and the service call again to change them back to ‘normal’.

Might want to add a condition that the sensor state is IN so it does not change your light when it is resetting from POST to PRE for the next week.

If you don’t want it to happen on the point after, you can compare the from_state of the team_score to the to_state and make sure it is greater than 1.

This should be close. You will need to fill in your services for your light.

description: "Notify Team Score"
mode: single
trigger:
  - platform: state
    entity_id:
      - sensor.dallas_cowboys
    attribute: team_score
condition:
  - condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.to_state == 'IN' }}"
      - condition: template
        value_template: "{{ trigger.to_state.team_score - trigger.from_state.team_score > 1 }}"
action:
  - service: ""
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: ""
    data: {}