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

This works for me:

panel: true
cards:
  - type: custom:layout-card
    layout: grid
    gridrows: auto auto auto #choose your own row heights
    gridcols: 400px 400px    # chosse your own column widths
    cards:
      - type: # card 1 here
        style: "ha-card { height: 100%; }"
        gridrow: 1 / 2
        gridcol: 1 / 2
      - type: # card 2 here
        style: "ha-card { height: 100%; }"
        gridrow: 1 / 2
        gridcol: 2 / 3
      - type: # card 3 here
        style: "ha-card { height: 100%; }"
        gridrow: 2 / 3
        gridcol: 1 / 2
      - type: # card 4 here
        style: "ha-card { height: 100%; }"
        gridrow: 2 / 3
        gridcol: 2 / 3
      - type: # card 5 here
        style: "ha-card { height: 100%; }"
        gridrow: 3 / 4
        gridcol: 1 / 3
3 Likes

Many thanks, that does the job :slight_smile:

1 Like

Iā€™m curious in how I can get this to be responsive across devices. I have been using the grid layout thinking that would be the best approach, but as Iā€™m finding out, something thatā€™s working on a tablet doesnā€™t quite respond well onto a mobile phone. Iā€™m wondering if thereā€™s something Iā€™m missing or doing incorrectly?

cards:
  - cards:
      - entity: sensor.date_time_iso
        gridcol: 1 / 3
        gridrow: 1 / 2
        style: 'ha-card { height: 100%; }'
        type: 'custom:clock-card'
      - gridcol: 1 / 2
        gridrow: 2 / 3
        icon: 'mdi:view-dashboard'
        name: Home Navigation
        style: 'ha-card { height: 100%; }'
        tap_action:
          action: navigate
          navigation_path: /lovelace-nate-development/tablet-home
        type: button
      - entity: weather.kmci
        gridcol: 2 / 4
        gridrow: 2 / 4
        style: 'ha-card { height: 100%; }'
        type: weather-forecast
      - entities:
          - entity: sensor.average_inside_temperature
            icon: 'mdi:thermometer'
            name: Indoor Temperature
          - entity: sensor.wupws_temp
            name: Outdoor Temperature
          - entity: sun.sun
            name: Sun
        show_name: true
        show_state: true
        gridcol: 3 / 5
        gridrow: 1 / 1
        show_header_toggle: false
        style: 'ha-card { height: 100%; }'
        type: glance
      - aspect_ratio: 16x9
        camera_view: live
        entity: camera.front_door
        gridcol: 4 / 5
        gridrow: 2 / 4
        show_state: false
        style: 'ha-card { height: 100%; }'
        type: picture-entity
    gridcols: 180px auto 180px
    gridrows: 180px 200px auto
    layout: grid
    type: 'custom:layout-card'
column_width: 100%
layout: vertical
type: 'custom:layout-card'

Hereā€™s what I have currently. I like this, but if I go to a smaller device, the columns donā€™t "collapse.

Layout grid cannot be responsive by design, because of columns pixel sizesā€¦
You have to use an horizontal layout and probably nested layout-cards.

My bad, you can use % sizes even in grid layout

Just tested this :

layout: grid
gridrows: auto auto auto
gridcols: 30% 30% 30%

and it works :slight_smile:

image

Even though percentages are acceptable, it doesnā€™t allow for example, in row 1 with two columns, and row 2 with three columns, when the screen size decreases, column 3 row 2 doesnā€™t fall below.

I may have to use your previous suggestion to see if i can make that work.

Getting things responsive takes some work and careful thinking.
I donā€™t think grid is the best way to go about it.
Hereā€™s my POC of a responsive view: https://github.com/thomasloven/hass-config/blob/008f62dcb9d95c91556715be36be17b1138b2436/lovelace/views/dashboard_view.yaml



Another way to go about it could be by combining my state-switch card (for switching between different layouts depending on screen width), layout-card (for building the layouts) and q-card (for not having to define the same card several times). Thatā€™s probably easier to fine tune.

@thomasloven, so if I think Iā€™ve gotten something to start working.

I have. a question though. When Iā€™m utilizing vertical is it possible to have something like my image below where row 1 i have two columns, and row two i have three?

The problem I see with how I am trying to do it now is i can add a third column to row 1, but it would be empty and iā€™d prefer the two columns on row one to be fluid from end to end.

I think thatā€™s only possible if you stack layout-cards, i.e.:

type: custom:layout-card
layout: vertical
cards:
  - type: custom:layout-card
    layout: horizontal
    cards:
      - card 1
      - card 2
  - type: custom:layout-card
    layout: horizontal
    cards:
      - card A
      - card B
      - card C

I guess from your deleted post that you realized what rtl stands for, btw?

Ha. Yes! Found out what rtl was standing for. Felt silly once i figured it out. :slight_smile: haha. I will give the stacked layout-cards a try to see if that helps me out. :slight_smile:

@thomasloven , how do the card_options: work? Do you have documentation on the use of that? I havenā€™t been able to find that yet.

card_options are applied to all cards, e.g:

type: custom:layout-card
cards:
  - type: entities
    show_header_toggle: false
    ...
  - type: entities
    show_header_toggle: false
    ...

is equivalent to

type: custom:layout_card
card_options:
  show_header_toggle: false
cards:
  - type: entities
    ...
  - type: entities
    ...
1 Like

Great! I was kind of thinking so, but I wasnā€™t sure.

One thing I can see being super beneficial would be to enable the grid system to work responsively. I like how i can span cards, but they end up being static. Maybe itā€™s not a bit deal and I will just have to live with having a ā€œbig buttonā€ with two other columns next to it, but it would be nice to be able to shrink columns and the others become responsive and slide over.

For now, Iā€™m going to continue trying to make this work.

I use grid quite a bit, but I have to say - itā€™s not the best for truly responsive layouts. Nor can I see how it could be, itā€™s all about placing things exactly where you want - kind of the opposite to responsive.

I use separate dashboards for portrait and landscape, layout cards to control layout and !include for individual ā€˜cardsā€™ that I reuse between views. I also use lovelace_gen to further reuse ā€˜cardsā€™ with different parameters.

My ā€˜cardsā€™ are usually yaml files with embedded layout cards or stack-in-cards with several lovelace cards, controlled by lovelace_gen variables.

A couple of examples here:

Totally understand where the ā€œrepsonsiveā€ grid may not be the best use case there. Iā€™m thinking of it from a bootstrap outlook in a home assistant way.

The biggest thing Iā€™m struggling with now is if I have two columns in row 1, three columns in row 2. column 1 in row 2 maybe isnā€™t as wide as column 2 and three are. if i do that currently, I have to have a big gap between col 1 and col 2 and it just looks odd.

Im having trouble visualising the problem, do you have screenshot and code of it looking wrong?

Is it possible to have something implemented like a ā€œbreakā€ on the horizontal layout @thomasloven?

Again, iā€™m not sure what I"m trying to accomplish is actually achievable without utilizing the grid layout. The only downfall to using the grid layout is responsiveness for me.

Hereā€™s a screenshot where Iā€™m trying a dashboard for my tablet. The problem is I didnā€™t want a huge button and was trying to get it where my weather card and perhaps the camera columns would ā€œadjustā€ and move left where the column ends on the button-card.

type: 'custom:layout-card'
layout: vertical
max_width:
  - 100%
  - 50px
cards:
  - type: 'custom:layout-card'
    layout: vertical
    column_width: 100%
    cards:
      - type: markdown
        content: |
          # Cal-Ped Home
  - type: 'custom:layout-card'
    layout: vertical
    column_width: 50%
    cards:
      - type: markdown
        content: |
          # 12:00:00 AM
      - break
      - entities:
          - entity: sensor.average_inside_temperature
            icon: 'mdi:thermometer'
            name: Indoor Temperature
          - entity: sensor.wupws_temp
            name: Outdoor Temperature
          - entity: sun.sun
            name: Sun
        show_header_toggle: false
        show_name: true
        show_state: true
        style: 'ha-card { height: 100%; }'
        type: glance
        column_width: 100
        max_width: 100%
  - type: 'custom:layout-card'
    layout: horizontal
    column_width: 33.3333%
    cards:
      - type: 'custom:layout-card'
        layout: horizontal
        column_width: 75%
        justify_content: left
        cards:
          - type: button
            icon: 'mdi:menu'
            name: Home Navigation
            style: 'ha-card { height: 100%; }'
            tap_action:
              action: navigate
              navigation_path: /lovelace-nate-development/tablet-home
      - type: weather-forecast
        entity: weather.kmci
        style: 'ha-card { height: 100%; }'
      - type: picture-entity
        entity: camera.front_door
        show_state: false
        camera_view: live
        aspect_ratio: 16x9

good day

When using the layout card, I have the following problem: if I open the
input-select and the selection consists of a long menu that goes beyond the screen, then the screen starts twitching. This can be seen in the attached video.
And without a layout card, there is no defect.
Can this be fixed?

having some scaling issues with layout-card. It seems to stretch the height and width of cards ignoring the direct configuration.

here is the complete card as an example, the second button card is no longer 36px high:

---
id: test3
title: TEST3
icon: mdi:test-tube
panel: true
path: test3
cards:

  - type: custom:layout-card
    layout: vertical
    max_width: [100%]
    cards:
      
      - type: horizontal-stack
        cards:
          - type: "custom:button-card"
            color_type: label-card
            name: Alarm Panel2
            #aspect_ratio: 4/1
            styles:
              card:
                - height: 36px
                - width: 400px

          - type: "custom:button-card"
            #color_type: label-card
            name: Alarm Panel3
            styles:
              card:
                - height: 36px
                #- width: auto
                #- width: 400px