Lovelace background based on state is it possible?

So I have been converting my setup to have instant changes to the interface. For example I use an input_select to set the border-radius of my setup and this can be changes instantly.

However when using backgrounds I can only use themes or hardcode it into lovelace. So if I wanted a single theme to have interchangeable wallpapers I would have to duplicate the same theme over and over again.

Would there be any way to template this based on an input_selects state?

Any idea is welcome.

You can do by calling the frontend.set_theme service. See: https://www.home-assistant.io/components/frontend/#theme-automation

But I don’t know about just changing the background without resetting every setting in the theme.

Yeah that’s the problem.

I don’t see any other way than creating a new theme for each background.

This may not work because you’ll probably need to refresh the page… But you could try to make a custom component that copies images and saves them as a specified name, e.g. /local/image.png. Then have lovelace only look at the /local/image.png. Then use a service to copy the background you want and overwrite /local/image.png.

I doubt it will work. What you’ll ultimately end up needing is something built into lovelace to handle this. It would be a good #feature-requests.

And, just another thought… use anchors, only changing the background.

anchors:
  my_theme_colors: &my_theme_colors
    blah: blah

theme:
  some_theme:
    <<: *my_theme_colors
    # I don't know if these attributes are correct, pulling this out of my ass.  
    # It would be best if you used the correct info.
    background_image: blah 
  some_theme_2:
    <<: *my_theme_colors
    # I don't know if these attributes are correct, pulling this out of my ass.  
    # It would be best if you used the correct info.
    background_image: blah2

I have thought of anchors (though I use mostly includes which would serve almost the same purpose).

I have already thought of this. But it is a bit hacky. For example I have a template for border-radius (as this is possible with both button-card and card-mod). Though the background seems like there is no other way than to create multiple themes and do it via includes or anchors.

I appreciate the input though. I will probably go for the last option with includes/anchors but I really wish it could be selectable without the need of having multiple theme’s set up.

yep, #feature-requests. I’m sure with your following you could get that pretty high on the list in no time.

Was there any #feature-requests follow through on this thread? I’m working on a David Bowie themed mobile dashboard; which, I hope, will give each room in the apartment a Bowie album theme. I use ESPresence for room detection so what I need is exactly what you described.

WIP

Hey guys,

I know this topic is very old, but maybe someone has found a solution.
I would like to know, how I can change the lovelace-background based on state.

I created a sensor and an automation, but absolutly nothing is working, and no, I don’t wanna do that with themes.

The only way I know is via themes and then use a card mod on it. From there you can simply add a template that looks at a certain entity. You could even use input text so you can change it on the fly by entering the filename in that input.

But yeah it does require editing the current theme.

There is a workaround (but definitely not a neat one). It would be using a mod-card (part of card_mod) and then give it a full height and width and fix the card in place. Other cards should be rendered on top of it if you give it a z-index value.