NFL game sensor (scores, possession, etc)

hello, i have 2 questions.

the Bye Week card is not displaying in my lovelace card using the newest update. Is there something I need to do to get it to display?

Also could anybody point me in the right direction to create automations for details like game start, team score etc. Im not sure how or what attribute I should be watching to do so.

thanks again this is awesome!

In terms of automations, I’m a yaml person so here are how I’d do them…

- alias: "Game started"
  trigger:
  - platform: state
    entity_id: sensor.nfl
    from: "PRE"
    to: "IN"
  action:
    - service: notify.everywhere # use your own notify stuff here
      data_template:
        title: "Game started!"
        message: ":rotating_light: The Seahawks game has started!!"

For touchdowns, you can scroll up and find @davearneson 's post here: NFL game sensor (scores, possession, etc) - #150 by davearneson which should get you sorted.

1 Like

The bye week seems to be working on my HA install as well as the dev container I spun up. Are you viewing through a web browser or HA app? Can you check with chrome and see if you have any errors in the chrome console? Can anyone else test to see if bye weeks are working for them?

Works for me over in dark land.

2 Likes

Bye week is working for me (with the Steelers).

1 Like

XFL please

Love the layout tweaks!!

1 Like

Just pushed an update to fix that team win probability percent padding. Otherwise, it looked really good to me too! Thanks

I have tried on both. nothing is showing. im testing with the Steelers.

in the console i am getting errors but it doesn’t appear to be from your card

football:1 Uncaught DOMException: Failed to execute ‘define’ on ‘CustomElementRegistry’: the name “card-templater” has already been used with this registry
at Module. (http://192.168.86.96:8123/hacsfiles/lovelace-card-templater/lovelace-card-templater.js:144:5706)
at n (http://192.168.86.96:8123/hacsfiles/lovelace-card-templater/lovelace-card-templater.js:1:110)
at http://192.168.86.96:8123/hacsfiles/lovelace-card-templater/lovelace-card-templater.js:1:902
at http://192.168.86.96:8123/hacsfiles/lovelace-card-templater/lovelace-card-templater.js:1:912
app-header-layout.js:151 Uncaught (in promise) http://192.168.86.96:8123/hacsfiles/lovelace-card-mod/card-mod.js.js
:8123/developer-tools/state:1 Autofocus processing was blocked because a document already has a focused element.

Can you check the version that you’re using? Maybe try a reinstall from HACS if you’re already running v0.3.3. Is the sensor state BYE?

i installed 3.4 and the bye week is showing,tanks for the automation example also. I appreciate you guys very much!

Thanks for sharing this automation, it works very well! Im wondering if there is a way to trigger a action on set point values? ie; 6 points (Touchdown) 3 points (fieldgoal) 1 point (extra Point) 2 points (2 point conversions) just to add a bit more to the automations. I have tried to figure it out but was unsuccessful.

You could setup some template sensors for the scores (since they are only attributes right now), and then do an automation based on numeric_state using the from: and to: options. If you wanted to pursue that template sensor, then for the value template you would use something like {{ state_attrs('sensor.nfl', 'team_score') }}.

You can trigger off of attributes as well. This isn’t exactly what @Corey_Maxim is looking for, but it might serve as a starting point: Here’s my automation that tracks multiple games each week. I’ll add and remove teams from the integration and change the entity_ids in the automation once a week for my wife, sister and brother-in-law’s survivor pool. End result is that our phones get regularly updating notifications, one for each game with the scores, timeouts, and win probability, and eventually final score.

alias: NFL Game Score
description: >-
  (add nfl sensors to each of the 3 triggers to keep track of the relevant
  games)
trigger:
  - platform: state
    entity_id: >-
      sensor.nfl_phi, sensor.nfl_dal, sensor.nfl_bal, sensor.nfl_pit,
      sensor.nfl_buf
    attribute: team_score
  - platform: state
    entity_id: >-
      sensor.nfl_phi, sensor.nfl_dal, sensor.nfl_bal, sensor.nfl_pit,
      sensor.nfl_buf
    attribute: opponent_score
  - platform: state
    entity_id: >-
      sensor.nfl_phi, sensor.nfl_dal, sensor.nfl_bal, sensor.nfl_pit,
      sensor.nfl_buf
    to: POST
condition:
  - condition: template
    value_template: '{{ states(trigger.entity_id) in [ "IN", "POST" ]  }}'
action:
  - service: notify.phones
    data:
      title: >-
        {{ state_attr(trigger.entity_id, "team_name") }} / {{
        state_attr(trigger.entity_id, "opponent_name") }}
      message: >-
        {{ state_attr(trigger.entity_id,"team_abbr") }} {{
        state_attr(trigger.entity_id,"team_score") }} {{ ("•••" if
        state_attr(trigger.entity_id,"team_timeouts")|int == 3 else "••" if
        state_attr(trigger.entity_id,"team_timeouts")|int == 2 else "•" if
        state_attr(trigger.entity_id,"team_timeouts")|int == 1 else "" ) if 
        state_attr(trigger.entity_id,"team_timeouts")  else ""}}

        {{ state_attr(trigger.entity_id,"opponent_abbr") }} {{
        state_attr(trigger.entity_id,"opponent_score") }} {{ ("•••" if
        state_attr(trigger.entity_id,"opponent_timeouts")|int == 3 else "••" if
        state_attr(trigger.entity_id,"opponent_timeouts")|int == 2 else "•" if
        state_attr(trigger.entity_id,"opponent_timeouts")|int == 1 else "" ) if
        state_attr(trigger.entity_id,"opponent_timeouts")  else ""}}

        {{ "Q" ~  state_attr(trigger.entity_id, "quarter") if
        state_attr(trigger.entity_id, "quarter") else ""  }} {{ " - " ~ 
        state_attr(trigger.entity_id, "clock") if state_attr(trigger.entity_id,
        "clock") else "" }}

        {{ "Final" if states(trigger.entity_id) == "POST" else
        (state_attr(trigger.entity_id, "team_win_probability") * 100 | int) ~ "%
        chance of winning" if state_attr(trigger.entity_id,
        "team_win_probability") else ""}}
      data:
        tag: '{{ state_attr(trigger.entity_id,"team_abbr")|lower }}-score'
        url: /lovelace/football
        group: football
mode: parallel
max: 15

This does trigger a little more often than it needs – for instance, sometimes they might roll the score back after a challenge, and I noticed today after the nationwide Comcast outage that the scores all updated (you can see this in the times in the screenshot I just took) – but mostly it ‘just works’.

Note the tag and group fields in the notification data. The tag field will replace a specific notification with a new one, so the scores just update rather than my notification center being filled with Home Assistant entries by the end of the game). And grouping lets me keep the couple of games I’m tracking all together, and separate from the laundry, geo-location, doorbell, phone, and half dozen other things I have HA notify me for :-). And the url field goes to the HA dashboard page with the nfl cards :-), of course!

1 Like

Thank You for sharing this, I will have a good lock over it!

Thanks zacs, I appreciate it! I will see what I can come up with! You guys are the best!

Ok, I can’t seem to figure it out, or find any examples.
if i enter this into the template.

{{state_attr(‘sensor.browns’, ‘team_score’)}}

It returns 0,thisis expected because thers no game right now. Im just not sure howto structure it after this. can something like this be done to get the desired result?

- id: browns_touchdown

  alias: Browns Touchdown

  trigger:

  - platform: state

    entity_id: sensor.browns

    attribute: team_score

  condition:

  - condition: template

    value_template: '{{ trigger.to_state.attributes.team_score|int > (trigger.from_state.attributes.team_score|int

      == 6) }}'

Then do the action for touchdown.
and then maybe this for the extra point?

- id: browns_extra_point

  alias: Browns Extra Point

  trigger:

  - platform: state

    entity_id: sensor.browns

    attribute: team_score

  condition:

  - condition: template

    value_template: '{{ trigger.to_state.attributes.team_score|int > (trigger.from_state.attributes.team_score|int

      == 1) }}'
- id: browns_two_point_conversion

  alias: Browns Two Point Conversion

  trigger:

  - platform: state

    entity_id: sensor.browns

    attribute: team_score

  condition:

  - condition: template

    value_template: '{{ trigger.to_state.attributes.team_score|int > (trigger.from_state.attributes.team_score|int

      == 2) }}'

Im sure the solution can’t be that simple. Its hard to test without a game. I can try it with the ravens game tomorrow.

I think you are pretty close…

I haven’t used to_state and from_state with a numeric_state trigger before, so this might not work, but here’s a guess.

This would be for a 6 point increase…

automation:
  trigger:
    - platform: numeric_state
      entity_id: sensor.browns
      attribute: team_score
  condition:
    condition: template
    value_template: >
      {{
        (trigger.to_state.team_score|int - trigger.from_state.team_score|int) == 6
      }}
  action:
    ...
1 Like

I think the condition value_template would need to go into the attributes of the trigger entity like this:

      {{
        (trigger.to_state.attributes.team_score|int - trigger.from_state.attributes.team_score|int) == 6
      }}

By the way, you can test the automation by going into the Developer tools>States and modifying the score manually:

1 Like

Hey @Corey_Maxim, sorry for the delayed response. I see the discussion above, did you figure it out?

One option using the template I shared above might be:

alias: NFL - Example Trigger Automation for Field Goal
description: Triggers if Team Score changes by 3 points
trigger:
  - platform: state
    entity_id: sensor.nfl
    attribute: team_score
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.attributes.team_score|int ==
      (trigger.from_state.attributes.team_score|int + 3) }}
action:

mode: single

I left the action part of the automation blank so you can just do whatever you want. Just change the number 3 in the template to whatever score value you want.

If you want everything in one automation using the choose function, you could try something like this:

alias: NFL - TEST Multiple Score Value Triggers
description: Turns on input boolean for one minute if Saints score changes by 6+ points
trigger:
  - platform: state
    entity_id: sensor.nfl
    attribute: team_score
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.to_state.attributes.team_score|int ==
              (trigger.from_state.attributes.team_score|int + 6) }}
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.nfl_touchdown_detector
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.to_state.attributes.team_score|int ==
              (trigger.from_state.attributes.team_score|int + 1) }}
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.nfl_pat_detector
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.to_state.attributes.team_score|int ==
              (trigger.from_state.attributes.team_score|int + 2) }}
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.nfl_2pt_detector
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.to_state.attributes.team_score|int ==
              (trigger.from_state.attributes.team_score|int + 3) }}
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.nfl_fg_detector
    default: []
mode: single

I just made up dummy input booleans to turn on for the choose example, but you can just make the actions whatever you want.

I haven’t tested those automations, but I don’t see why they wouldn’t work.

2 Likes