Light/dark theme switcher based on sun

This is a simple blueprint to change your theme based on the sun.sun entity. Make sure to clear any light/dark specific themes first.

blueprint:
  name: Theme switcher
  description: Switch to dark theme when the sun goes down.
  domain: automation
  input:
    light_theme:
      name: Light theme name
      description: What do you call your light theme when you go to choose it?
    dark_theme:
      name: Dark theme name
      description: What do you call your dark theme when you go to choose it?

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: sun.sun

action:
- choose:
  - conditions:
    - condition: state
      entity_id: sun.sun
      state: "above_horizon"
    sequence:
    - service: frontend.set_theme
      data:
        name: !input light_theme
  - conditions:
    - condition: state
      entity_id: sun.sun
      state: "below_horizon"
    sequence:
    - service: frontend.set_theme
      data:
        name: !input dark_theme
6 Likes

If I want to use custom light/dark themes which name would be right to replace it with? Thanks for sharing! :slight_smile:

Could you clarify a bit, or share a screenshot to show what you mean? You add the blueprint, and then you can enter in the names in the fields.

Sorry, didnt understand correctly how it works. Now I got it. Thanks anyway!

It doesn’t work :frowning:
i don’t understand why…
when I call the frontend.set_them service on dev tools it has no effect

ok I must to set “Backend-selected” them on my profile.

I’m super new to HA still, and this blueprint looks pretty awesome, but I’m curious whether it is still required in recent versions of HA?

In my theme settings, there appears to be support for theme switching built in:

image

Does that make this blueprint obsolete, or is there still a need for it? I have noticed that most (maybe all?) 3rd party themes don’t seem to properly support whatever is required for the built-in automatic switching to function, so maybe this blueprint is a workaround for that?

As the title suggests, this is based on sun. So during the night, when the sun has set, it uses the dark theme, and vice versa for light theme. HA’s built-in switching means that if your phone or whatever is configured to use system-wide dark theme, it’ll use dark theme as well.