A different take on designing a Lovelace UI

I Think this should do it…

temperature:
  template:
    - base
  show_state: false
  custom_fields:
    circle: >
      [[[ {
      const temperature = Math.round(entity.state);
      return `<svg viewBox="0 0 50 50"><circle cx="25" cy="25" r="20.5" stroke="#313638" stroke-width="1.5" fill="#FFFFFF08" style="
      transform: rotate(-90deg); transform-origin: 50% 50%;" />
      <text x="50%" y="54%" fill="#8d8e90" font-size="14" text-anchor="middle" alignment-baseline="middle" dominant-baseline="middle" dominant-baseline="middle">${temperature}°</text></svg>`; } ]]]
    graph:
      card:
        type: "custom:mini-graph-card"
        line_color: "#3182b7"
        line_width: 4
        font_size: 75
        show:
          name: false
          icon: false
          state: false
          legend: false
          labels: false
  styles:
    name: [top: 57%, left: 0%, width: 100%, position: absolute]
    custom_fields:
      graph: [bottom: 0%, left: 0%, width: 100%, position: absolute]
      circle:
        - display: initial
        - width: 90%
        - letter-spacing: 0.03vw
        - margin: -6% -6% 0 0
        - justify-self: end
        - opacity: 1
      icon:
        - width: 67%
        - fill: "#9da0a2"
1 Like

Yes friend. Thanks

after updating to HA 2021.9.4 from 2021.8.6, I noticed some problems in the dashboard. sidebar icons are bigger (marked as red). if I click one of them it opens the popup and the icons return to small, as it should be. it happens in chrome and kiosk browser. any one else having this problem? FYI i haven’t update the code for this theme (aug 2021)

From the used fonts it looks like you haven’t selected the “tablet” theme under your user account.
Could you check if the behaviour is still present when you use the correct theme?

i have the tablet theme selected. as before the update.

@wjbridge thanks. I have seen this before. but I have a problem with using new updates from @Mattias_Persson .
after I applied the new update (theme, not HA), all the buttons are destroyed. it looks like this.

I noticed the sidebar_template some styling has been used which is controlling/overriding the style of other buttons also (like lights in the pictures.). for example the #name part (don’t know what is the name for these) exist both in the sidebar and all buttons. so what I write in sidebar_template is overwriting what I wrote before in the base template’s #name section.

      #name {
        padding: 1.8vw 2.5vw 0 var(--custom-layout-card-padding);
        white-space: normal;
        text-align: left;
      }

#name in sidebar

#name in buttons

I guess my problem on the swipe-card temperature is the same.
it’s mostly about the reponsive on the phone version of the home assistant app

1 Like

Hi guys,

i update all Features from Mattias.

One Problem at my View 2.

before:

now:

How can I slide left more to the right?

I am bit confused on this Lovelace UI. How do you get the left side clock and stuff? Is that the dashboard in HA or some type of HA Dashboard? Like the clean layout.

Hi everyone. I cannot solve this problem. The images it shows of people are deformed. It only happens on a miniipad. I imagine it is safary compatibility since it is an old version. But maybe you can modify something in the css that only on the tablet does something different.
This is possible?

If I remove this style on android and pc it doesn’t change. But on the ipad the shape of the image is corrected but it looks square.
#- display: flex

It is part of this specific dashboard
It is not part of Home Assistant by default

You could try adding -webkit- in front of flex for -webkit-flex
Depending on the safari version this might help
Could also try using -webkit-flexbox instead of flex

If the images look square you can try the same
add -webkit- in front of clip-path: circle() so it says: - -webkit-clip-path: circle()

ok, problem solved. it was really a simple one. i needed a dummy button card at the top. because

Note: extra_styles MUST NOT be used on the first button-card of the current view, else it will be applied to all the cards in all Lovelace. It is not possible to fix this behaviour.

now i have a different problem. :frowning:

bottom icons are in at the bottom. i guess the following code is responsible to put it at bottom
image

but the path to this block is different i think in my case. If i set the alignment in following place, then it moves to end. if i right click and copy selector it is “#root > hui-grid-card:nth-child(3)”. how can i fix this?

1 Like

Oh! So how do you get this form of dashboard instead of the default one?

Should read the first post in this thread

So, the out of the box experience should work for everyone
Meaning, if it doesn’t work for you (as with the problems you have) it’s most likely because you are using a different setup, or haven’t merged all the updated files with your files correctly
It’s very hard to help someone troubleshoot their own code, especially when you only see tine snippets of it
So I would advise you to use Matthiases work as your base, and copy over specific parts of your own configuration, testing between edits
That way you start from a working situation and can see when something you change breaks something
You are now doing it the other way around, taking bits and pieces from matthias to replace parts of your existing (working) code, and breaking stuff along the way, it’s much harder to see why/where things go wrong that way
What I’m trying to say is: if you go down this path, you will face error after error after error, when you solve one you will find the next, or might even create more errors with quick patches you apply to solve a previous error.
You might want to try working from the working situation that Matthias created, and go from there

