Theme Automation Broken

Hi All,

Okay updated tot he latest version of HA yesterday, and it looks like the themes automation that I had is now broken due to the “light” and “dark” mode of the default theme.

I used to have the ‘default’ theme as my primary theme during the day, and then after sunset I had an automation switch it to a custom dark theme, but that no longer works.

the automation code I had was the following:

name: |
    {% if states.sun.sun.state == "above_horizon" %}
      default
    {% else %}
      slate
    {% endif %}
service_template: frontend.set_theme>

is there maybe a way to use the ‘default’ theme, but just create a automation to switch it between ‘light’ and ‘dark’ mode depending on the state of the sun?

Thanks in advance.

Just out of my curiosity. Having it this way, didn’t you have the issue that although you wanted to have themes you were having to set that on every device?
Or was this working regardless device? In my situation if I login with a user from a new device or session I have to select a theme from there always. It doesn’t remember…

Silvrr posted the values for the default theme the other day. You could save it as a “day” theme and switch to that instead.

No there is no way to do this. It only switches depending on the device dark mode. I asked for it durning the beta and was refused.

1 Like

It would work regardless of device, currently I am the only user on my HA, but if i logged in via Ipad, laptop, android device, the theme would be consistent across devices.

Yep that was my argument too.

I’ve found one way you can do it if you want to switch between a custom dark theme and the default light one without the dark/light toggles showing in the profile.

  1. Create an almost empty theme called something like “light”. The theme can be as basic as:
light:
  dummy-variable: ""

The dummy variable is needed there as a theme needs to be a dictionary. Since this theme doesn’t override anything from the “default” theme, it is effectively the same as “default” but without light and dark options.

  1. Update your automation to call the frontend.set_theme service twice, with mode “light” and “dark” for the same theme, like this:
action:
  - service: frontend.set_theme
    data_template:
      mode: light
      name: |
        {% if states.sun.sun.state == "above_horizon" %}
          light
        {% else %}
          slate
        {% endif %}
  - service: frontend.set_theme
    data_template:
      mode: dark
      name: |
        {% if states.sun.sun.state == "above_horizon" %}
          light
        {% else %}
          slate
        {% endif %}

This makes sure that the same theme is selected whether or not the device is in dark mode.

1 Like

Brilliant, Thanks a stack, will give this a go later today and test it out :slight_smile: