Auto switch theme to dark for all users/devices

Hi,

I use a device with an older Android version which doesn’t have dark mode.
So, even with the theme set to auto, it is always Light theme…

Is there a solution to switch theme by hour ? Or sunset ?
I found a solution here with an automation that calls the frontend.set_theme service but it is deprecated and doesn’t work…

Thank you and see you soon!

Is it depreciated? It’s still in the docs.

I think he means the example is deprecated.

Try this:


alias: set theme
trigger:
  - platform: state
    entity_id:
      - sun.sun
    to: above_horizon
    id: light
  - platform: state
    entity_id:
      - sun.sun
    to: below_horizon
    id: dark
action:
  - if:
      - condition: trigger
        id: light
    then:
      - service: frontend.set_theme
        data:
          name: here_your_light_theme
    else:
      - service: frontend.set_theme
        data:
          name: here_your_dark_theme

2 Likes

Hi, thanks for your help !
It seems to run ok but doesn’t really work, in fact the theme is still dark wathever the automation set.

I tested the frontend.set_theme service via the tools and there is something strange: if I change the theme and set the mode to dark, it successfully changes the theme but if I do the same thing by setting the mode to light, it doesn’t change the theme at all (I tested with Home Assistant theme and Google theme, which can successfully set in light mode by the user settings).
It could at least change the theme and keep it in dark mode, but no, it doesn’t change the theme at all.

I tested with two users, in user settings theme by default and auto mode (tested with light and dark too).

Edit: Plus, I can see il changes the theme only for my current user, not for the tablets…

That’s why I did not use ‘mode’ in the automation action.

But how can I switch my themes from light to dark and vice versa in this case ?

The automation example above „uses“ 2 themes (not one with light and dark mode): One theme has light colors and the other dark ones.

Ok, I got the point!
Installed Google Light and Google Dark themes separatly and it works.
I didn’t quite understand the light and dark mode either, I thought it was to activate the mode and I’ve just realised that it’s to replace the theme in this mode only…
Thanks for your help!

Hi there @pedolsky , thank you for providing a good solution;

Would it also be possible to shift the time a little, for example “above_horizon + 1 hour” and “below_horizon - 1 hour” ?

Thank you!

I’ve been battling against setting the theme to dark or light mode for the past few hours and then came across this post. Why is there a “mode” setting in the HA docs for “frontend.set_theme” if it is not possible to set it to “dark” or “light”? Is it a bug?

Thanks.

…currently it’s still very cumbersome to simply switch dark/light mode;
Fyi, for people stumbling upon this, related Github issue: