The current project is a card that will stay updated with my Braves. The background image will actually change based on the venue. I have been working on the code for the background image and now I just need to fill in with scores and other info I decide on.
I’m sure the code can be cleaned up, I pulled the code from HERE and just added it to what I was looking for. Having trouble coming up with a design for the Lovelace card.
Sensors:
#MLB sensors
- platform: rest
resource: http://statsapi.mlb.com/api/v1/schedule?sportId=1&teamId=144
name: mlb_game_status
scan_interval:
hours: 24
value_template: '{{ value_json.dates[0].games[0].status.detailedState }}'
json_attributes:
- dates
- platform: template
sensors:
mlb_away_score:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
No_Game
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["score"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Away
{% else %}
{{ states.sensor.mlb_game_status.attributes["dates"][0]["games"][0]["teams"]["away"]["team"]["name"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/mlb.com/builds/site-core/f1bd3a33969d8febdbcb23b1161db091cf3ae918_1561045539/images/logos/team-cap-on-light/{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["team"]["id"] | int }}.svg
{% endif %}
entity_id: sensor.mlb_game_status
mlb_game_time:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
No_Game
{% else %}
{% set time = states.sensor.mlb_game_status.attributes["dates"][0]["games"][0]["gameDate"] %}
{% if (time[11:13]|int - 5) > 12 %}
{{ (time[11:13]|int - 5 - 12)|string ~ time[13:16] }}
{% else %}
{{ (time[11:13]|int - 5)|string ~ time[13:16] }}
{% endif %}
{% endif %}
mlb_home_score:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
No_Game
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["score"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Home
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["team"]["name"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/mlb.com/builds/site-core/f1bd3a33969d8febdbcb23b1161db091cf3ae918_1561045539/images/logos/team-cap-on-light/{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["team"]["id"] | int }}.svg
{% endif %}
entity_id: sensor.mlb_game_status
mlb_venue:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Park
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["venue"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Park
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["venue"]["name"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/mlb.com/builds/site-core/f1bd3a33969d8febdbcb23b1161db091cf3ae918_1561045539/images/logos/team-primary-on-light/{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["team"]["id"] | int }}.svg
{% endif %}
entity_id: sensor.mlb_game_status
home_pct:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Pct
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
PCT
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["leagueRecord"]["pct"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
away_pct:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Pct
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
PCT
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["leagueRecord"]["pct"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
home_wins:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
W
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Wins
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["leagueRecord"]["wins"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
away_wins:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
W
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Wins
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["leagueRecord"]["wins"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
home_losses:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
L
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Losses
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["home"]["leagueRecord"]["losses"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
away_losses:
value_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
L
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["team"]["name"] }}
{% endif %}
friendly_name_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
Losses
{% else %}
{{ states.sensor.mlb_game_status.attributes.dates[0]["games"][0]["teams"]["away"]["leagueRecord"]["losses"] }}
{% endif %}
entity_picture_template: >-
{% if states('sensor.mlb_game_status') == 'unknown' %}
https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR8rGHWIehoVzpadKbNwJhQ_IxdUbKv81ed06p_3fRsSvmJzluS
{% else %}
https://www.mlbstatic.com/team-logos/league-on-dark/1.svg
{% endif %}
entity_id: sensor.mlb_game_status
#MLB sensors#########