As always, nicely done @ehcah .
I am not going to post all of the code I have in this soccer sandbox but will put in pieces that I am doing now if it helps anyone. I am sandboxing the soccer leagues and want to get back to NCAAF and starting to sandbox the NCAA Basketball.
As I have stated earlier, templates errored out on a couple of the NCAA conferences because of their size. So everything I am pulling is through sensors. I still use templates but for the things that fit.
@ehcah and I are looking at performance and trying to determine if there are ways to improve - like reducing code.
One more quick comment. I do notice when I restart my HA container I will see API errors. I am guessing that ESPN is shutting down the requests I am making at the same time. These eventually get populated, but if you see them they typically populate soon.
So in soccer I noticed that you have to change where the promotion/relegation/on the bubble lines are for the leagues.
Here is an example:
Premier League looks like this:
Bundesliga looks like this:
And Bundesliga 2 looks like this:
So I adjusted my decluttering card to take variables and put the 4 colored lines where you want.
here are the variables. They correspond to a line and if you put 0 then no line for that variable
- promotion: 0
- in-running: 6
- near-out: 15
- relegation: 17
The decluttering card that does that is here:
soccer_standings:
card:
type: custom:flex-table-card
title: '[[title]]'
css:
table+: 'padding: 0px; width: 100%; border-collapse: collapse; margin-top:12px;'
tbody tr td:first-child: 'width: 1%;'
tbody tr td:nth-child(2): 'width: 10%;'
tbody tr td:nth-child(3): 'width: 3%;'
tbody tr td:nth-child(n+4): 'width: 1%;'
tbody tr td:nth-child(5): 'color: green;'
tbody tr td:nth-child(6): 'color: yellow;'
tbody tr td:nth-child(7): 'color: red;'
tbody tr td:nth-child(10): 'background-color: green; color: white;'
tbody tr:nth-child([[relegation]]): 'border-bottom: 2px solid crimson!important;'
tbody tr:nth-child([[near-out]]): 'border-bottom: 2px solid yellow!important;'
tbody tr:nth-child([[in-running]]): 'border-bottom: 2px solid dodgerblue!important;'
tbody tr:nth-child([[promotion]]): 'border-bottom: 2px solid green!important;'
tbody tr:hover: 'background-color: dimgrey!important; color:white!important;'
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]]'
columns:
- name: Rank
data: entries
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'R')
!=='undefined'){x.stats.find(y=>y.abbreviation ==
'R').displayValue}else{'-'}
- name: Team
data: entries
modify: |-
if (typeof x.team.logos !== 'undefined')
'<div><img src="' + x.team.logos[0].href + '" style="height:20px;vertical-align:middle;"> ' + x.team.displayName + '</div>'
else
'<div><span style="display: inline-block;width: 20px;"></span> ' + x.team.displayName + '</div>'
- name: Record
data: entries
hidden: false
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'Total') !== 'undefined'
){x.stats.find(y=>y.abbreviation == 'Total').displayValue}else{'-'}
- name: Wins
data: entries
hidden: false
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'W') !== 'undefined'
){x.stats.find(y=>y.abbreviation == 'W').displayValue}else{'-'}
- name: Draws
data: entries
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'D') !== 'undefined'
){x.stats.find(y=>y.abbreviation == 'D').displayValue}else{'-'}
- name: Losses
data: entries
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'L') !== 'undefined'
){x.stats.find(y=>y.abbreviation ==
'L').displayValue}else{'-'}
- name: Points
data: entries
modify: >-
if(typeof x.stats.find(y=>y.abbreviation == 'P') !== 'undefined'
){x.stats.find(y=>y.abbreviation == 'P').displayValue}else{'-'}
align: center
And here is an example of how you call it:
- attributes:
label: Premier League (EPL)
icon: mdi:account-group
card:
type: horizontal-stack
cards:
- type: vertical-stack
cards:
- type: markdown
content: |
<h1>EPL Standings</h1>
- type: custom:decluttering-card
template: soccer_standings
variables:
- title: EPL Standings
- entity: sensor.soccer_english_premier_league
- attribute: entries
- promotion: 0
- in-running: 6
- near-out: 15
- relegation: 17
- type: vertical-stack
cards:
- type: markdown
content: >
<h1>Pre,Live,Post EPL
Games</h1>
- type: markdown
content: |
<h1>EPL Games Live</h1>
- type: custom:decluttering-card
template: european_soccer_game_stats
variables:
- sport: EPL
- sport_path: soccer
- group: group.eng_1
- team_names: sensor.soccer_team_names_premier_league
- status: IN
- type: markdown
content: |
<h1>EPL Games Coming-up</h1>
- type: custom:decluttering-card
template: european_soccer_game_stats
variables:
- sport: EPL
- sport_path: soccer
- group: group.eng_1
- team_names: sensor.soccer_team_names_premier_league
- status: PRE
- type: markdown
content: |
<h1>EPL Games Completed</h1>
- type: custom:decluttering-card
template: european_soccer_game_stats
variables:
- sport: EPL
- sport_path: soccer
- group: group.eng_1
- team_names: sensor.soccer_team_names_premier_league
- status: POST
I know some will also ask what is group and names. I used that on the NCAAF card to limit the cards I am using. I am also trying to see if that helps performance. Targeted calls vs cycling through TeamTracker cards.
Here is a Bundesliga example I have in groups.yaml. you see eng.1 for the premier league and it also has a group.
ger_2:
- sensor.fortuna_dusseldorf
- sensor.karlsruher_sc
- sensor.hamburg_sv
- sensor.1_fc_magdeburg
- sensor.sc_paderborn_07
- sensor.hannover_96
- sensor.hertha_berlin
- sensor.sv_07_elversberg
- sensor.1_fc_nurnberg
- sensor.fc_cologne
- sensor.kaiserslautern
- sensor.spvgg_greuther_furth
- sensor.sv_darmstadt_98
- sensor.schalke_04
- sensor.ssv_ulm_1846
- sensor.tsv_eintracht_braunschweig
- sensor.preussen_munster
- sensor.ssv_jahn_regensburg
and here is the template I use to put all of the names that are in the league in a sensor which I use in decluttering card.
- name: soccer_team_names_bundesliga_two
unique_id: sensor.soccer_team_names_bundesliga_two
state: "{{ now() }}"
attributes:
team_names: >
{% set cteams = namespace(cteam=[]) %}
{% for team in state_attr('sensor.soccer_bundesliga_two', 'entries') %}
{% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
{% endfor %}
{{ cteams.cteam | join(', ') }}
Hope this helps