vasqued2 / ha-teamtracker-card

A Home Assistant frontend custom card that will display real-time updates for teams tracked with the ha-teamtracker integration. Has custom in-game layouts for football, baseball, basketball, hockey, soccer, golf, tennis, racing, and mma.
GNU General Public License v3.0
75 stars 16 forks source link

Add the ability to get entity: from a template #62

Closed ejpenney closed 1 year ago

ejpenney commented 1 year ago

This is a feature request regarding https://github.com/vasqued2/ha-teamtracker/issues/102, if I create a bunch of Team Tracker entities tracking all the leagues my international soccer team is in, then I could go create a card with (in some cases) many conditions but that's messy, for example USWNT would require as many as 7 conditional cards. I would prefer to create one sensor that tells the card which team sensor to use, then one card based on that sensor.

Here's my example, tracking the USWNT:

sensor:
  - platform: template
    sensors:
      uswnt_next_game:
        friendly_name: "USWNT Next Game Sensor"
        value_template: >
          {%- set entities = states.sensor | selectattr("entity_id", "search", "uswnt") | rejectattr("entity_id", "eq", this.entity_id) | rejectattr("attributes.date", "eq", None) | rejectattr("state", "eq", "NOT_FOUND") | sort(attribute="attributes.date", reverse=True) %}
          {%- set ns = namespace(entity = "NOT_FOUND") %}
          {%- for entity in entities %}
            {%- if entity.state != "POST" or as_datetime(entity.attributes.date) > (now() - timedelta(days=1)) %}
              {%- set ns.entity = entity.entity_id %}
            {%- endif %}
          {%- endfor %}
          {{ ns.entity }}

This creates sensor.uswnt_next_game, which points to the sensor with the next upcoming game in it, then I'd like to create a card like this:

type: custom:teamtracker-card
entity: '{{ states("sensor.uswnt_next_game") }}'

But that isn't currently possible. Maybe there's a cleaner way to handle this, but I'm not seeing it?

vasqued2 commented 1 year ago

Try using the auto-entities card. You should be able to come up with a naming convention that let's you pull in the sensors you want to consider for display and only display the ones w/ the status that you want. No need to create the template sensor, auto-entities will cycle through them all and pull the ones you want.

Example at the link.

https://github.com/vasqued2/ha-teamtracker/wiki/Using-Auto-Entities-Card-to-Hide-NOT_FOUND-Status