2 Likes

Hello, can you share the motion icon code in the light button? As I understand it, it changes color when moving in the light button to blue? Thanks in advance!

Having a really weird issue, adding some more icons on the sidebar bottom, for some reason they come out all messed up and huge, if I click on one it goes back to normal, but about 20 seconds later on its own they become big and messed up again, here are images when OK and when messed up - any idea. Here is code:

views:
  - type: custom:grid-layout
    path: 0
    layout:
      grid-gap: var(--custom-layout-card-padding)
      grid-template-columns: 0 repeat(4, 1fr)
      grid-template-rows: 0fr repeat(2, fit-content(100%)) 0
      grid-direction: rtl
      grid-template-areas: |
        ".  .        .           .          sidebar"
        ".  kitchen  familyroom  mainfloor  sidebar"
        ".  media    home        home       sidebar"
        ".  footer   footer      footer     sidebar"

    cards:

      - type: custom:button-card #extra_styles fix
      - type: vertical-stack
        view_layout:
          grid-area: sidebar
        cards:
          - type: custom:button-card
            entity: sensor.template_sidebar
            template: sidebar_template

          - type: grid
            cards:
              - type: button
                icon: custom:beginner
                tap_action:
                  action: none
                hold_action:
                  action: none

              - type: button
                icon: custom:advanced
                tap_action:
                  action: navigate
                  navigation_path: /lovelace
                hold_action:
                  action: none

              - type: button
                icon: custom:expert
                tap_action:
                  action: navigate
                  navigation_path: /lovelace
                hold_action:
                  action: none

              - type: button
                icon: custom:roborock-vacuum
                tap_action:
                  !include popup/sidebar_vacuum.yaml
                hold_action:
                  action: none

              - type: button
                icon: mdi:information-outline
                tap_action:
                  !include popup/sidebar_information.yaml
                hold_action:
                  action: none

              - type: button
                icon: mdi:arrow-up-bold-circle-outline
                tap_action:
                  !include popup/sidebar_update.yaml
                hold_action:
                  action: none

sure, here you go.
this is for one motion sensor (kitchen in this case). for a second motion sensor light button, change ‘- light_motion_kitchen’ to something else. and change ‘base_motion_kitchen’ accordingly.

- type: custom:button-card
  entity: light.kitchen_main
  name: Kitchen Top
  template:
    - light_motion_kitchen
    - icon_hue

button_card_template.yaml (additional code to original)

  light_motion_kitchen:
    template:
      - base_motion_kitchen
      - motion
      - hold_action_light

  motion:
    custom_fields:
      motion: >
        [[[
          return `<ha-icon
            icon="mdi:motion-sensor"
            style="width: 20px; height: 20px;">
            </ha-icon>`
        ]]]

  base_motion_kitchen:
    variables:
      motion_timeout: >
        [[[ return states['input_number.motion_timeout'].state; ]]]
      motion_state: >
        [[[ return states['binary_sensor.kitchen_motion_sensor'].state; ]]]
    template:
      - base_motion
    styles:
      custom_fields:
        motion:
          - color: >
              [[[
                if (states['binary_sensor.kitchen_motion_sensor'].state === 'on')
                  return 'var(--primary-color)';
                return "grey";
              ]]]

  base_motion:
    variables:
      state: >
        [[[ return entity === undefined || entity.state; ]]]
      timeout: >
        [[[ return entity === undefined || Date.now() - Date.parse(entity.last_changed); ]]]
      light_color: >
        [[[ return entity === undefined || entity.state === 'unavailable' ? 'var(--state-icon-color)' : 'var(--button-card-light-color-no-temperature)'; ]]]
    aspect_ratio: 1/1
    show_state: true
    show_icon: false
    state_display: >
      [[[ if (variables.state === true) return 'Okänd'; ]]]
    tap_action:
      ui_sound_tablet: |
        [[[
          const screensaver = states['switch.galaxy_tab_a_screensaver'] === undefined || 
            states['switch.galaxy_tab_a_screensaver'].state;

          if (variables.state === 'off' && screensaver === 'off') {
            hass.callService('media_player', 'play_media', {
              entity_id: 'media_player.galaxy_tab_a',
              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.galaxy_tab_a',
              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  motion"
            "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') ?
                'rgb(0, 0, 0)' :
                'rgba(255, 255, 255, 0.3)';
            ]]]
        - color: >
            [[[
              return (variables.state === 'on' || variables.state === 'home') ?
                'rgba(0, 0, 0, 0.6)' :
                'rgba(255, 255, 255, 0.3)';
            ]]]
        - background-color: >
            [[[
              return (variables.state === 'on' || variables.state === 'home') ?
                'rgba(255, 255, 255, 0.8)' :
                'rgba(115, 115, 115, 0.2)';
            ]]]
    extra_styles: |
      #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);
        }
      }