šŸ”¹ Layout-card - Take control of where your cards end up

Hi janick, many thanks for your reply but not quite what Iā€™m after in terms of rendering. Definitely hits the mark with the blank position though.
I donā€™t want the cards across a row to look they are cards. With the base Entities card there is no discernible card style rendering of the rows.
So a row of two columns showing temperature sensor values:

<icon> Inside              22            <icon> Outside                  16
       8 minutes ago                            20 minutes ago

just appears like a nicely formatted table and not two entities with bevelled boxes.
Many thanks for your suggestion.

Any chance for you to provide some rendering as to what this should look like.

Like, what do you want it to exactly look like basically ?

Can you share something like that perhaps ?

Hi dexstar,

Essentially I want it to function and display exactly like the native Entities Card except allow columns.
So a column count of 1 would be no different to the native Entities Card. A column count of 2 would place the second nominated entity to the right of the first nominated entity etc.
Other than the columnar layout, no different presentation to native Entities Card.
Iā€™ll cobble a picture together tomorrow.

Thanks.

Iā€™m not sure if this will achieve exactly what you want, but you can do something like this with native entities cards, and vertical and horizontal stack cards.

The trick is to use Thomas Lovenā€™s hui-element card, which allows you to use core cards as entities in a standard entity card.

So something like this:

  - type: entities
    title: "<Main Card with Title>"
    entities:
      - type: custom:hui-element
        card_type: horizontal-stack
        cards:
          - type: vertical-stack
            cards:
              - type: entities
                title: "<First column>"
                entities:
                  - <your-entity-here>
          - type: vertical-stack
            cards:
              - type: entities
                title: "<Second column>"
                entities:
                  - <your-entity-here>

In this case, you would probably want to use card-mod to remove the background on the ā€˜childā€™ entities cards, and maybe reduce the padding too. Itā€™s pretty easy to do, but if you adopt this approach, let me know if you need code examples.

Hi Chris,
Many thanks.
This sounds like what I am trying to achieve but canā€™t get back to it for a week or so to give it a try.
Iā€™ll need to figure out how to leave a blank position for a child entity.
Iā€™ll check out the hui-element card but Iā€™d love to get a coding example. Iā€™m not very experienced with CSS.
Thanks, Todd.

Glad to be of help. Iā€™ll reply now even though you wonā€™t see this for a week or so, just in case I forget.

You can set an empty entities card like this:

- type: entities
  title: "<Second column>"
  entities: []

Using card-mod to remove background and box-shadow, and reduce the padding from the default 16px on an entities cards would look something like this (you need to set the padding separately for the title area, and for the main content area):

- type: entities
  card_mod:
    style: |
      ha-card {
        background: none;
        box-shadow: none;
      }
      h1.card-header {
        padding: 8px;
      }
      div#states.card-content {
        padding: 8px;
      }
  title: "<Second column>"
  entities: []

Hereā€™s a screenshot combining the code from my 2 posts (with default theme, and default column width within a layout-card set as custom-vertical-layout for the whole dashboard view):

Untitled

Recently started with the layour-card and Iā€™m puzzled by the following.

I use the layout card to control the width of a grid card. In the grid card there are 4 columns each containing a button-card that it 200px wide. The total width of the grid card is 836px (apparently there is 12px space between the columns).

To fit this in the layout card I need to specify a width of 560ā€¦ almost precisely 2/3 of 836.

Stripped down the yaml is:

title: Home
views:
  - theme: Backend-selected
    path: default_view
    title: Home
    type: custom:masonry-layout
    layout:
      width: 560
    badges: []
    cards:
      - type: vertical-stack
        cards:
          - type: grid
            columns: 4
            square: true
            cards:
              - type: custom:button-card
                styles:
                  card:
                    - height: 200px
                    - width: 200px
                entity: light.bulb1
              - type: custom:button-card
                styles:
                  card:
                    - height: 200px
                    - width: 200px
                entity: light.bulb2
              - type: custom:button-card
                styles:
                  card:
                    - height: 200px
                    - width: 200px
                entity: light.bulb3
              - type: custom:button-card
                styles:
                  card:
                    - height: 200px
                    - width: 200px
                entity: light.bulb4

Apparently Iā€™m overlooking something trivialā€¦ but what?

Iā€™d like to have the layout work like the horizontal but vertically. Vertical option doesnā€™t seem to do what I mean as it just puts all cards in one long column. I want the cards to be added to each column at the bottom until they would end up below the fold, then add to a new column. In theory I could force this with layout-break cards but the issue is I want the break to depend on the height of the screen. Is there a way to do this?

Sorry if this was already covered in this thread, I tried searching but didnā€™t find anything.

I have been trying to use it to display my lights on a Dashboard. But the results are inconsistent based on the device. What am I doing wrong?

This is the code I use:

type: custom:mod-card
view_layout:
  grid-column: 2 / span 1
  grid-row: span 1
card:
  type: custom:layout-card
  layout_type: custom:grid-layout
  layout:
    grid-template-columns: 1fr 1fr 1fr 1fr
    grid-template-rows: auto
  cards:
    - type: custom:mushroom-title-card
      title: Living
      view_layout:
        grid-column: 1 / span 2
    - type: custom:mushroom-title-card
      title: Kitchen
      view_layout:
        grid-column: 3 / span 1
    - type: custom:mushroom-title-card
      title: Porch
      view_layout:
        grid-column: 4 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.family_room_light
      icon: mdi:sofa-outline
      name: ' '
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 1 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.tv_backlight_led
      icon: mdi:television
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 2 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.kitchen_light
      icon: mdi:food
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 3 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.porch_light
      icon: mdi:car
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 4 / span 1
    - type: custom:mushroom-title-card
      title: Office
      view_layout:
        grid-column: 1 / span 1
    - type: custom:mushroom-title-card
      title: Dining
      view_layout:
        grid-column: 2 / span 2
    - type: custom:mushroom-title-card
      title: Sunroom
      view_layout:
        grid-column: 4 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.office_light
      icon: mdi:laptop
      name: ' '
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 1 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.dining_table
      icon: mdi:table-chair
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 2 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.dining_backdoor
      icon: mdi:silverware
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 3 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.sun_room_light
      icon: mdi:weather-sunny
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 4 / span 1
    - type: custom:mushroom-title-card
      title: Porch
      view_layout:
        grid-column: 1 / span 1
    - type: custom:mushroom-title-card
      title: Hall
      view_layout:
        grid-column: 2 / span 1
    - type: custom:mushroom-title-card
      title: Attic
      view_layout:
        grid-column: 3 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.porch_light
      icon: mdi:car
      name: ' '
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 1 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.hall_bathroom
      icon: mdi:light-recessed
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 2 / span 1
    - type: custom:button-card
      state:
        - value: 'on'
          color: yellow
      tap_action:
        action: toggle
      entity: light.attic_light
      icon: mdi:home-roof
      name: Guest
      show_name: false
      aspect_ratio: 1/1
      view_layout:
        grid-column: 3 / span 1

This is the result on PC and Tablet. The last column displays the button bigger than the other buttons:

This is the result on iPhone. There are no two buttons with the same size:

It it possible to build a responsive view that uses a horizontal stack when on desktop

image

but then collapses to a vertical stack on mobile?

yes, grid layout. More than a lot examples in this thread.

The documentation specifically describes how this can be done using the grid layout with the mediaquery option.

What a great Tool! I managed to define a (responsive) Header-Layout, awesome!

But in Grid-Layout, is there a Way to define that all later coming Cards are either treated in a different Layout (e.g. Mansory)? Or at least define ā€œfrom Row 4 on, always use xxxxā€?
By now, i have it set up like this:

grid-template-columns: 50% 25% 25%
grid-template-areas: |
  "main info home"
  "banner banner sub"
  "content1 content1"
  "content2 content2"
  "content3 content3"
  "content4 content4"
  "content5 content5"
  "content6 content6"
  "content7 content7"
  "content8 content8"

When playing around with Content, it is rather annoying to always add/edit the view_layout.
There is the Workaround by using a Vertical-Stack Card. But i do have already nested Stack Cards, it gets really confusing.
So, is there an Option i missed to ā€œfor all Cards after ā€˜subā€™ use following Layout?ā€

Hi @thomasloven
Thanks for this great card, iā€™ve used it to create this tablet dashboard below.
I have some slider cards that open some conditional cards but as you can see from the screenshots if one of the cards is longer it extends the sidebar .
Which way would you recommened to fix the resoluton or even keep the sidebar fixed and have the right hand side produce a scroll bar
Thanks
Steve


2 Likes

help. please.

Soo, this (see attached image) grid is a basic grid.
And I cannot for the love of me sort this out in Layout Card instead.

Could someone please help me out with the code?
The thing is that I want to set each horizontal row height.
Best regards

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    subtitle: Vardagsrummet
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: line
        type: sensor
        entity: sensor.vardagsrum_temp
        detail: 1
        name: VDR
      - square: false
        columns: 2
        type: grid
        cards:
          - type: custom:mushroom-entity-card
            entity: binary_sensor.vardagsrum_rokdetektor
            layout: vertical
          - type: custom:mushroom-entity-card
            entity: binary_sensor.vardagsrum_rorelsesensor
            layout: vertical
            secondary_info: last-changed
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-light-card
        entity: light.vdr_hyllan
        layout: vertical
        name: Glasboll
        icon: mdi:web
      - type: custom:mushroom-light-card
        entity: light.tv_rum
        layout: vertical
      - type: custom:mushroom-light-card
        entity: light.soffan_nere
        layout: vertical
  - type: custom:mushroom-light-card
    entity: light.vardagsrummet
    show_brightness_control: true
    use_light_color: false
    layout: horizontal

image

1 Like

installed this via HACS, added as a resource, but Iā€™m not seeing any config issues in the dashboard views

Iā€™m guessing it may not have been updated as yet to work with 2022.4.7?

Hi,

I have the following view:

  - path: something
    type: custom:grid-layout
    layout:
      grid-template-columns: auto 30% 
      grid-template-rows: auto
      grid-template-areas: |
        "main sidebar"
      mediaquery:
        "(max-width: 600px)":
          grid-template-columns: auto
          grid-template-areas: |
            "sidebar"
            "main"
    cards:
      - type: custom:layout-card
        layout_type: custom:vertical-layout
        view_layout:
          grid-area: sidebar
        cards:
          - type: picture-entity
            ...
          - type: horizontal-stack
            cards:
              - type: gauge
                ...
              - type: gauge
                ...
              - type: gauge
                ...
          - type: entities
            entities:
              ...
          - type: entities
            entities:
              - type: custom:hui-element
                card_type: glance
                entities:
                  ...
              - type: custom:hui-element
                card_type: glance
                entities:
                  ...

      - type: custom:layout-card
        layout_type: custom:vertical-layout
        view_layout:
          grid-area: main
        layout:
          width: 800
        cards:
          - type: custom:apexcharts-card
            ...

          - type: custom:apexcharts-card
            ...

          - type: custom:apexcharts-card
            ...

And it works almost perfectly, but I cannot force the charts in the main area to occupy the whole width of the area. The only way I can make the charts bigger is by specifying an absolute width in the vertical layout properties, but itā€™s not right and breaks smaller displays like a smartphone.

Any ideas? Or perhaps Iā€™m using the grid layout incorrectly in the first place? I mean, what if there is a way to stack cards in the grid without using inner vertical layouts?

Thanks.

Sorry if Iā€™m giving you information you already know: I see youā€™re using the core horizontal-stack cards successfully - have you tried using core vertical-stack cards instead of the ā€˜innerā€™ layout-cards?

For even greater control over vertical and horizontal stacking within a custom-layout card view, thereā€™s also RomRiderā€™s custom stack-in-card, which can be used for both horizontal and vertical stacking, and also can be more easily styled (e.g backgrounds, borders) if youā€™re comfortable using Thomas LovĆ©nā€™s card-mod card, as custom stack-in-card has an ha-card element.

I canā€™t believe it was so simpleā€¦ Thank you so much! I will also check stack-in-card too.

Is it possible to define a background color for a ā€˜custom:layout-cardā€™ with a ā€˜gridā€™?

I am using a grid within a vertical-stack and I would like this grid card to have a background color (but I donā€™t want to color the grid areas but rather the parent).
Maybe I should be giving the second row of the vertical-stack the background color, but I would have thought I can give this to the grid card.

  type: vertical-stack
  cards:
    - type: custom:button-card
.
.
    - type: custom:layout-card
      layout_type: grid
      layout:
        grid-template-columns: 2fr 1fr 1fr 1fr
        grid-template-rows: 1
        grid-template-areas: |
          "main1 main2 main3 main4"      # basically this row should have a background color spaning the entire row
      cards:
        - type: entities