Day/Night theme switching automation

we are talking about Theme change based on SUN trigger.

Yes. Sure.
Post the automation so we can help
in any case, use this:

    trigger:
      - platform: sun
        event: sunrise
      - platform: sun
        event: sunset

Here

Note, that the below used to work perfectly before the update

event: start
platform: homeassistant
entity_id: sun.sun
platform: state
to: above_horizon
entity_id: sun.sun
platform: state
to: below_horizon
action:
data:
data_template:
name: “{% if states.sun.sun.state == “above_horizon” %}\n Light - Light
\ Red\n{% else %}\n Dark - Light Red\n{% endif %}\n”
service: frontend.set_theme

well, that seems hardly possible… there’s no single spacing in the full automation. you might want to have a look at what’s in the docs and what people post here.

I’ve given you the correct triggers already, in the correct format. Why don’t you start with that and build, using

service: frontend.set_theme
data:
  name: >
    {% if trigger.event == 'sunrise' %} Sunrise theme name
    {% else %} Sunset theme name
    {% endif %}

have a look here, for 2 automations to give you an idea how things work:

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

  - alias: Sun based theme change
    id: Sun based theme change
    trigger:
      platform: state
      entity_id: sensor.sun_based_theme
    condition:
      condition: numeric_state
      entity_id: sensor.uptime_minutes
      above: 1
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.theme
          option: >
            {{states('sensor.sun_based_theme')}}
      - condition: state
        entity_id: input_boolean.notify_system
        state: 'on'
      - service: notify.system
        data:
          title: >
            Ha Rpi4: Sun based Theme
          message: >
            {{as_timestamp(now())|timestamp_custom('%X')}}:
            Sun is {{states('sun.sun')}} and Frontend is set to '{{states('sensor.sun_based_theme')}}'

Hello,

any idea why this is unsuccessful ?

the theme is not set, nothing change. and no error in the logs

2 Likes

Also not working for me; not sure what is wrong or what changed?

Anyone have a working automation that is in a single automation (not separate)?

Good day, this must be a bug.
this definitely doesnt work.
I’ve set theme to back end selected and does nothing.

Hey,
this one has worked for me for years

- id: theme_change
  alias: Theme Change
  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: frontend.set_theme
      data_template:
        name: >
          {% if states.sun.sun.state == "above_horizon" %}
            ios-dark-mode-light-blue-alternative
          {% else %}
            ios-dark-mode-blue-red-alternative
          {% endif %}

I want to change the background theme based on my solar production. That is, if I am producing over 5KW theme color changes to green else remains red. Can this be done and if so how. I am aware of sun condition of day/night but that seems embedded with HA and is not what I am after.