A different take on designing a Lovelace UI

you can create them as a template from your weather entity attribute or you use it directly in your button-card template like i do. Here an example

  label: >
    [[[
      return `
        <ha-icon icon="mdi:water-percent" style="width: 1em; height: 1em; margin-right: -0.3em;"></ha-icon>
        <span> ${states[entity.entity_id].attributes.humidity}°</span>
        <ha-icon icon="mdi:arrow-up-thin" style="width: 1.1em; height: 1.1em; margin-right: -0.3em;"></ha-icon>
        <span> ${states[entity.entity_id].attributes.forecast[0].temperature}°</span>
        <ha-icon icon="mdi:arrow-down-thin" style="width: 1.1em; height: 1.1em; margin-right: -0.3em;"></ha-icon>
        <span> ${states[entity.entity_id].attributes.forecast[0].templow}°</span>
      `
    ]]]
1 Like

thanks a lot for the answer.

1 Like

Can you confirm that card-mod is installed and working correctly?

Hi, when I click a button I want to open the energy dashboard in an iframe. but it opens the settings page of the energy dashboard. maybe anyone could help me to find the right direction…

Bildschirm­foto 2023-04-25 um 07.54.12

energy_iframe:
  ap_action:
    action: fire-dom-event
    browser_mod:
      service: browser_mod.popup
      data:
        title: ' '
        size: fullscreen
        content:
          type: iframe
          aspect_ratio: 16x9.15
          url: >
            [[[ return `/${hass.panels.config.url_path}/energy` ]]]
  template: icon_name

I can confirm that it is installed.

This is in my config.yaml

lovelace:
  mode: yaml
  resources:
    [
      { url: /hacsfiles/apexcharts-card/apexcharts-card.js, type: module },
      { url: /hacsfiles/bar-card/bar-card.js, type: module },
      { url: /hacsfiles/button-card/button-card.js, type: module },
      { url: /hacsfiles/light-entity-card/light-entity-card.js, type: module },
      { url: /hacsfiles/light-popup-card/light-popup-card.js, type: module },
      { url: /hacsfiles/lovelace-layout-card/layout-card.js, type: module },
      { url: /hacsfiles/lovelace-card-mod/card-mod.js, type: module },

and www/community/lovelace-card-mod/card-mod.js is there.

How can I test if its working? I’ve tried changing the font-size: under h1 { multiple times and nothing is changing on my computer or phone after reloading the frontend theme in dev tools and refreshing the page.

EDIT:
When I change button-card-font-size: 1.0vw in my themes.yaml the font on the buttons does change. That would mean that card-mod is working, correct? I still cant get the card header fonts to change though.

Your url path says something about config:

[[[ return `/${hass.panels.config.url_path}/energy` ]]]

I don’t know if it works, but you could try it without specifying config in your path.

[[[ return `/${hass.panels.url_path}/energy` ]]]
1 Like

You can see if card-mod is installed and working by checking out the chrome console, where it will report the installed version.
image
Although you can add it as a resource, it is recommended to add it as a frontend module. That’s also how it’s added in the original files.

For certain edits to work, I’ve had to do full restarts in HA. I’ve tried the update theme service, and the new reload yaml “restart”, but changes wouldn’t take effect until a real restart. So, I’d recommend doing that to test out edits at first, and once you can confirm that’s working, you can try alternatives.

The card-mod bits are later in the theme file, starting at line 140 in tablet.yaml

The fact that you’ve changed font-size: under h1 { and it hasn’t worked, leads me to believe either card-mod isn’t working correctly, or you need a full restart to see the changes.

Shows that card-mod is installed. Im getting a suboptimal performance warning, even after moving it to my config.yaml and restarted HA.

Still nothing changes when I alter things.

I believe that message is shown even if it’s applied as recommended.

Ct.some((t=>t.endsWith("card-mod.js"))) || console.info("You may not be getting optimal performance out of card-mod.\nSee https://github.com/thomasloven/lovelace-card-mod#performance-improvements");

As for it still not working, you might have to inspect the element and look at the CSS.

In that screenshot, the card-mod h1 element styles override the .card-header styles. You should take a look to see if the card mod styles are even present, and if they are, if they’re being overridden. You might want to try adding a style in tablet.yaml h1 section that is not defined like background-color: hotpink; just to see if that shows up. If that still doesn’t work, share your tablet.yaml file, or at least the code starting from

####################################################
#                                                  #
#                     CARD-MOD                     #
#                                                  #
####################################################

until the SWIPE CARD MARGIN section.

I’m using pirate weather which gives you the attributes a little differently.
How do you write out the attribute when it’s this way?
there is no .forcast[0].templow but a - datetime: ‘2023-04-25T08:00:00+00:00’
How do I access that since the date changes every day.
Or… what do people use for weather these days? since Dark Sky is gone and Openweather doesn’t do temple and high.

Thanks

temperature: 13.5
temperature_unit: °C
humidity: 93
ozone: 323.18
pressure: 1011.7
pressure_unit: hPa
wind_bearing: 187.13
wind_speed: 3.64
wind_speed_unit: km/h
visibility: 12.6
visibility_unit: km
precipitation_unit: mm
forecast:

  • datetime: ‘2023-04-25T08:00:00+00:00’
    precipitation_probability: 0
    wind_bearing: 184.38
    condition: sunny
    temperature: 26.2
    templow: 11.8
    wind_speed: 4.07
    precipitation: 0
  • datetime: ‘2023-04-26T08:00:00+00:00’
    precipitation_probability: 0
    wind_bearing: 242.67
    condition: partlycloudy
    temperature: 18.1
    templow: 11.7
    wind_speed: 8.14
    precipitation: 0

Pirate weather is pretty much a drop-in replacement for dark sky. .attributes.forecast[0].templow is correct. The forecast attribute is actually an array, and you’re referencing the first dataset in the array “[0]” and the templow within that dataset.

Did anyone got a solution for the translation Problem?
image

Till Update 2023.3 or so there was the correct translation.

Edit: Found a workariund with state_display in the base.yaml

  state_display: >
    [[[ if (variables.state === true) return variables.translate_unknown; 
        if (entity.state == 'on') return 'An';
        if (entity.state == 'off') return 'Aus';
        if (entity.state == 'open') return 'Offen';
        if (entity.state == 'opening') return 'Öffnen';
        if (entity.state == 'closed') return 'Geschlossen';
        if (entity.state == 'paused') return 'Pausiert';
        if (entity.state == 'playing') return 'Spielt';
    ]]]
3 Likes

But binary sensors with a set device class still display as ‘on’ or ‘off’ (or in your case ‘An’ and ‘Aus’) correct? I’m not looking forward to having to template every binary sensor in my set up. Or is that not the case?

If I’m reading this correctly, my h1 is getting overridden.

you need to add !important to override the .card-header styles. So for instance
font-size: 2em !important;
Notice how they’re set up in the original tablet.yaml theme file.

This is what I have in my edited “tablet yaml”. And the above screenshot of devtools is what it looks like. I even have the unedited tablet.yaml to switch to and it doesnt look any different.

    #################################################
    #                                               #
    #              GRID CARD HEADINGS               #
    #                                               #
    #################################################
    grid-layout$:
      hui-grid-card:
        .: |
          hui-grid-card {
            padding-bottom: 1vw;
          }
        $: |
          /* default */
          h1 {
            font-size: 6.5vw !important;
            line-height: 0 !important;
            font-weight: 600 !important;
            color: rgba(255, 255, 255, 0.8) !important;
            padding: 0.2vw 0 2vw 0 !important;
            letter-spacing: normal !important;
            width: 100%;
            background-color: hotpink !important;
          }
          /* portrait */
          @media screen and (max-width: 1200px) {
            h1 {
              font-size: 3.3vw !important;
              line-height: 1.1vw !important;
            }
          }
          /* phone */
          @media screen and (max-width: 800px) {
            h1 {
              font-size: 5.5vw !important;
              line-height: 6vw !important;
              margin: 2vw 0 0 0 !important;
            }
          }

I copied the original tablet.yaml and I can change the grid card header font!!! So something is missing in my edited one.

EDIT
I copied my changes into the original tablet.yaml and everything works the way it should.

Thank you so much for walking me through this.

1 Like

It works with binary_sensor, but idk if it works with binary_sensors with a set device class.

footer popup menu has a separator, i lost one between 2nd and 3rd column while i was editing. can anybody tell how can i get it back?

2 Likes

thanks. I found my problem. my middle section was set to have no border in the card-mod section.