NFL game sensor (scores, possession, etc)

I believe the attribute is team_colors_rbg correct? It should actually be RGB and not RBG. Meaning the middle value is green, not blue and the attribute is named incorrectly.

Also, you can use the RGB color array by itself without splitting the values.

service: lifx.effect_pulse
data:
  power_on: true
  mode: strobe
  brightness: 255
  cycles: 20
  period: 0.5
  rgb_color: "{{ states.sensor.nfl.attributes.team_colors_rbg[0] }}"
target:
  entity_id: light.lamp

With all that said, I find the color accuracy of the lifx bulbs a little off, and prefer to set the color for my team manually. But if you want it to dynamically change this would be the easiest way.

1 Like

Ah - Unfortunately, neither of the Superbowl teams are my team! I’m just looking to have the lights flash the primary colors of whichever team scores.

In this case, I was trying to use the blueprint found here:

After updating it to use the “teamtracker” integration as opposed to the original “nfl” integration, it throws the error:

Stopped because an error was encountered at February 11, 2023 at 4:05:20 PM (runtime: 0.01 seconds)

None for dictionary value @ data[‘rgb_color’]

I’d originally thought it was because the teamtracker integration uses the attributes “team_colors” and “opponents_colors” as opposed to team_colors_rgb and opponent_colors_rgb, but correcting those to reflect the proper attribute names didn’t seem to resolve anything.

The RGB color options were added to this integration after team tracker forked it, and it doesn’t look like team tracker has included those. TT only has hex values for the colors. The LIFX integration doesn’t allow hex values so rgb and color_name are your only options.

Here’s an example of a score automation that uses CSS color names.

- alias: NFL - Team Score
  trigger:
  - platform: state
    entity_id:
    - sensor.nfl
    attribute: team_score
  condition:
  - condition: state
    entity_id: sensor.nfl
    state: IN
  - condition: template
    value_template: '{{ (trigger.to_state.attributes.team_score | int) >= (trigger.from_state.attributes.team_score
      | int + 1) }}'
  - condition: template
    value_template: '{{ (trigger.to_state.attributes.team_score | int) <= (trigger.from_state.attributes.team_score
      | int + 6) }}'
  - condition: template
    value_template: '{{ (trigger.to_state.attributes.team_score | int) != (trigger.from_state.attributes.team_score
      | int)}}'
  action:
  - service: lifx.effect_pulse
    data:
      mode: strobe
      brightness: 255
      color_name: red #CSS COLOR NAME HERE
      period: 0.5
      cycles: 20
    target:
      entity_id: light.lamp
  mode: parallel

The conditions are just added to cut down on false positives if the integration drops for a moment. For the lights to flash with either team, you could add either one of the teams as the integration sensor and then a second automation similar to this, but use opponent_score in place of team_score.

If anyone else is running Hyperion, I set something up to display team (and opponent) colors in an effect using the RGB colors from the sensor.

in configuration.yaml (replace ip with the ip of your hyperion instance)

shell_command:
  hyperion_team_score: curl "http://192.168.0.231:8090/json-rpc" -X POST -d '{"command":"effect", "effect":{"name":"Police Lights Single", "args":{"color_one":'"{{ color_1 }}"', "color_two":'"{{ color_2 }}"', "colors_count":'"{{ color_length }}"'}}, "duration":10000, "priority":1, "origin":"Home Assistant"}'

and this is an automation that’s set up to flash a lifx bulb and trigger that shell script with the colors from each team

- id: '1676166925172'
  alias: Super Bowl Score Flash
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.super_bowl
    attribute: team_score
    id: '0'
  - platform: state
    entity_id:
    - sensor.super_bowl
    attribute: opponent_score
    id: '1'
  condition:
  - condition: or
    conditions:
    - condition: and
      conditions:
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.team_score | int) >= (trigger.from_state.attributes.team_score | int + 1) }}'
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.team_score | int) <= (trigger.from_state.attributes.team_score | int + 6) }}'
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.team_score | int) != (trigger.from_state.attributes.team_score | int)}}'
    - condition: and
      conditions:
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.opponent_score | int) >= (trigger.from_state.attributes.opponent_score | int + 1) }}'
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.opponent_score | int) <= (trigger.from_state.attributes.opponent_score | int + 6) }}'
      - condition: template
        value_template: '{{ (trigger.to_state.attributes.opponent_score | int) != (trigger.from_state.attributes.opponent_score | int)}}'
  - condition: state
    entity_id: sensor.super_bowl
    state: IN
  action:
  - service: lifx.effect_pulse
    data:
      period: 0.5
      cycles: 20
      power_on: true
      mode: strobe
      brightness_pct: 100
      rgb_color: >
        {% if (trigger.id == '0') %}
          {{ states.sensor.super_bowl.attributes.team_colors_rbg[0] }}
        {% else %}
          {{ states.sensor.super_bowl.attributes.opponent_colors_rgb[0] }}
        {% endif %}
    target:
      entity_id: light.lamp
  - if:
    - condition: trigger
      id: '0'
    then:
    - service: shell_command.hyperion_team_score
      data_template:
        color_1: '{{ trigger.to_state.attributes.team_colors_rbg[0] }}'
        color_2: '{{ trigger.to_state.attributes.team_colors_rbg[1] }}'
        color_length: 120
    else:
    - service: shell_command.hyperion_team_score
      data_template:
        color_1: '{{ trigger.to_state.attributes.opponent_colors_rgb[0] }}'
        color_2: '{{ trigger.to_state.attributes.opponent_colors_rgb[1] }}'
        color_length: 120
  mode: parallel

The colors spin around the screen, but you could adapt the command to work with any effect that accepts colors.

2 Likes

the attribute is named incorrectly

Guess that slipped through the code review :grimacing:

My NFL Integration started erroring out recently. If I try to follow the link for documentation or known issues on github, it fails. The best I can tell is that it is trying to get to ha_nfl instead of ha-nfl (underscore vs. a dash). Would this also lead to the integration not loading with the following log entry? Or is this just normal at this point in between seasons?

Error setting up entry Green Bay Packers for nfl
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 387, in async_setup
result = await component.async_setup_entry(hass, self)
File “/config/custom_components/nfl/init.py”, line 66, in async_setup_entry
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
AttributeError: ‘ConfigEntries’ object has no attribute ‘async_setup_platforms’

Some work needs to happen on the integration. See this for details. hass.config_entries.async_setup_platforms is scheduled to be removed in 2023.03 · Issue #37 · zacs/ha-nfl · GitHub

Should be fixed now, thanks for the PR @D34DC3N73R! I’ll cut a release shortly.

I’m not sure why the pytest is failing. Ran out of time to work on it today, but the actual async issue is resolved with that PR.

No worries. If you have time to look into it that’s appreciated. Otherwise I can take a look one night this week.

If anyone’s interested, I made a dashboard with dynamic cards for the whole league to follow all the games.
In addition to ha-nfl and ha-nfl-card, the custom card auto-entities is also needed.

2 Likes

I have a issue setup the NFL Game Score Light Color Flasher
I ran a test via the Automation and got a error of :
Stopped because an error was encountered Error rendering data template: UndefinedError: 'dict object' has no attribute 'entity_id'

here are some of the screenshots

Can someone please assist me on what I am doing wrong
thank you

You can’t test via the automation editor because the automation depends on trigger data that has to come from actual entity changes. Once it’s set up, it’s possible to manipulate the entity attributes via the States tab in Developer Tools to test. The sensor state has to be set to IN first (it is most likely PRE at the moment of writing this). Then you can change the team_score attribute of the nfl entity (and opponent_score if you’re also activating on it).

Thank you!

I see this error occasionally in my logs:

This causes the entity to show as offline when it occurs. Anyone else run into this?

Leads me to think maybe the ESPN JSON went away temporarily. It shows up now for me. Did it fix itself for you?

Yes, it’s intermittent. Looking at the logs it’s happened 75 times in the past 2 weeks. I first noticed when I went to view the score in my dashboard and it wasn’t available. I wasn’t sure if it’s something in my system or the ESPN API.

i have hyperhdr rooted in my LG tv. can I use hyperhdr with the blueprint or any automation out there for hyperhdr wled?

Not super familiar with that. It’s like Hyperion right? If they have a json api, you can check out this post to see an automation and shell command I used with Hyperion.

That would work for any team (and opposing team) using the RGB colors from the team sensor, make sure to change team_colors_rbg to team_colors_rgb as that was corrected after I made the automation.

I personally don’t really use it anymore, but call a custom effect in hyperion as well as some WLED strips. If you run into problems I can post the automation I use.

Please post the automation you use. Hyperhdr is just hyperion just enhanced for HDR. what i’m looking for is when my Cowboys play hyperhdr does team colors and effects when they score. Then when game done. go back to normal HyperHDR