Different backgrounds for each views

Good day,

I’ve been searching around the forum regarding how to implement a background image for a view. Pretty much all I’ve seen so far is a background set by a theme. My understanding would be that the very same background image would be applied lovelace-wide for every views.

The main goal would be to have a sunny beach background for the Weather view and rackmount servers for the System Information view. I would love to have different backgrounds and, if possible, later on, have different styles so I can arrange the look and feel of each and every views.

So, the very first objective woud be to have different backgrounds. If there is a way to set a theme specific for a view, then that would provide me the best flexibility.

Thanks for your help!

Oh, I’ve found it seems like possible to set a theme for a view… Will be investigating this and report back. (I haven’t think of setting a theme for a view before I started to type this post).

It went partially well… right now, I am unable to make the background image show in the Weather view… but it will show lovelace-wide across all views when selecting the “weather” theme I have created specifically for testing purposes.

I’m absolutely lost… but since I’ve been able to show the background image site-wide, it means the path to the file is correct.

here are the config:

  themes: !include_dir_merge_named themes

inside the folder “themes”, there is a file named weather.yaml:

  background: 'center / cover no-repeat url("/local/background-lovelace/views/weather2.jpg") fixed'
  lovelace-background: 'center / cover no-repeat url("/local/background-lovelace/views/weather2.jpg") fixed'

I’ve used both background and lovelace-background.

When it comes to lovelace, here is the main yaml:

  - url: /local/custom-lovelace/weather-card/weather-card.js
    type: module
  - url: /local/custom-lovelace/mini-graph-card/mini-graph-card-bundle.js?v=0.6.0
    type: module
  - url: /local/custom-lovelace/bar-card/bar-card.js
    type: module
  - url: /local/custom-lovelace/vertical-stack-in-card/vertical-stack-in-card.js
    type: module
  - url: /local/custom-lovelace/card-modder/card-modder.js
    type: js
  - url: /local/custom-lovelace/mini-media-player/mini-media-player-bundle.js
    type: module 
  - url: /local/custom-lovelace/card-tools/card-tools.js
    type: js
  - url: /local/custom-lovelace/button-card/button-card.js
    type: module 
  - url: /local/custom-lovelace/spotify-card/spotify-card.umd.js
    type: module 
  - url: /local/custom-lovelace/layout-card/layout-card.js
    type: module 
  - url: /local/custom-lovelace/compact-custom-header/compact-custom-header.js?v=0.0.1
    type: module

background: var(--lovelace-background)
views: !include_dir_list ui-lovelace/

and in the “ui-lovelace” folder, there is a file named 040-weather.yaml which is the weather view itself:

    title: Weather
    icon: mdi:weather-sunny
    background: var(--lovelace-background)
    theme: clear
      - type: weather-forecast
        entity: weather.home
      - type: entities
        title: Sunlight Information
        show_header_toggle: false
          - sun.sun
      - type: custom:weather-card
        entity: weather.home
        name: Meteo SJSR
        icons: "/local/custom-lovelace/weather-card/icons/"

as you can see, I’ve tried background: var(--lovelace-background) at both the lovelace main YAML and the weather view itself.

Any thoughts would be greatly appreciated because I’m lost. Thank you!

I do this for each of my views… you need to apply the background image per view. The below is taken from my raw config editor for my “Finance” View

  - background: center / cover no-repeat url("/local/money.jpg") fixed
    badges: []
      - entities:
          - entity: sensor.starling_effective_balance
          - entity: sensor.starling_cleared_balance
        title: Finance
        type: glance
      - aspect_ratio: 75%
        title: GBP -> ZAR
        type: iframe
        url: >-
    icon: 'mdi:cash-multiple'
    path: finance
    title: Finance

The key things here are:

  1. Make usre you have your indentation right
  2. Get the image url…

It worked!!! I am able to get the background applied for a view only! Much appreciated! :slight_smile:

you sound surprised :wink: …np

1 Like

hahha well I’ve been struggling for a while… and I was trying to make it work through the theme feature… I was using - background: in the view file but was refering to a theme variable… I haven’t think of literally use that property to actually point directly to the jpg file. :slight_smile:
Glad you took a few minutes!

no worries buddy, that is what we are here for… glad you got it working…

1 Like

Oh, I realized the background: var(--lovelace-background) at the view level was working when I cleared the cache… but only once!

Like, 'say I clear the browser cache, then I’ll log back into HA, and go to the Weather view and the backgroung will show using background: var(--lovelace-background)… but when clicking on another view and THEN going back to Weather, the background isn’t there anymore… it shows the regular white-color background.

Do you know the reason why it would behave like that? I’m much more a core guy than UI… so any thoughts might help! :wink: Setting the background like that would allow me to dynamically change it depending of the actual weather (for example).

I have a solution now that works, but still curious about the behavior I’m having…

I messed around with dynamic/animated backgrounds but then got sidetracked… squirrel! . …

Haven’t looked at it for a while, but have a look here: Lovelace: Animated Background based on entity state

Lovelace is really a lot of CSS, so if you can get your head around that, then generally, just use HACS to get the views etc you need…


Woah thanks again! Will be looking at it later for sure! :slight_smile:

life saver i have been traying to get a .gif file as a background and all i had to do was add the one line you metioned Awesome : " - background: center / cover no-repeat url("/local/money.jpg") fixed " Thank you so much

1 Like

Hi Vjmaz. I have been trying this for about an hour now. I have change the .jpg name but it just blanks the whole view. Where did you put the image?
Does the “local” mean HA will search the whole file locations for the image?

Hi Diligence ( Peter ) local for me was inside the www folder …
So, for example, my home assistant is install on IP … now you need to be able to get to it via ftp or folder share ( I use Folder share with an ADDON called "Samba share " .

\ \config\www\ place pic in here
Hope this helps you I have added pics if that assists.

As you can see I am using a family pic as background on a for a simple Date and Time I wanted in one of my dashboards by using a Picture Elements Card Configuration it allowed me to add my background also adjust the writing locations and color :slight_smile:

have fun

Hope this helped Peter

Regards Maz