So we can get this:
team_abbr: SF
opponent_abbr: LV
down_distance_text: 4th & 2 at LV 40
possession: '13'
opponent_id: '13'
team_id: '25'
That is every thing we need.
who has the ball? possession=‘13’
Which is? opponent_id
Which is? opponent_abbr: LV
So the statement cut at the end is “LV 40”
So that means LV had the ball at the LV 40 …
So if changed to SF 20 would mean “Red Zone”
Just goofing around:
{% 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,'opponent_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] %}
{{ team }} is the team entity
{%- if opponent_id == possession %}
{{ opponent_abbr }}
{%- else %}
{{ team_abbr }}
{%- endif %} has the ball
{{ down_distance_text }} is the down distance text
{%- if opponent_id == possession %}
{{ opponent_abbr }}
{%- else %}
{{ team_abbr }}
{%- endif %} has ball toward endzone {{ down_distance_endzone}} at {{ down_distance_yardline }} yardline
Yields:
Result type: string
sensor.san_francisco_49ers is the team entity
LV has the ball
1st & 10 at LV 35 is the down distance text
LV has ball toward endzone LV at 35 yardline
So I think its only a matter of if the possession team != endzone team and the yardline <= 20 … Red Zone.
I think this just may do it …
{% 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 need some team to get in the REDZONE!
And of course no one gets in the Redzone after I wrote it.
Next game I guess.
THen we turn that into a template in the NFL stats … Red Zone tab or something!