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.
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.
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.
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.
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).