I’m trying unsuccessfully to create an automation that toggles between light and dark mode. I think I’m on the right track below. I’ve tried using syntax from the frontend documentation but still can’t get over the finish line.
Keep in mind that this action only affects the default theme used by the frontend, it will not override user-selected themes or dark-light behavior. If you want the actions to work for you, you need make sure the Theme is set properly in your User Profile Settings.
The action you need to use relies on the setting in your actual browser too. If you want to make sure you always get the theme you want, define both the default and dark options in the action:
Are there themes named “dark-theme” and “light-theme” in your themes directory?
IIRC, there’s a service created by Browser Mod that can switch between light and dark mode, but it’s been a while since I used that integration… so that may not be the case anymore.
Yeah there is no way to change the built-in theme light/dark mode automatically. This has been requested repeatedly since it was introduced many years ago - and so far ignored.
You need to define your own dark and light themes to do this.
Well, I installed the darkish and Google Light Themes, but this is still not working. Not sure what is preventing it from working. Using the toggle switch or running the actions directly has no effect.
-Thanks
alias: Toggle Light / Dark Themes
description: ""
triggers:
- id: "on"
trigger: state
entity_id:
- input_boolean.theme_toggle
from:
- "off"
to:
- "on"
- id: "off"
trigger: state
entity_id:
- input_boolean.theme_toggle
from:
- "on"
to:
- "off"
conditions: []
actions:
- if:
- condition: trigger
id: "on"
then:
- action: frontend.set_theme
data:
name: Google Light Theme
else:
- action: frontend.set_theme
data:
name: darkish
mode: single
I tried adding one, then two, frontend.reload_themes, but still the themes are not changing. I read one article that says you have to specify a user. Does the automation below work for you? (Assuming you have the two themes installed).
Both your previous automation without reloads and just name defined and the one with reloads and definitions for both name and name_dark work for me.
Have you double checked that the setting in your user profile is set to use the default theme? Also try setting the mode to Light.
Have you double checked the settings in the actual browser you are using? For me, using Firefox, it seems to work fine with any of the three settings, but that may not be the case with other browsers.