#NFL Team Score Automation

1 messages · Page 1 of 1 (latest)

marble girder
#

@hardy pecan requested I bring this templating issue to you all for assistance. Original thread, https://discord.com/channels/330944238910963714/1054144517370028065. I am wanting to trigger my WLED playlist whenever my football team scores. I have the HACS https://github.com/zacs/ha-nfl working and I see sensor.philadelphia_eagles with various attributes. I only want to trigger the automation when a touchdown is scored, >=6 points and not for a field goal 3 points.

The sensor state IN means game is active and the attribute team_score seems to be what we'll need to use. I don't know how best to store or get the previous value to compare to the new value so I can determine the type of score. How best do you all suggest doing this? Attributes below, but game ended so some values don't apply.

attribution: Data provided by ESPN
date: 2022-12-18T18:00Z
kickoff_in: 3 hours ago
quarter: null
clock: null
venue: Soldier Field
location: Chicago, IL
tv_network: FOX
odds: null
overunder: null
possession: null
last_play: null
down_distance_text: null
team_abbr: PHI
team_id: 21
team_name: Eagles
team_record: 13-1
team_homeaway: away
team_logo: https://a.espncdn.com/i/teamlogos/nfl/500/scoreboard/phi.png
team_colors: #06424D, #a5acaf
team_colors_rbg: 
- - 6
  - 66
  - 77
- - 165
  - 172
  - 175

team_score: 25
team_win_probability: null
team_timeouts: 3
opponent_abbr: CHI
opponent_id: 3
opponent_name: Bears
opponent_record: 3-11
opponent_homeaway: home
opponent_logo: https://a.espncdn.com/i/teamlogos/nfl/500/scoreboard/chi.png
opponent_colors: #152644, #0b162a
opponent_colors_rgb: 
- - 21
  - 38
  - 68
- - 11
  - 22
  - 42

opponent_score: 20
opponent_win_probability: null
opponent_timeouts: 3
last_update: 2022-12-18 16:24:10-05:00
icon: mdi:football
friendly_name: Philadelphia Eagles
hardy pecan
marble girder
#

Thanks, hoping someone can help refine a complete solution. I think this will be really cool if I can get it working.

hardy pecan
#
{{ trigger.to_state.attribute.whatever|int(0) - trigger.from_state.attribute.whatever|int(0) >= 6 }}
``` was what I shared before
#

Looks like your whatever is team_score

marble girder
#

oh so i don't need to store and recall anything for the previous values as they are actually stored in the trigger data?

hardy pecan
#

Yes, see the link I posted

marble girder
#

By default is the conditions section "AND" configuration or do I need to wrap them in an "AND" condition? I want to be sure the game sensor is "IN" meaning a game is being played and the difference is 6 or greater.

wide doveBOT
#

There are three sections to an automation:

  • trigger: When any one of these becomes true the automation starts processing. Only one trigger is ever responsible for starting an automation, if you make a condition that checks for more than one having started the automation then the condition can never be true.
  • condition: These are checked after a trigger starts the processing, and must be true for the automation to continue.
  • action: This is the part that does something, and can also include further conditions.
hardy pecan
#

Check the doc links there for the details, but conditions are and by default

marble girder
#

Thanks. i was trying to post image but cant seem to in this thread. I think I have not all configure then. I'll test with another team playing since mine is no longer. Thanks for your info!

wide doveBOT
#

Please use imgur or other image sharing web sites, and share the link here.

Image posting is blocked in most channels to discourage people from sharing text as images. Sharing text as images assumes that everybody sees the world as you do, which isn't the case. Some people are colour blind, or have visual impairment that means they can't make sense of an image of text.

hardy pecan
#

The automation is text, in automations.yaml, that's a far nicer thing to share 😉

marble girder
#
- id: '1671400560269'
  alias: Eagles Score a Touchdown
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.philadelphia_eagles
    attribute: team_score
  condition:
  - condition: state
    entity_id: sensor.philadelphia_eagles
    state: IN
  - condition: template
    value_template: '{{ trigger.to_state.attribute.team_score|int(0) - trigger.from_state.attribute.team_score|int(0)
      >= 6 }}'
    alias: Score Touchdown
  action:
  - device_id: 12d91b206038ca58d14da184ca0c46f3
    domain: select
    entity_id: select.basement_tree_playlist
    type: select_option
    option: Eagles Touchdown
    alias: Run Basement Tree "Eagles Touchdown" Playlist
  mode: single
#

I manually set the sensor state to "IN" and the "team_score" to 31 (was 25). I got an error in the automation Trace.

Executed: December 18, 2022 at 5:07:03 PM
Error: In 'template' condition: UndefinedError: 'homeassistant.core.State object' has no attribute 'attribute'

marble girder
#

I configured a test case with the Buccaneers and it errored with Live data. Same error:

Error: In 'template' condition: UndefinedError: 'homeassistant.core.State object' has no attribute 'attribute'