benct / lovelace-multiple-entity-row

Show multiple entity states and attributes on entity rows in Home Assistant's Lovelace UI
MIT License
805 stars 61 forks source link

Templating in the future? #35

Open CodexHere opened 4 years ago

CodexHere commented 4 years ago

Loving the card, but really craving some templating! I've seen others using card-tools to interpret the template for arbitrary config keys - would it be possible to add something like this in the near future?

benct commented 4 years ago

I really don't want to add a dependency (like card-tools) to the card if not absolutely necessary. I've seen others use config templating mods like this to support templates in custom card configs. See issue #31 for an example. Could you maybe try that?

Mariusthvdb commented 4 years ago

id like to add a +1 to the request, and give an example of what I would love to be able to do:

  - type: custom:auto-entities
    card:
      type: entities
      title: Multiple entities
      show_header_toggle: false
    filter:
      include:
        - entity_id: switch.sw*_template
          options:
            type: custom:multiple-entity-row
            state_color: true
            toggle: true
            secondary_info: last-changed
          primary:
            entity: sensor.[[this.entity_id[10:-9]]]_actueel
            name: Actueel
            unit: Watt
          secondary:
            entity: sensor.[[this.entity_id[10:-9]]]_totaal
            name: Totaal
            unit: kWh
          sort:
            method: name

it would be all needed, no further extra custom cards, not even the templater card. It would automatically create 24 + switches like this:

Schermafbeelding 2020-02-10 om 17 39 53

(now made with a decluttering template and as many configs as switches.

Fyi, This would take all switches in my config in the form of

switch.sw_boiler_bijkeuken_template, and have the sensors sensor.boiler_bijkeuken_actueel, and sensor.boiler_bijkeuken_totaal, as multiple entities.

the template format in my example is but a suggestion of sorts, hope it is clear for the purpose.

this is the jinja template:

{{states.switch.sw_boiler_bijkeuken_template.entity_id[10:-9]}}

but it could be in JS too of course.

We might be able to get close using the template-entity-row card, though I dont think it allows for the very nice multiple-entity you provide ;-) hence the support for the FR.

tbh, I wouldn't even know where to start using the config template card used by @SeLLeRoNe thanks for considering

SeLLeRoNe commented 4 years ago

I actually got confused and I provided the wrong response, those variables are taken directly from the Decluttering Card (https://github.com/custom-cards/decluttering-card)

If you use decluttering-card already you just need to send variables: Call the decluttering card like this:

What you can do is a template with decluttering-card for a standard switch (as per your example above) and then a decluttering-card template which call, for each sensor, the decluttering-card again passing as variable the entity to use.

Not really sure if the [10:-9] would work there, if it does, you don't need much more than the decluttering-card existing variables function.

As an example, this is how I generate the "energy view" on each room:

studio_energy:
  card:
    type: custom:vertical-stack-in-card
    cards:
      - type: custom:decluttering-card
        template: title
        variables:
          - title: '[[title]]'
      - type: custom:decluttering-card
        template: room_cost
        variables:
          - area: studio
      - type: divider
      - type: custom:decluttering-card
        template: room_total
        variables:
          - area: studio
      - type: divider
      - type: custom:decluttering-card
        template: room_device_10
        variables:
          - device_name: Desk Andrea
          - device: desk_andrea
      - type: divider
      - type: custom:decluttering-card
        template: room_device_10
        variables:
          - device_name: Desk Sonia
          - device: desk_sonia
      - type: divider
      - type: custom:decluttering-card
        template: room_device_10
        variables:
          - device_name: Table
          - device: studio_table

Basically I call each power monitor device using the decluttering card templates I have ready, sending the two only variables I need to change (this way, if I have a new device, I simply add it here).

So, for now you don't really need templating if you're using the decluttering-card, the only thing I am not sure is the range of numbers [10:-9], the rest it's fairly easy.

Please let me know if that's not clear enough and I can provide you maybe a few examples on your config.

Andrea

Mariusthvdb commented 4 years ago

Im using something like that:

type: entities
title: Switches multiple entity
show_header_toggle: false
entities:
  - type: custom:decluttering-card
    template: switches_multiple_entity
    variables:
      - entity: 'espresso_keuken'

  - type: custom:decluttering-card
    template: switches_multiple_entity
    variables:
      - entity: 'multi_purpose'

  - type: custom:decluttering-card
    template: switches_multiple_entity
    variables:
      - entity: 'vaatwasser_keuken'

  - type: custom:decluttering-card
    template: switches_multiple_entity
    variables:
      - entity: 'quooker_keuken'

  - type: divider

  - type: custom:decluttering-card
    template: switches_multiple_entity
    variables:
      - entity: 'netwerk_auditorium'

etc
etc
etc

with a decluttering card:

card:
  type: custom:multiple-entity-row
  entity: switch.sw_[[entity]]_template
  state_color: true
  toggle: true
  secondary_info: last-changed
  primary:
    entity: sensor.[[entity]]_actueel
    name: Actueel
    unit: Watt
  secondary:
    entity: sensor.[[entity]]_totaal
    name: Totaal
    unit: kWh

my hope was to compact all that to the one config above, if multiple-entity-row would support templating.

and no decluttering only supports strings, no templates of any kind. Did wager a FR with Thomas, but it wasn't accepted (I think)

konikvranik commented 4 years ago

Hello,

thank you for valuable card. I like it and I also appreciated templating posibility, especially to set icon in dependency on the state or attribute.

Mariusthvdb commented 4 years ago

I really don't want to add a dependency (like card-tools) to the card if not absolutely necessary. I've seen others use config templating mods like this to support templates in custom card configs. See issue #31 for an example. Could you maybe try that?

HI @benct Ben, was this a no, or could we temp you to support templates in the fields. It would truly make this a much more versatile and prominent card...

Appreciate your stance to keep the card as independent as possible. Still, have my hopes up for this fundamental piece of support for templating, especially since introducing card-templater or config-template-card would be even more of a complicating factor, relying on external custom cards, on cooperation with the auto entities. Tried that but couldn't get it to work just yet.. maybe not even possible

thanks for considering anyways!

benct commented 4 years ago

I can try to add some sort of fundamental templating support in the next release.

Mariusthvdb commented 4 years ago

great, that would be really awesome! let me know if/how I can help to test, other than providing the templates in my post above https://github.com/benct/lovelace-multiple-entity-row/issues/35#issuecomment-584213191 to give you some thoughts on what could be useful. thanks!

osnwt commented 1 year ago

Any updates? I need to use area and last_changed in local language in my secondary info field using auto-entities card. Since there’s no area attribute, I have to use template with area_name() call. Would be great if secondary_info value could be a template string.

emufan commented 4 months ago

Would be great if secondary_info value could be a template string.

Just here to ask for this as well. Would like to set the value of secondary_info in the way I want/need via template