thomasloven / lovelace-layout-card

🔹 Get more control over the placement of lovelace cards.
MIT License
1.08k stars 127 forks source link

Layout-card behavior is inconsistent #145

Closed kamtschatka closed 3 years ago

kamtschatka commented 3 years ago

What I am doing:

I have created a card like this:

type: 'custom:layout-card'
cards:
  - type: entities
    entities:
      - entity: postag.1023060501090050840400
      - type: attribute
        attribute: Latest_Country
        entity: postag.1023060501090050840400
      - postag.1025822102523050240406
      - type: attribute
        attribute: Latest_Country
        entity: postag.1025822102523050240406
layout_type: masonry

This results in a card like this: image

Then there is a description to use the card with auto-entities https://github.com/thomasloven/lovelace-layout-card#use-with-entity-filters:

type: 'custom:auto-entities'
card:
  type: 'custom:layout-card'
  cards: 
    type: entities
    entities:
      - entity: postag.1023060501090050840400
      - type: attribute
        attribute: Latest_Country
        entity: postag.1023060501090050840400
      - postag.1025822102523050240406
      - type: attribute
        attribute: Latest_Country
        entity: postag.1025822102523050240406
filter:
  include:
    - entity_id: postag.1025822102523050240406
    - entity_id: postag.1023060501090050840400

That results in this:

image

So the cards parameter is completely ignored and it is defaulted to the entity card. This is very counter intuitive as the layout-card is usually way more powerful.

The reason for this is that if the entities properties is set, this is mapped and the type is defaulted to „entity“ if it is missing: https://github.com/thomasloven/lovelace-layout-card/blob/master/src/layout-card.ts#L19

My suggestion to fix that problem would be to create a copy of the cards property instead of the entities. This will open a different problem, because naturally people will want to automatically create cards for different entities and each card shows detailed information about this entity. With my second example I would be referencing fixed entities for each card that is created, which is quite useless. So I have created a local patch that will copy the cards and provide the placeholder „+++entitiyid+++“, that will be populated by the layout-card with the current entityid and can then used in every card below it. So the yaml for the sample above would look like this:

type: 'custom:auto-entities'
card:
  type: 'custom:layout-card'
  cards:
    type: entities
    entities:
      - +++entityid+++
      - type: attribute
        attribute: Latest_Country
        entity: +++entityid+++
      - +++entityid+++
      - type: attribute
        attribute: Latest_Country
        entity: +++entityid+++
filter:
  include:
    - entity_id: postag.1025822102523050240406
    - entity_id: postag.1023060501090050840400

The result is the following: image

While I can see why it works like it works, I don't think it is how it should work. What do you think?

sdrapha commented 3 years ago

Hey, I was just passing by, looking for something else, but I thought I could try to help somehow..:

Did you tryed something like this I quickly put together? : ( I did NOT tested it) I use something similar for multiple 'mini-media-players' cards to show multiple chromecast players instances.

type: 'custom:auto-entities'
card:
  type: 'custom:layout-card'
  layout_type: custom:masonry-layout
  layout:
    max_cols: 1
card_param: cards
filter:
  include:
    - entity_id: postag.*
      options:
        type: entities
        entities:
          - entity: this.entity_id
          - entity: this.entity_id
            type: attribute
            attribute: Latest_Country
kamtschatka commented 3 years ago

Hi

Thanks for the comment. I was also playing around a bit today with another problem for a System Monitoring dashboard and after some debugging came to a similar solution. I have not tried it with this particular problem yet, but I think you are correct and it might work. One downside I see is that the "options" only apply to the current section. This works fine:

    - entity_id: postag.*
      options:
        type: entities
        entities:
          - entity: this.entity_id
          - entity: this.entity_id
            type: attribute
            attribute: Latest_Country

This will require me to duplicate the options, as they only apply to "something else":

    - entity_id: <something>
    - entity_id: <something else>
      options:
        type: entities
        entities:
          - entity: this.entity_id
          - entity: this.entity_id
            type: attribute
            attribute: Latest_Country

I would also argue that it is quite counterintuitive that you can specify the card, but it doesn't actually work. Since I found out that theree already is a placeholder "this.entity_id", I will change my implementation to use this as well and make it available.

thomasloven commented 3 years ago

The current behavior is expected and 100% consistent with how auto-entities works with any other card, where the options for each entity is specified in the relevant filter.

The answer by @sdrapha illustrates the correct usage.

Having an option named cardS expect a single card configuration is also bad form.