Sub YAML files that get loaded in configuration.yaml

I know, that in much like the web languages I am used to, there are ways to write sub files and have them all loaded in a main file saving you form having 1 main file with 1 trillion lines of code.

I see stuff like script: !include scripts.yaml but I’m not sure how exactly how to name the include files. For instance:

tysensors:
count_sensor:
friendly_name: "Since Day 0"
value_template: "{{ states('sensor.count_sensor') | int + 1 }}"
initial: 4


count_sensor2:
friendly_name2: "Count"
value_template2: "{{ states('sensor.count_sensor2') | int + 1 }}"
initial2: 1


light:
  - platform: switch
    name: "Dummy Light"
    entity_id: switch.dummy_light
  - platform: switch    
    name: "Bed Time"
    entity_id: switch.bed_time
  - platform: switch
    name: "Tally Up"
    entity_id: switch.tally_up
    
switch:
  - platform: template
    switches:
      dummy_light:
        friendly_name: "Dummy Light Switch"
        value_template: "{{ is_state('input_boolean.dummy_light_state', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          target:
            entity_id: input_boolean.dummy_light_state
        turn_off:
          service: input_boolean.turn_off
          target:
            entity_id: input_boolean.dummy_light_state
            
      bed_time:
        friendly_name: "Bed Time Light Switch"
        value_template: "{{ is_state('input_boolean.bed_time_state', 'on') }}"
        turn_on:
          service: input_boolean.turn_on
          target:
            entity_id: input_boolean.bed_time_state
        turn_off:
          service: input_boolean.turn_off
          target:
            entity_id: input_boolean.bed_time_state
            
      tally_up:
        friendly_name: "Tally Up"
        value_template: "{{ is_state('input_boolean.tally_up_state', 'on') }}"
        turn_on:
            service: input_boolean.turn_on
            target:
                entity_id: input_boolean.tally_up_state
        turn_off:
            service: input_boolean.turn_off
            target:
                entity_id: input_boolean.tally_up_state
                
# YAML for the Template Sensor (in templates.yaml or configuration.yaml)
input_boolean:
  dummy_light_state:
    name: Dummy Light State
    initial: off
    
  bed_time_state:
    name: Bed Time State
    initial: off
    
  tally_up_state:
    name: Tally Up State
    initial: offpe or paste code here

I would really like to clean that up into 2 or 3 files.
As you can tell I am pretty new to YAML so any pointers on anything in that example I could have done cleaner would also be helpful to me.
Oh, also, are there any good linters for YAML out there? tried a few that seemed to confuse me more than help me learn.

you can name your file as you like but you need this format

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
switch: !include switch.yaml
binary_sensor: !include binary_sensor.yaml
mqtt: !include mqtt.yaml
group: !include group.yaml
template: !include template.yaml
climate: !include climate.yaml

and create your file

and on your file

- platform: generic_thermostat
  name: Clima Sammy
  unique_id: clima_sammy
  heater: switch.aire_sammy  # ← tu switch (puede ser un enchufe o relé)
  target_sensor: sensor.sammy_temperature  # ← tu sensor de temperatura
  ac_mode: true
  min_temp: 20
  max_temp: 42
  target_temp: 26
  cold_tolerance: 0.5
  hot_tolerance: 0.5
  min_cycle_duration:
    minutes: 5
  initial_hvac_mode: "cool"
  away_temp: 33
  sleep_temp: 25
  eco_temp: 28

make sure you doble check your indentention

as a linters you can try gemini or chatgps but only as reference as sometimes use older version of homeassistant

The Packages option is mentioned in the docs above, but it tends to be missed and I find it to be the most intuitive method…

1 Like

Here a Screen Shot of mine

I have started using

!include_dir_merge_list

this will load al files in said folder

in my mqtt\light folder I have to files make it easier to find read LOL

1 Like

This is actually really nice and clean option, I complete miss the

include_dir_merge_list

+1 on packages

yeap they cool also creat for grouping EVERYTHING in one place but

have to do a full restart i think each time you change something.

Reload works, just need to know what you changed.

When changing package stuff
mite of changes havent had to play with my package for a lonnnng time

JUst remeber saving bloody not working ooooooooooooo reload it that right

think thats showing my age in here tho days still haunt me LOL