Skip to content

folke/lovelace-styler

Repository files navigation

🎨 Lovelace Styler

Plugin to customize the styling of Lovelace cards.

✨ Features

⚡ Performance

Great care has been taken to minimize the overhead of this plugin. This plugin works by hooking into Lit's reactive life-cycle using ReactiveElement.addInitializer and a custom Reactive Controller that only runs once per card in the hostUpdated live-cycle callback.

📦 Installation via HACS

Have HACS installed, this will allow you to update easily.

  • Adding Styler to HACS can be done using this button:

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

(If the button above doesn't work, add https://github.com/folke/lovelace-styler as a custom repository of type Integration in HACS.)

  • Click Download on the HACS page
  • Reload the Home Assistant web page

🚀 Usage

Style any component as a card

type: vertical-stack
styler:
  card: true
cards: ...

type: grid
styler:
  card: true
cards: ...

type: custom:layout-card
styler:
  card: true
cards: ...

Remove card styling from any card

type: mushroom-light-card
entity: light.my_light
styler:
  card: false

Apply custom CSS to any component

type: mushroom-light-card
entity: light.my_light
styler:
  style: |
    .card {
      border-color: red;
    }

Configuring the sections view

With styler, it's fairly easy to configure some options related to the sections view.

The example below sets the grid gap to 10px and the maximum number of sections to 2.

title: Home
type: sections
styler:
  style: |
    .container {
      --column-gap: 10px !important;
      --column-max-width: 100hw !important;
      --max-column-count: 2 !important;
    }
sections: ...

Tile Card Customization

type: tile
info: false # hides the info section, so only shows the icon
animation: spin # adds a spinning animation to the icon
animation: pulse # adds a pulsing animation to the icon

🏠 Advanced Example

The code below was used to create the two room cards in the screenshot above. The example code uses the Mushroom Custom Cards.

Living Room Card

type: horizontal-stack
layout_options:
  grid_columns: 2
styler:
  card: true
cards:
  - type: custom:mushroom-template-card
    primary: Living Room
    secondary: "{{ states('sensor.netatmo_living_room_temperature_2') | round(0) }} °C"
    icon: mdi:sofa
    icon_color: pink
    tap_action:
      action: navigate
      navigation_path: downstairs
    styler:
      style: |
        mushroom-state-info { min-height: 150px }
        ha-card { --icon-size: 130px }
        mushroom-shape-icon {
          position: absolute;
          margin: -20px -25px;
        }
  - type: grid
    columns: 1
    square: false
    styler:
      style: |
        :host {
          flex: 0 0 auto !important;
          margin: 12px;
        }
    cards:
      - type: tile
        info: false
        entity: light.group_lounge
      - type: tile
        info: false
        entity: binary_sensor.presence_living_room
        color: blue

Upstairs Card

type: horizontal-stack
layout_options:
  grid_columns: 2
styler:
  card: true
cards:
  - type: custom:mushroom-template-card
    primary: Upstairs
    secondary: "{{ states('sensor.netatmo_upstairs_temperature_3') | round(0) }} °C"
    icon: mdi:bed
    icon_color: brown
    tap_action:
      action: navigate
      navigation_path: downstairs
    styler:
      style: |
        mushroom-state-info { min-height: 150px }
        ha-card { --icon-size: 130px }
        mushroom-shape-icon {
          position: absolute;
          margin: -20px -25px;
        }
  - type: grid
    columns: 2
    square: false
    styler:
      style: |
        :host {
          flex: 0 0 auto !important;
          margin: 12px;
        }
    cards:
      - type: tile
        info: false
        entity: alarm_control_panel.upstairs
      - type: tile
        info: false
        entity: light.group_all_upstairs
      - type: custom:mushroom-template-card
      - type: tile
        info: false
        entity: binary_sensor.presence_upstairs
        color: blue
      - type: custom:mushroom-template-card
      - type: tile
        info: false
        entity: fan.ventilos