Theme selector issue

Hello,
I have set up an automation to switch between my clear/dark themes at sunrise/sunset. It works fine.

- alias: Appliquer thème en fonction de l'heure
  hide_entity: true
  initial_state: true
  trigger:
    - platform: homeassistant
      event: start
    - platform: state
      entity_id: sun.sun
      to: above_horizon
    - platform: state
      entity_id: sun.sun
      to: below_horizon
  action:
    - service_template: frontend.set_theme
      data_template:
        name: >
          {% if states.sun.sun.state == "above_horizon" %}
            clear
          {% else %}
            clear-dark
          {% endif %}

However, since a few releases of Hassio and with this automation enabled, the theme selector (the dropdown list available in the profile page) does not work well : The theme I manually select is not properly applied. The screenshot below is what I see when I manually switch from a dark theme to the default one.


The manual theme selector will work again if:

  • I disable the automation
  • Explicity call the frontend.set_theme service with the new theme

Has anyone seen this issue before ?
Thank you for your help,
Mat

there’s no trigger in the automation for the input_select?

  - alias: 'Change current theme'
    id: 'Change current theme'
#    initial_state: 'on'
    trigger:
      platform: state
      entity_id: input_select.theme
    action:
      service: frontend.set_theme
      data_template:
        name: >
          {{states('input_select.theme')}}

o wait, you’re talking about the user profile page. Sorry. Tbh, I have that set to backend, and never go there.

If you add the trigger to your automation, you can do it from the lovelace card.

Yes, I am talking about this:


I’d prefer to keep using this option and avoid creating an input_select in the main interface. I do not change themes very often

What I do notice, is that sometimes a page refresh is necessary. Ive always contributed that to CCH , but maybe it is a HA thing.

Please try and see what happens after a theme change?

No, page refresh does not help. I have tried multiple times.
And when the automation is disabled, or when I call the frontend.set_theme service, I don’t need to refresh the page.
Only primary-color and the background color seem to change (only exception is when a background image is used with the initial theme, it still appears on the newly selected theme).
Interesting fact: the new theme is properly applied in the user profile page, developer Tools, Hassio and Configuration menus. The only problem is with the main views.

from what I can see is, if you change the setting in your profile to:

backend-seleted

changing the theme with the service frontend.set_theme is working fine.

2 Likes

Yes, it’s true.
But in the past, even with backend-selected theme chosen by default, I was able to change themes directly with the theme dropdown list. It is not the case anymore.
I opened an issue directly on Github, hope someones looks into that.

In the user profile you must have backend_selected. Then it will work. It’s working properly for me.

Do you mean you can switch from backend_selected to any other theme, from the theme dropdown list in the profile page without any issue ?

yes, this is working fine for me. And even as written above, when backend-selected, switching with automations is working too

Don’t change the theme from the profile page - if you do that it won’t work properly. Leave backend-selected on the profile page and use the service to change theme. I have all my themes in an input select with an automation and then a button and dropdown (2 options in Lovelace) to set the theme. It will also work in automations then as well.

See my themes package here home-assistant/packages/themes.yaml at 48c147d7469c00f8b216078d80c59eb8c6f06d55 · DavidFW1960/home-assistant · GitHub

Then my lovelace:

              - type: custom:button-card
                entity: input_select.theme_switcher
                icon: mdi:palette-outline
                lock:
                  enabled: true
                  duration: 5
                name: Theme
                tap_action:
                  action: call-service
                  service: input_select.select_next
                  service_data:
                    entity_id: input_select.theme_switcher
          - type: entities
            title: Theme Switcher
            show_header_toggle: false
            entities:
              - input_select.theme_switcher

The indenting depends on where you place it in lovelace - my button is in a horizontal_stack hence the indenting is different.

I also do this as since 0.97 this dropdown menu broke for me. I actually opened an issue about this back then, but they said they did not change anything about the code around theming. (apparently they did as that suddenly stopped working). I do know a way how to semi fix that. Only use names used by Home Assistant itself (e.g. --primary-text-color: red or border-radius: 20px something like this does seem to work with the dropdown menu. But as soon as you define some custom names (e.g. button-card-color-off: green it won’t change).

Currently doing it the backend way as well, but it would be nice to have actual per user themes (just like we did a few months ago, which worked like a charm btw).