Sports Standings and Scores

I think i know what I did wrong… when I get home ill give it a go and see if i Was correct.

To me it looks like the indentation on the YAML is wrong.
You should copy and post it using the </> above and not a screen image,

it was wrong. I just created a split config and tested it, its working. TY

1 Like

I cannot get the sensors to work! Pulling my hair out. Placed your sensor.yaml and template.yaml file in the same dir and configuration.yaml. Edit configuration.yaml to include both files. Aaaaand nothing…

And you restarted to get the sensors to load?

Made a little progress - my test HA environment is running in a VM on Unraid and not working - although my production HA in Synology docker is giving me some sensor data (so that must be a permissions issue on some files maybe). Still getting a blank table though as well as template errors in log

Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.pageProps.date }}’

1:00:09 PM – (ERROR) helpers/template.py

Invalid config for [template]: [name] is an invalid option for [template]. Check: template->name. (See /config/include/template.yaml, line 513).

12:59:58 PM – (ERROR) config.py - message first occurred at 12:59:58 PM and shows up 25 times

Edit - seems to be the Standings tab that is not showing data

What does line 513 look like? Show us five lines above and below with it please.

Line 513 is where the NBA Division attributes are it looks like

entries: “{{ state_attr(‘sensor.nba_standings’,‘children’)[0][‘children’][0][‘standings’][‘entries’] }}”

* name: NBA Eastern Central
unique_id: sensor.nba_eastern_central
state: “{{ now() }}”
attributes:
entries: “{{ state_attr(‘sensor.nba_standings’,‘children’)[0][‘children’][1][‘standings’][‘entries’] }}”
* name: NBA Eastern Southeast
unique_id: sensor.nba_eastern_southeast
state: “{{ now() }}”
attributes:

Please post you code using the </> icon so that we can see the indentation you have. Otherwise we cannot diagnose the issue.

trying to edit

I think you put the crap code into the code block.

Can you repaste from your yaml in there please.

  - name: NBA Eastern Atlantic
    unique_id: sensor.nba_eastern_atlantic
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[0]['children'][0]['standings']['entries'] }}"
  - name: NBA Eastern Central
    unique_id: sensor.nba_eastern_central
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[0]['children'][1]['standings']['entries'] }}"
  - name: NBA Eastern Southeast
    unique_id: sensor.nba_eastern_southeast
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[0]['children'][2]['standings']['entries'] }}"
  - name: NBA Western Northwest
    unique_id: sensor.nba_western_northwest
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[1]['children'][0]['standings']['entries'] }}"
  - name: NBA Western Pacific
    unique_id: sensor.nba_western_pacific
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[1]['children'][1]['standings']['entries'] }}"
  - name: NBA Western Southwest
    unique_id: sensor.nba_western_southwest
    state: "{{ now() }}"
    attributes:
        entries: "{{ state_attr('sensor.nba_standings','children')[1]['children'][2]['standings']['entries'] }}"

In what file is that snippet contained? And if separate, is it included? And above the first name entry do you have:

sensor:

In my setup I use includes so my main configuration yaml has:

template: !include template.yaml

Then this file would be:

sensor:
  - name: NBA Eastern Atlantic
   ... rest of stuff here ...

That is in template.yaml.

Log says:
Invalid config for [template]: [name] is an invalid option for [template]. Check: template->name. (See /config/include/template.yaml, line 513).

Line 513 starts at

entries: "{{ state_attr('sensor.nba_standings','children')[0]['children'][0]['standings']['entries'] }}"

First line of template.yaml should be:

sensor:

Then the rest of the actual stuff you posted. Is the first line correct?

This means exactly what I am saying. HA sees …

template:
  - name: ,,,,,,

not

template:
  sensor:
    - name: ,,,,

Ok…looks like I have team showing up now
But stats are definitely wonky - like Games played for NFL

SO this is for the NFL? It is possible you have the old code maybe. Like this is the latest for the decluttering template for NFL:

  nfl_settings:
    card:
      type: custom:flex-table-card
      title: '[[title]]'
      css:
        table+: 'padding: 0px; width: 1600px;'
        tbody tr td:first-child: 'width: 2%;'
        tbody tr td:nth-child(2): 'width: 20%;'
        tbody tr td:nth-child(n+3): 'width: 6%;'
        tbody tr:hover: 'background-color: green!important; color:white!important;'
        tbody tr td:nth-child(7): 'background-color: green; color: white;'
      card_mod:
        style:
          .: |
            ha-card {
              overflow: auto;
              }
          $: |
            .card-header {
               padding-top: 6px!important;
               padding-bottom: 4px!important;
               font-size: 14px!important;
               line-height: 14px!important;
               font-weight: bold!important;
             }
      sort_by: entries-
      entities:
        include: '[[entity]]'
        exclude: '[[excluded_entities]]'
      columns:
        - hidden: true
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'PCT').value.toFixed(2)
        - name: C
          data: entries
          modify: >-
            if(typeof x.stats.find(y=>y.abbreviation == 'CLINCH') !==
            'undefined' ){x.stats.find(y=>y.abbreviation ==
            'CLINCH').displayValue}else{'-'}
        - name: Team
          data: entries
          modify: >-
            '<div><img src="' + x.team.logos[0].href + '" style="height:
            20px;vertical-align:middle;">&nbsp;' + x.team.displayName + '</div>'
        - name: GP
          data: entries
          modify: >-
            x.stats.find(y=>y.abbreviation == 'L').value +
            x.stats.find(y=>y.abbreviation == 'W').value +
            x.stats.find(y=>y.abbreviation == 'T').value
        - name: W
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'W').value
        - name: L
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'L').value
        - name: T
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'T').value
        - name: PCT
          data: entries
          modify: x.stats.find(y=>y.abbreviation == 'PCT').value.toFixed(2)
        - name: HOME
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'HOME').displayValue
        - name: AWAY
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'AWAY').displayValue
        - name: DIV
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'DIV').displayValue
        - name: CONF
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'CONF').displayValue
        - name: PF
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'PF').displayValue
        - name: PA
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'PA').displayValue
        - name: DIFF
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'DIFF').displayValue
        - name: STRK
          data: entries
          modify: x.stats.find(y=>y.shortDisplayName == 'STRK').displayValue

