A different take on designing a Lovelace UI

Well, it was your idea. This makes the text scroll.

state_display: >
  [[[
    return `<marquee>${entity.attributes.football}<\marquee>`;
  ]]]
2 Likes

Where is ‘sensor.template_sidebar’ created, and how does it gets the values?
I can only see one mention of it with no other references

      - type: vertical-stack
        view_layout:
          grid-area: sidebar
        cards:
          - type: custom:button-card
            entity: sensor.template_sidebar
            template: sidebar_template
1 Like

Hi. I have to ask Again. If i change aspect to 4/1 and add square: true in grid it doesnt come together.

Just sharing the beginning of the code to keep it simple.

layout:
  #default
  grid-gap: var(--custom-layout-card-padding)
  grid-template-columns: repeat(4, 1fr) 0
  grid-template-rows: repeat(3, fit-content(100%))
  grid-template-areas: |
    "sidebar  hverdagsrum  opgaveliste     media      "
    "sidebar  temperatur   picture_slide   .          "
    "sidebar  weather      picture_slide   .          "
cards:
  - view_layout:
      grid-area: hverdagsrum 
    type: grid
    title: Hverdagsrum
    square: true
    columns: 2
    cards:
      - type: custom:button-card
        entity: light.spisebord
        name: Spisebord
        aspect_ratio: 4/1

It’s because square should be false

Perfect, fixed it … many Thx Mattias :+1:

Thanks. that pulls it up. But if i still want to maintain a ratio of 1/1. Do i then need to move away from aspect and do width and height procentage?

Where is there a call to template.yaml?

  • template.yaml creates sensor.template_sidebar entity
  • sidebar_template in button_card_templates.yaml
    returns the attributes of the entity

sensor.template_sidebar and sidebar_template are defined in ui-lovelace.yaml

1 Like

I clearly don’t get what you’re asking :woozy_face:

  1. You say that the buttons don’t fit your screen without scrolling
  2. You edit the button aspect ratio and it fits
  3. You don’t want to edit the button aspect ratio
  4. You’re back to square one?

aspect ratio = width/height%

Thanks, I mean where is the !include action for “template.yaml” file?
where is the place that tells this file to load

Ah okay, configuration.yaml

1 Like

Haha. sorry for confusing you. i wanted to keep the aspect-ratio but at a smaller size.
i Thought i good adjust the custom layout grid to fit the cards style. So setting three rows at a specific height and the card would fit itself inside each row and not auto exspand grid so i get the scroller.
Does it give meaning what i am trying to explain? basically i want to make the layout fixed within the resolution size of the screen.

I guess so, you’re talking about grid-template-columns and grid-template-rows?
Use this https://grid-v1.layoutit.com/, I’d use fr/% but if you really need it fixed use px

2 Likes

Did you used the icons as png oder svg?
If png, can you show me your code how you implemented png as icons?

I use the png

state:
  - value: 'on'
    entity_picture: \local\img\icons8-scoop-beleuchtung-48.png
    color: rgba(255,255,255,0.9)
  - value: 'off'
    entity_picture: \local\img\icons8-scoop-beleuchtung-48.png
    color: rgba(65,65,63,0.8)
    styles:
      card:
        - filter: opacity(50%)
      icon:
        - filter: grayscale(100%)

Can sombody explain why this does not work? I wont show the entity_picture.
image

          - type: custom:button-card
            entity: cover.garage_tor
            name: Garage
            tap_action:
              action: toggle
            hold_action:
              action: more-info
            show_entity_picture: true
            entity_picture: \local\img\icons8-closed-window-48.png
            template:
              - base

button_card_template

base:
  variables:
    state: >
      [[[ return entity === undefined || entity.state; ]]]
    timeout: >
      [[[ return entity === undefined || Date.now() - Date.parse(entity.last_changed); ]]]
    light_color: >
      [[[ return entity === undefined ? 'var(--state-icon-color)' : 'var(--button-card-light-color-no-temperature)'; ]]]
    consider_on: >
      [[[
        var state = entity === undefined || entity.state;
        return (
          state == 'on' ||
          state == 'home' ||
          state == 'cool' ||
          state == 'fan_only' ||
          state == 'playing'
        );
      ]]]
  aspect_ratio: 1/1
  show_state: true
  show_icon: false
  state_display: >
    [[[ if (variables.state === true) return 'Unbekannt'; ]]]
  tap_action:
    ui_sound_tablet: |
      [[[
        const screensaver = states['switch.dashboard_screensaver'] === undefined || 
            states['switch.dashboard_screensaver'].state;

        if (variables.state === 'off' && screensaver === 'off') {
          hass.callService('media_player', 'play_media', {
            entity_id: 'media_player.browsermod_dashboard_fullykiosk',
            media_content_id: '/local/sound/on.m4a',
            media_content_type: 'music'
          });
        }
        if (variables.state === 'on' && screensaver === 'off') {
          hass.callService('media_player', 'play_media', {
            entity_id: 'media_player.browsermod_dashboard_fullykiosk',
            media_content_id: '/local/sound/off.m4a',
            media_content_type: 'music'
          });
        }
      ]]]
    animation_card: |
      [[[
        const animation_speed_ms = 900;
        const animation = `card_bounce ${animation_speed_ms}ms cubic-bezier(0.22, 1, 0.36, 1)`;
        this.shadowRoot.getElementById("card").style.animation = animation;
        window.setTimeout(() => {
          this.shadowRoot.getElementById("card").style.animation = "none";
        }, animation_speed_ms)
      ]]]
    action: toggle
    haptic: medium
  styles:
    grid:
      - grid-template-areas: |
          "icon  circle"
          "n     n"
          "s     s"
      - grid-template-columns: repeat(2, 1fr)
      - grid-template-rows: auto repeat(2, min-content)
      - gap: 2%
      - align-items: start
    name:
      - justify-self: start
      - line-height: 115%
    state:
      - justify-self: start
      - line-height: 115%
    card:
      - font-family: Sf Display
      - border-radius: var(--custom-button-card-border-radius)
      - -webkit-tap-highlight-color: rgba(0,0,0,0)
      - transition: none
      - padding: 10%
      - --mdc-ripple-color: >
          [[[
            return (variables.state === 'on' || variables.state === 'home' || variables.state === 'open') ?
              'rgb(0, 0, 0)' :
              'rgba(255, 255, 255, 0.3)';
          ]]]
      - color: >
          [[[
            return (variables.state === 'on' || variables.state === 'home' || variables.state === 'open') ?
              'rgba(0, 0, 0, 0.6)' :
              'rgba(255, 255, 255, 0.3)';
          ]]]
      - background-color: >
          [[[
            return (variables.state === 'on' || variables.state === 'home' || variables.state === 'open') ?
              'rgba(255, 255, 255, 0.8)' :
              'rgba(115, 115, 115, 0.2)';
          ]]]
  extra_styles: |
    [[[
      if (entity) {
        let hs = entity.attributes.hs_color == undefined;
        let h = hs || entity.attributes.hs_color[0];
        let s = hs || entity.attributes.hs_color[1];
        let l_min = 28;
        let l_max = 48;
        let l_calc =
          ((entity.attributes.brightness / 2.54) * (l_max - l_min)) / 100 + l_min;
        var light_color =
          entity.attributes.color_mode === 'color_temp'
            ? `hsl(204, 58%, ${l_calc}%);`
            : `hsl(${h}, ${s}%, ${l_calc}%);`;
      }
      return `
        svg {
          --light-color:
          ${ variables.state === 'on' && entity.attributes.brightness != undefined
              ? light_color
              : variables.state === 'on' && entity.attributes.brightness == undefined
              ? 'var(--state-icon-active-color);'
              : 'var(--state-icon-color);'
          }
        }
        #name, #state {
          font-size: 1.34vw;
          letter-spacing: 0.05vw;
        }
        /* portrait */
        @media screen and (max-width: 1200px) {
          #name, #state {
            font-size: 2vw;
            letter-spacing: 0.05vw;
          }
        }
        /* phone */
        @media screen and (max-width: 800px) {
          #name, #state {
            font-size: 3.1vw;
            letter-spacing: 0.12vw;
          }
        }
        @keyframes card_bounce {
          0% {
            transform: scale(1);
          }
          15% {
            transform: scale(0.9);
          }
          25% {
            transform: scale(1);
          }
          30% {
            transform: scale(0.98);
          }
          100% {
            transform: scale(1);
          }
        }
      `
    ]]]

Because I do not make use of img_cell or i. In that grid area I use the custom_fields icon.

This is without altering the grid

custom_fields:
  icon: >
    <img src="/local/*.png" width="100%">

and like this if you really need entity_picture

show_entity_picture: true
entity_picture: /local/*.png
size: 100%
styles:
  grid:
    - grid-template-areas: |
        "i  circle"
        "n     n"
        "s     s"

Now it is working. Thought it would be something with the grid, but didnt get it.

Hello,
Can you please write a short manual on your github repo for neccessery steps for installation process? Thanks