Home Assistant Community

Background image in theme

#1

wondering if anyone out there has added a background image to their theme, I have not been able to get it to work. I can add it to my lovelace config and get it to work, but I have 2 themes, light and dark with an automation and would like to have 2 different backgrounds. this works for only one background in the lovelace config
background: center / cover no-repeat url("/local/background_dark2.jpg") fixed
but not in the theme.yaml file I have, any thoughts?

0 Likes

#2

Are you planing on using your theme with lovelace? In lovelace you can set a background for all views or individual backgrounds for each tab.

0 Likes

#3

I have lovelace setup but not the main frontend yet, basically I can flip the switch but want it the way I want before I do that. I am very close just a few things left. Basically I have the automation set to light for above_horizon and dark for below_horizon. I want all backgrounds to be the same just change for sun up and sun down with the theme change

0 Likes

#4

Did you ever work out a way to do this?

0 Likes

#5

Also interested of this is possible.
Anyon managed to get a result?

0 Likes

#6

Yes, I got a background to work. you have to add this to the root every lovelace view in the raw config editor.

background: var(--background)

So like this:

- title: something
  type: something
  background: var(--background)
  cards:

“–background” being the name you gave in your theme.

1 Like

#7

Ah interesting, so how do you declare the variable within the theme? Something like:
background-image-clear=/local/by.jpg

0 Likes

#8

Yes, I changed it to match the name given above from “background-image-clear” to “background”

I found this info on Clear Theme

1 Like

#9

Sound good, I’ll give it a shot!

0 Likes

#10

This is the exact code in the theme

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

0 Likes

#11

Hi,

I have tried to modify the background image to my own image.

It works perfectly on PC Chrome browser, but not good in mobile app Chrome browser whereby the background image is scaled bigger and become not nice.

So how to solve this issue in order one background image works perfectly on both PC Chrome browser and mobile app Chrome browser?

Thanks.

0 Likes

#12

I think you have to play around with the “center / cover no-repeat” part. I don’t know the values you can change it too but you probably have too search for CSS tags too position images.

Maybe take a look here: CSS image positioning - W3 schools

I don’t know if it will work because I also got the info from a forum post. Let me know if you figure it out!

0 Likes