JayBlackedOut / hass-nhlapi

NHL Stats API Integration Into Home Assistant
64 stars 18 forks source link

Setting Up Frontend #57

Closed Droppisalt closed 11 months ago

Droppisalt commented 1 year ago

Seems to be similar to this one: https://github.com/JayBlackedOut/hass-nhlapi/issues/50

I'm using UI Lovelace Minimalist if that's useful to know.

Here is my code from my configuration.yaml:

sensor: !include sensor.yaml

template:
  - sensor:
    - unique_id: away_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("away_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("away_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("away_logo", "") }}'
  - sensor:
    - unique_id: home_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("home_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("home_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("home_logo", "") }}'

and here's my sensor.yaml:

- platform: nhl_api
  team_id: 8

image image image

JayBlackedOut commented 1 year ago

Hi there, can you describe the issue? I also don't see how you are rendering sensors with entity ID sensor.montreal_canadiens and sensor.toronto_maple_leafs with the config you posted. You should be getting sensor.template_away_team and sensor.template_home_team.

Droppisalt commented 1 year ago

Forgot to include my code to show it on my dashboard:

cards:
  - type: entities
    show_header_toggle: false
    entities:
      - entity: sensor.nhl_sensor
      - entity: sensor.template_away_team
      - entity: sensor.template_home_team

Result: image

I also have no idea how I got those two sensors. I'll try to delete nhl_api and start from scratch

Droppisalt commented 1 year ago

Started from scratch and still no luck. Now I've got no sensors at all

JayBlackedOut commented 1 year ago

What version of Home Assistant are you running?

Droppisalt commented 1 year ago

2023.8.1

JayBlackedOut commented 1 year ago

Try restarting HA and then check the States table in the dev menu and let me know what you see.

Droppisalt commented 1 year ago

Just did, and I see sensor.nhl_sensor, sensor.montreal_canadiens and sensor.toronto_maple_leafs

If I remove this from my configuration.yaml file, I can remove sensor.montreal_canadiens and sensor.toronto_maple_leafs, but as as I as add it back and refresh my templates, they pop back in


template:
  - sensor:
    - unique_id: away_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("away_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("away_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("away_logo", "") }}'
  - sensor:
    - unique_id: home_team
      name: '{{ states.sensor.nhl_sensor.attributes.get("home_name", "") }}'
      state: '{{ states.sensor.nhl_sensor.attributes.get("home_score", "") }}'
      picture: '{{ states.sensor.nhl_sensor.attributes.get("home_logo", "") }}'
JayBlackedOut commented 1 year ago

Are you certain you only put:

- platform: nhl_api
  team_id: 8

in your sensor file? I don't see any reason why those template sensors are rendering with those names. The unique id field should dictate the entity ID. Maybe try the HA forums.

JayBlackedOut commented 11 months ago

Closing

theesquire commented 9 months ago

I experienced this issue just yesterday, when setting up my version of the frontend. Through a little digging, it appears the Unique_ID does not control the entity name when a Name is also available. This explains this Issue's behavior.

The Unique_ID will be recorded... somewhere... and persist, so the two entities created are proxies for home and away (if the home team is TOR when setting it up, all future home teams will be sensor.toronto_maple_leafs).

My simple fix was to rename the home and away entities to the names you intended them to have, such that the rest of the logic in the frontend works. This seems to solve the issue (though is inelegant).

JayBlackedOut commented 9 months ago

Is this related to the template sensors or the nhl_api sensor?

theesquire commented 9 months ago

This is related to the template sensors