This was changed long ago to remove dependency on the position and use a lookup to find the proper column by its abbreviation. This solves issues when ESPN changes structures of the data.

And those would use this for NFL tab:

                        card:
                          type: custom:tabbed-card
                          styles:
                            '--mdc-theme-primary': green
                            '--mdc-tab-text-label-color-default': silver
                            '--mdc-typography-button-font-size': 12px
                          tabs:
                            - attributes:
                                label: Divisional
                              card:
                                type: custom:stack-in-card
                                mode: vertical
                                cards:
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: American Football Conference East
                                      - entity: sensor.nfl_afc_east
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: American Football Conference North
                                      - entity: sensor.nfl_afc_north
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: American Football Conference South
                                      - entity: sensor.nfl_afc_south
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: American Football Conference West
                                      - entity: sensor.nfl_afc_west
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: National Football Conference East
                                      - entity: sensor.nfl_nfc_east
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: National Football Conference North
                                      - entity: sensor.nfl_nfc_north
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: National Football Conference South
                                      - entity: sensor.nfl_nfc_south
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: National Football Conference West
                                      - entity: sensor.nfl_nfc_west
                            - attributes:
                                label: Conference
                              card:
                                type: custom:stack-in-card
                                mode: vertical
                                cards:
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: American Football Conference
                                      - entity: sensor.nfl_afc_*
                                  - type: custom:decluttering-card
                                    template: nfl_settings
                                    variables:
                                      - title: National Football Conference
                                      - entity: sensor.nfl_nfc_*
                            - attributes:
                                label: Overall
                              card:
                                type: custom:decluttering-card
                                template: nfl_settings
                                variables:
                                  - title: Overall
                                  - entity: sensor.nfl_*_*
                                  - excluded_entities:
                                      - sensor.nfl_red_zone
                                      - sensor.nfl_standings
                                      - sensor.nfl_teams
                            - attributes:
                                label: Playoffs
                              card:
                                type: markdown
                                content: coming soon!

If you read here, this talks about the issue and resolution. I have not done all the sports. I guess I need to update the GITHUB so people do not grab the older code:

Updating the dashboard, yaml file seems to fixed NFL and MLB standings…not getting any live scores now…lol
This is an awesome piece of work though…I’m sure I’ll figure it out!
Thanks for the help and work!

If you just took my code verbatium I will guess at the issue.
You have no sensor named sensor.nfl_red_zone

You should remove the test for this sensor which I use to draw a red border in NFL live scores when a team goes into the red zone.

This is where I mean (the game_stats decluttering template):

  game_stats:
    card:
      type: custom:auto-entities
      unique: true
      show_empty: false
      card:
        type: custom:layout-card
        layout_type: masonry
        width: 200px
        max-columns: 5
      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\n    color:  black; \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

Remove the “if” and “else/endif” for the red zone test. This is a generic template. What it does is loop through all teams in teamtracker for a particular sport. If the status in “IN” and the team is the home team then it will draw a card. If the team matches a team in the red zone list, the border is red, if not it is just regular. It will not break MLB, NHL, NBA because there is no such thing as “Red Zone” but it would break if you do not have that sensor.

If you do not have that sensor, details were posted above on it but I can report if you like … or you can just remove the test.

I was thinking of expanding the logic on that for MLB to draw red border when bases are loaded. MLB, NHL not much there but could do like overtime/shootout.

I will also note that this is why you see things like this:

                              variables:
                                  - title: Overall
                                  - entity: sensor.nfl_*_*
                                  - excluded_entities:
                                      - sensor.nfl_red_zone
                                      - sensor.nfl_standings
                                      - sensor.nfl_teams

Since those sensors (red zone, standings, teams) do not carry the standings they must be excluded from sensors used to draw the standings ( sensor.nfl_*_*) or the standings will break.

A whole lot of red last night for my Detroit Lions!