"Dark" theme, or "night" mode/theme

@j.assuncao, @bachoo786, @forsquirel, @DPB61: Here is my automation rule, based on changing an input select box manually and/or automatically. There are of course other ways of accomplishing this, but this works fine for me (and is pretty comprehensible).

Please note however that changing the theme in your configuration frontend UI overrides all of it. So better leave the frontend config (https://your.home.assistant/config/core) theme set to ‘backend-selected’.

frontend:
  themes: !include configuration_themes.yaml # your themes go in this file, or directly below here

input_select:
  hass_template:
    name: Choose template
    options:
     - default
     - day
     - night
    initial: day
    icon: mdi:theme-light-dark

automation:
  # IF: { input_select hass_template is changed by user OR home assistants boots up } THEN: { set theme to state given by input_select.hass_template }
  - id: switch_hass_template
    alias: switch_hass_template
    trigger:
      - platform: state
        entity_id: input_select.hass_template
      - platform: homeassistant
        event: start
    action:
      - service: frontend.set_theme
        data_template:
          name: "{{ states.input_select.hass_template.state }}"

  # IF: { sun.sun goes under horizon } THEN: { set theme to night mode }
  - id: day_to_night_theme
    alias: day_to_night_theme
    trigger:
      - platform: state
        entity_id: sun.sun
        from: 'above_horizon'
        to: 'below_horizon'
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.hass_template
          option: 'night'

  # IF: { sun.sun is up } THEN: { set theme to day mode }
  - id: night_to_day_theme
    alias: night_to_day_theme
    trigger:
      - platform: state
        entity_id: sun.sun
        from: 'below_horizon'
        to: 'above_horizon'
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.hass_template
          option: 'day'
2 Likes