thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.29k stars 116 forks source link

Support Templates in Options #216

Open maddox opened 3 years ago

maddox commented 3 years ago

This is a feature request to allow templating in filter.options.

I'm trying to combine the usage of this great card with template-entity-row and it's just not possible. It'd be great and really clean up some lovelace yaml if this was supported.

Mariusthvdb commented 3 years ago

like to add my support for this, as I am trying to auto fill a set of decluttering cards with object_id;s of group members:

  - type: custom:auto-entities
    card:
      type: vertical-stack
      cards:
        - type: custom:decluttering-card
          template: update_zwave_switches
          variables:
            - id:  *list of object_ids*
    filter:
      template: |
        {{ expand('group.z_wave_switches')| map(attribute='object_id') | list }}

of course this doesnt work, since the filter now only supports entity_id's ? having templates would hopefully create the possibility to do just that.

this might be clearer about the goal I am looking for:

  - type: custom:auto-entities
    filter:
      include:
        - group: group.z_wave_switches
    card:
      type: vertical-stack
      cards:
        - type: custom:decluttering-card
          template: update_zwave_switches
          variables:
            - id: this.object_id

this is the verbose config I use now:

  - type: vertical-stack
    cards:
      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: afzuigkap_zolder

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: amp_right_auditorium

      - type: custom:decluttering-card
        template: update_zwave_switches
        variables:
          - id: dorm_studenten

see: https://community.home-assistant.io/t/auto-entities-automatically-fill-cards-with-entities/147801/411?u=mariusthvdb for some more background

chadbaldwin commented 1 year ago

Yes! 100% support this. Just to add a personal use case to this request...here is what I'm trying to do:

type: custom:auto-entities
card:
  type: history-graph
filter:
  include:
    # I am aware you can filter based on domain/attributes.
    # However, I have many auto-created entities for temperature
    # Like in mobile app devicess that I don't want showing up here
    - entity_id: /^sensor\.(.*)_temp$/
      options:
        name: |
          {{
            state_attr(config.entity, 'friendly_name')
              | replace(' - Temp', '')
          }}
hours_to_show: 12
refresh_interval: 5

I like to name my entities so that they are postfixed with their type. So for example, Kitchen Sink - Leak - Battery indicates the battery entity for the leak sensor under the kitchen sink. Or Bedroom - Motion - Temp is the temperature entity for the motion sensor in the bedroom.

Problem is, when I put all of these into a dashboard card, it's too wordy and a bit annoying. So I use template-entity-row to strip out the postfix and makes it much cleaner.

Unfortunately, template-entity-row only works for the entities card.

jumpingmushroom commented 9 months ago

I support this as a feature as well. Right now I'm trying to use the entities produced by the Battery Notes integration to create a list of batteries with their type, last replaced date as well as a press button to update the last replaced date. However, as long as it's not possible to use templates for the options, I can't add _type and _last_updated to the entity produced by auto-entities to add the needed options for the card.

Here's an example of what I'm trying to accomplish:

type: custom:auto-entities
show_empty: false
card:
  type: entities
  title: Battery list
  state_color: false
  show_header_toggle: false
filter:
  include:
    - entity_id: sensor.*battery
      state: < 40
      options:
        type: custom:multiple-entity-row
        toggle: false
        styles:
          font-weight: bold
          width: 80px
          text-align: center
        tap_action:
          action: call-service
          service: button.press
          service_data:
            entity_id: button.outdoor_environmental_sensor_battery_replaced
          confirmation:
            text: Please confirm that you have replaced the batteries
        entities:
          - entity: sensor.outdoor_environmental_sensor_battery_type
            name: Type
          - entity: sensor.outdoor_environmental_sensor_battery_last_replaced
            name: Last replaced
  exclude:
    - state: "off"
    - state: "unavailable"
    - state: "0"
sort:
  method: state
  numeric: true
  reverse: false

This results in a list separated by columns where it's possible to press a line to replace the battery. The column displaying the name and battery percentage works fine, but of course the tap_action as well as the extra entities that show for each column are static.

Hope there will be a way to accomplish this through templates.