Invalid automation config

I am trying to split up my home assistant configuration. I used to have:

automation: !include automations.yaml

and my automations in an automation.yaml file which worked absolutely fine.
I’m now trying to split it out into a folder so I added a folder called automation and added the following to the config folder:

automation: !include_dir_named automation/

I have also added a file called ha_night_day_theme.yaml which has the code:

- alias: 'Set HA theme for day and night'
  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" %}
            Light - Navy Blue
          {% else %}
            slate
          {% endif %}

But now when I check my config I get the following error:

Invalid config for [automation]: [ha_night_day_theme] is an invalid option for [automation]. Check: automation->ha_night_day_theme. (See /config/configuration.yaml, line 47)

What am I doing wrong?

Service should probably not be service_template. Just service:

The automation worked absolutely fine before hand, I just pulled it out of the automation file and saved it into a separate YAML file.

I will give it a go though.

Edit: alas no, that didn’t change anything

hmmm…
my config.yaml has the following;
automation: !include_dir_merge_list automation
try that.

I thing you are looking for this:

alias: Set HA theme for day and night
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" %}
          Light - Navy Blue
        {% else %}
          slate
        {% endif %}

Just a formatting issue.

@ThePapaMaan That did the trick! thanks very much. Do you know why !include_dir_named didn’t work? I looked at some of the public configurations and they seemed to include the named version rather than the merge list.

I honestly don’t know mate. The documentation and use cases did not make sense to me last i checked a couple of years ago :laughing: