Guessing you could just do an if else else on that ‘#’ column - similar to the rankings up and down code. If ‘#’<=4 do this, if 5-6 do this and if =>16 do this. And the do this is something @kbrown01 worked on last year on the flex-table card here:https://community.home-assistant.io/t/flex-table-card/461173/53
Thanks @kbrown01 that was my error. Moving them around 1 of the files didn’t have sensor: at the top - that fixed it.
I figured it out . I think it’s not the perfect solution but for my needs it’s enough.
type: custom:flex-table-card
entities:
include: sensor.team_tracker_bund_tabelle
columns:
- name: Rank
data: entries
modify: |-
if (x.stats[10].value >=16 )
'<div style="background-color: #ff2c0a;">' + x.stats[10].value + '</div>';
else if (x.stats[10].value >=5 )
'<div style="background-color: #202124;">' + x.stats[10].value + '</div>';
else if (x.stats[10].value <=4 )
'<div style="background-color: #ea8109;">' + x.stats[10].value + '</div>';
align: center
- name: Logo
data: entries
Not sure if you were able to add lines to your template per @bburwell 's share? This is what I do. Add more lines, change them, change the color - your choice. I only define the top 4 (nth-child 4) and bottom 2 (nth-child 16).
bundesliga_settings:
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: 9%;'
tbody tr td:nth-child(n+3): 'width: 3%;'
tbody tr:hover: 'background-color: dimgrey!important; color:white!important;'
tbody tr:nth-child(4): 'border-bottom: 1px solid dodgerblue!important;'
tbody tr:nth-child(16): 'border-bottom: 1px solid crimson!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;
}
@ehcah nice. Do you have a github page? I was going to start building out MLS and UEFA but it looks like you already have that built. Would love to copy those files, sensors, templates, etc. and pay you with heaps of Kudos
Thanks and nicely done!!!
@bburwell No github or pastebin. I’m sure I could figure something out though. Happy to share anything I have.
One challenge I’ve run into. With 570 + various sensors for sports alone, my HA server has been slowing down. As a result, I’ve start hashing out some sensors that aren’t required today. As mentioned above, I did update all my multiscrape sensors to rest or template.
Multiscrape: 1
Template: 69
Rest: 148
TeamTracker: 352
I actually pulled all sensors off my server and added them onto a fresh HA install on proxmox where I keep a few machines spun up for other purposes. I thought a dedicated HA Sports Dashboard machine would be the answer. This works well for a few days and then slows. My intention is to add it back as a webpage dashboard on my server.
Yeah I have been noticing the slowdown as well. That was why I asked the question earlier about splitting up the sensors and templates. I plan on streamlining the dashboards and looking to maybe create a seasonal rotation for sports I kind of follow and then keep the main ones year around. I am also going to play around at some point with polling.
Funny thing is that I originally started looking at this because I wanted to have a scrolling marquee that I send updates to a bunch of Hub75’s. Right now I’m just sending Padres updates to a couple WS2812B’s.
Because of @kbrown01 great work this has kind of turned into something akin to eating potato chips - you think you can stop after a couple but there is always another tempting option to chose
Do we have any MLB playoff views yet?
I was looking at what @mandolin did last year but I haven’t tried the code yet. Maybe give it a try - https://community.home-assistant.io/t/sports-standings-and-scores/547094/443
Figured I would ask here. I am trying to create a simple template like I use for conferences but for the top 25. My conferences that are almost identical work fine and when I put the code below in the template editor it returns exactly how I expect. But when the code is in the template.yaml I keep getting no entities found.
Here is the code in the template.yaml
########
##NCAA Top 25 Football Teams
#### Weekly Top 25
- name: ncaaf.ap_poll_T25
unique_id: sensor.ncaaf_ap_poll_T25
state: "{{ now() }}"
attributes:
team_names: >
{% set cteams = namespace(cteam=[]) %}
{% for team in state_attr('sensor.ncaaf_rank','rankings')[0]['ranks'] %}
{% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
{% endfor %}
{{ cteams.cteam | join(', ') }}
Here is the code in Template editor
{% set cteams = namespace(cteam=[]) %}
{% for team in state_attr('sensor.ncaaf_rank','rankings')[0]['ranks'] %}
{% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
{% endfor %}
{{ cteams.cteam | join(', ') }}
Which gives me this:
So when code is in template.yaml it won’t populate the sensor. But when the code is in the template editor it returns the values as expected.
Any ideas are appreciated.
It looks like you are defining cteam as an array and then using join. Just use
{{ cteams.cteam }}
On output.
Note this one from my templates for red zone (no join):
{% set hteams = namespace(hteam=[]) %}
{% for team in state_attr('sensor.nhl_wildcard','children')[0]['standings']['entries'][2:] %}
{% for stat in team['stats'] | selectattr('name','eq','clincher') %}
{% else %}
{% set hteams.hteam = hteams.hteam + [team] %}
{% endfor %}
{% endfor %}
{{ hteams.hteam }}
Good evening, I would like to arrange table A3 correctly but I can’t do it myself. Does anyone have an idea?
type: custom:flex-table-card
sort_by: Platz
title: Gruppe A3
entities:
include: sensor.nations_league_a3
exclude: zwave.unknown_node*
columns:
- name: Platz
data: entries
modify: |-
if (x.stats[10].value >=4 )
'<div style="background-color: #cd0000;">' + x.stats[10].value + '</div>';
else if (x.stats[10].value >=3 )
'<div style="background-color: #ea8109;">' + x.stats[10].value + '</div>';
else if (x.stats[10].value <=2 )
'<div style="background-color: #228b22;">' + x.stats[10].value + '</div>';
else if (x.stats[10].value >=1 )
'<div style="background-color: #228b22;">' + x.stats[10].value + '</div>';
align: center
- name: Mannschaft
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: Spiele
data: entries
modify: x.stats[0].value
- name: Siege
data: entries
modify: x.stats[7].value
- name: Unentschieden
data: entries
modify: x.stats[6].value
- name: Niederlagen
data: entries
modify: x.stats[1].value
- name: Tor- Verhältniss
data: entries
modify: |-
{
x.stats[5].value +
" : " +
x.stats[4].value
}
- name: Differenz
data: entries
modify: x.stats[2].value
- name: Punkte
data: entries
modify: x.stats[3].value
strict: false
css:
tbody td:nth-child(0)+: "width: 250px;"
tbody tr td:nth-child(9): "background-color: green; color: white;"
tbody tr td:nth-child(4): "color: green;"
tbody tr td:nth-child(6): "color: red;"
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: 9%;"
tbody tr td:nth-child(n+3): "width: 3%;"
tbody tr:hover: "background-color: dimgrey!important; color:white!important;"
tbody tr:nth-child(2): "border-bottom: 1px solid green!important;"
tbody tr:nth-child(3): "border-bottom: 1px solid crimson!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;
}
Not sure what correctly means, but if those above are you only columns then maybe increase column two to maybe 59% and make the last three 10% each. Even though you have table set to 100%, it is not going to fill 100% because you are placing explicit width on all the columns.
You rules are >=4, >=3, <=2, >=1
, anything 2 or less will always match the third if
. You should flop that rule to >=2
and likely just use else
and not elseif
for the last rule.
Thanks @kbrown01 but regardless of join or not it doesn’t populate the sensor. In the template editor the only change was the format which now shows this:
The sensor is still empty:
Any chance I am not getting to the data correctly?
Big 12 works fine, Weekly Top 25 doesn’t similar code just pulling from different api’s:
Here is code for both Top 25 and Big 12
########
##NCAA Top 25 Football Teams
#### Weekly Top 25
- name: ncaaf.ap_poll_T25
unique_id: sensor.ncaaf_ap_poll_T25
state: "{{ now() }}"
attributes:
team_names: >
{% set cteams = namespace(cteam=[]) %}
{% for team in state_attr('sensor.ncaaf_rank','rankings')[0]['ranks'] %}
{% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
{% endfor %}
{{ cteams.cteam }}
########
##NCAA Football Teams
#### Big 12
- name: ncaaf_team_names_big_12
unique_id: sensor.ncaaf_team_names_big_12
state: "{{ now() }}"
attributes:
team_names: >
{% set cteams = namespace(cteam=[]) %}
{% for team in state_attr('sensor.college_football_standings', 'children')[2]['standings']['entries'] %}
{% set cteams.cteam = cteams.cteam + [team['team']['abbreviation']] %}
{% endfor %}
{{ cteams.cteam }}
Top 25 link: https://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard
Big 12 link: [https://site.web.api.espn.com/apis/v2/sports/football/college-football/standings?seasontype=2&type=0&level=3]
Can anyone think of a reason why the sensor wouldn’t be populated but appears correctly in Template Editor?
Try going slow. First, put just this in the template editor:
{% for team in state_attr('sensor.ncaaf_rank','rankings')[0]['ranks'] %}
{{team}}
{% endfor %}
And post the results
Thanks - Here are the 1st 2 pulled - 25 in total.
{'current': 1, 'previous': 2, 'points': 1516.0, 'firstPlaceVotes': 52, 'trend': '+1', 'team': {'id': '251', 'uid': 's:20~l:23~t:251', 'location': 'Texas', 'name': 'Longhorns', 'nickname': 'Texas', 'abbreviation': 'TEX', 'color': 'c15d26', 'logos': [{'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500/251.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'default'], 'lastUpdated': '2018-06-05T12:08Z'}, {'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500-dark/251.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'dark'], 'lastUpdated': '2018-06-05T12:08Z'}], 'links': [{'href': 'https://www.espn.com/college-football/team/_/id/251/texas-longhorns', 'text': 'Clubhouse', 'rel': ['clubhouse', 'desktop', 'team']}], 'logo': 'https://a.espncdn.com/i/teamlogos/ncaa/500/251.png'}, 'date': '2024-10-06T07:00Z', 'lastUpdated': '2024-10-06T21:14Z', 'recordSummary': '5-0'}
{'current': 2, 'previous': 3, 'points': 1473.0, 'firstPlaceVotes': 9, 'trend': '+1', 'team': {'id': '194', 'uid': 's:20~l:23~t:194', 'location': 'Ohio State', 'name': 'Buckeyes', 'nickname': 'Ohio State', 'abbreviation': 'OSU', 'color': 'ce1141', 'logos': [{'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500/194.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'default'], 'lastUpdated': '2023-02-17T21:15Z'}, {'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500-dark/194.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'dark'], 'lastUpdated': '2023-02-17T21:14Z'}], 'links': [{'href': 'https://www.espn.com/college-football/team/_/id/194/ohio-state-buckeyes', 'text': 'Clubhouse', 'rel': ['clubhouse', 'desktop', 'team']}], 'logo': 'https://a.espncdn.com/i/teamlogos/ncaa/500/194.png'}, 'date': '2024-10-06T07:00Z', 'lastUpdated': '2024-10-06T21:14Z', 'recordSummary': '5-0'}
OK now try:
{{team.team}}
Instead of just {{team}}
That gives me this:
{'id': '251', 'uid': 's:20~l:23~t:251', 'location': 'Texas', 'name': 'Longhorns', 'nickname': 'Texas', 'abbreviation': 'TEX', 'color': 'c15d26', 'logos': [{'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500/251.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'default'], 'lastUpdated': '2018-06-05T12:08Z'}, {'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500-dark/251.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'dark'], 'lastUpdated': '2018-06-05T12:08Z'}], 'links': [{'href': 'https://www.espn.com/college-football/team/_/id/251/texas-longhorns', 'text': 'Clubhouse', 'rel': ['clubhouse', 'desktop', 'team']}], 'logo': 'https://a.espncdn.com/i/teamlogos/ncaa/500/251.png'}
{'id': '194', 'uid': 's:20~l:23~t:194', 'location': 'Ohio State', 'name': 'Buckeyes', 'nickname': 'Ohio State', 'abbreviation': 'OSU', 'color': 'ce1141', 'logos': [{'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500/194.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'default'], 'lastUpdated': '2023-02-17T21:15Z'}, {'href': 'https://a.espncdn.com/i/teamlogos/ncaa/500-dark/194.png', 'width': 500, 'height': 500, 'alt': '', 'rel': ['full', 'dark'], 'lastUpdated': '2023-02-17T21:14Z'}], 'links': [{'href': 'https://www.espn.com/college-football/team/_/id/194/ohio-state-buckeyes', 'text': 'Clubhouse', 'rel': ['clubhouse', 'desktop', 'team']}], 'logo': 'https://a.espncdn.com/i/teamlogos/ncaa/500/194.png'}
and {{team.team.abbreviation}}
gives me this:
TEX
OSU
ORE
PSU
UGA
MIA
ALA
TENN
MISS