Splitting out configuration.yam (stuck on templates)

so… I’ve been at this for days now, scouring the web, this forum, youtube…etc for how to properly split out my configuration. I’ve tried mimicing Frenck’s, pinkwafer, ccostan, beardedthinker. This biggest issue in this has been the youtube videos are too old and no longer match their github mappings, plus the fact that home assistant has grown leaps and bounds. So there seems to no longer be a “great” guide to this anymore.

My largest obstacle is remaining is trying to get my “new format templates” into /config/entities/templates/[folder]/template-name.yaml

Here is an example (currently in my configuration.yaml)

# SENSORS (new format) 
template:
  - sensors:
      ## HUUM Template
      sauna_temperature:
        value_template: "{{ state_attr('sensor.sauna_status', 'temperature') }}"
        device_class: temperature
        unit_of_measurement: "C"

      sauna_target_temperature:
        value_template: "{{ state_attr('sensor.sauna_status', 'targetTemperature') }}"
        device_class: temperature
        unit_of_measurement: "C"

      sauna_door:
        value_template: >-
          {% set state = state_attr('sensor.sauna_status', 'door') %}
          {% if state == true %}Closed
          {% elif state == false %}Open
          {% else %}Unknown{% endif %}

      sauna_light:
        value_template: >-
          {% set state = state_attr('sensor.sauna_status', 'light') %}
          {% if state == 0 %}off
          {% elif state == 1 %}on
          {% else %}Unknown{% endif %}

      sauna_statuscode:
        value_template: >-
          {% set state = state_attr('sensor.sauna_status', 'statusCode') %}
          {% if state == 230 %}Offline
          {% elif state == 231 %}on
          {% elif state == 232 %}off
          {% elif state == 233 %}Blocked
          {% elif state == 240 %}Emergency
          {% else %}Unknown{% endif %}

      huum_temperature:
        friendly_name: 'HUUM Temperature'
        unit_of_measurement: F
        device_class: temperature
        value_template: "{{ ((states('sensor.sauna_temperature') | float) * 9 / 5) + 32 }}"

      huum_target_temperature:
        friendly_name: 'HUUM Target Temperature'
        unit_of_measurement: F
        device_class: temperature
        value_template: "{{ ((states('sensor.sauna_target_temperature') | float) * 9 / 5) + 32 }}"

      huum_sauna_door:
        friendly_name: 'HUUM Door Sensor'
        value_template: >
          {% set state = states.sensor.sauna_door.state %}
          {% if state == 'Open' %}Open
          {% elif state == 'Closed' %}Closed
          {% endif %}

        icon_template: >
          {% set state = states.sensor.sauna_door.state %}
          {% if state == 'Open' %}mdi:door-open
          {% elif state == 'Closed' %}mdi:door-closed
          {% endif %}

…and in /config/entities/templates/huum/
What is the best way?
Have a separate file for each template sensor?
Or one large file containing them all?

Oh, BTW, here is the definition for templates in /config/packages/templates.yaml

bash-5.1# cat ../../../packages/templates.yaml
---
#  Templates / Test Sensors
#
#
template: !include_dir_merge_list ../entities/templates

Will also note, I have several “old” format templates pulling up fine, just something different I am not getting yet in how to present the “new” format.

Any help is much appreciated.

Out of curiosity: Is there a certain reason why you want several directories for your templates and not using the existing (?) packages directory?

as I understood things…
/config/packages is mostly pointers to help the split configuration take place.
I might have a few expanded configs in it, but most of the meat/potatoes are in /config/entities//

…and I am not opposed to a flat file config either. I couple/few working examples would be great to see.

Usually the greatest guide is the documentation, not some tired video. Splitting up the configuration - Home Assistant

Just to make sure we’re on the same page, there’s nothing special about /config/packages or /config/entities. HA does not inherently look for those folders, they do nothing unless you !include them somehow in configuration.yaml.

So given that, do you want each sensor in its own file? If so then don’t bother with packages. Just put this in your configuration.yaml:

template: !include_dir_merge_list entities/templates
automation yaml: !include_dir_merge_list entities/automations
scene yaml: !include_dir_merge_list entities/scenes
...

Some like scripts will be merged into an object instead of an array. Use !include_dir_named if you want the file name to be the ID of the script. Or use !include_dir_merge_named if you prefer to put the ID of the script in the file.

Or do you prefer to group entities by some logical concept rather then simply by type? If so then use packages. If you prefer a single yaml file per package then add something to your configuration.yaml:

homeassistant:
  packages: !include_dir_named packages

And put a yaml file per package in that folder. Or if you prefer a folder per package and then a file per type of thing in that folder then do this:

homeassistant:
  packages:
    pack_1: !include_dir_named packages/pack_1
    pack_2: !include_dir_named packages/pack_2
    ...

Or split this part out into a packages.yaml file. Or do something else entirely.

There’s no magic here. You have these tools available to split the config. For a file to actually be included in your config you must be able to trace a path of !include statements from it back to configuration.yaml. Use those tools to organize your config in whatever way makes it easiest for you to manage.

I‘ll have different files for my template sensors. Based on the nature of the sensor

to clarify, offer more info on my setup…

bash-5.1# grep packages configuration.yaml
  packages: !include_dir_named packages

bash-5.1# pwd
/config/packages

bash-5.1# ls
automations.yaml      device_tracker.yaml   google_calendar.yaml  input_number.yaml     logger.yaml           scenes.yaml           switch.yaml
bhyve.yaml            discovery.yaml        group.yaml            input_select.yaml     media_player.yaml     script.yaml           templates.yaml
binary_sensor.yaml    envisalink.yaml       http.yaml             keymaster             neato.yaml            sensors.yaml          tts.yaml
default_config.yaml   frontend.yaml         input_boolean.yaml    light.yaml            rest_command.yaml     shell_command.yaml    utility_meter.yaml

bash-5.1# cat templates.yaml
---
#  Templates / Test Sensors
#
#
template: !include_dir_merge_list ../entities/templates

So the parts you mentioned are in place
When looking at the templates structure, there are 3 folders currently. Everything in the “enphase” folder for templates works fine and loads

bash-5.1# pwd
/config/entities/templates

bash-5.1# ls *
enphase:
grid_export_power.yaml     grid_import_power.yaml     grid_solar_corrected.yaml

huum:
READ.ME                          huum.yaml.DISABLED               sauna_temperature.yaml.DISABLED

lights:
READ.ME                                   current_energy_used_lights.yaml.DISABLED  current_lights_on.yaml.DISABLED

An example of a working template

bash-5.1# cat enphase/grid_export_power.yaml
---
#
#
#

## ENPHASE TEMPLATE
- sensor:
    - name: Grid Export Power
      icon: mdi:solar-panel-large
      unit_of_measurement: "W"
      state_class: measurement
      device_class: power
      state: "{{ [0, states('sensor.envoy_12200xxxxxx_current_power_production') | int - states('sensor.envoy_12200xxxxxx_current_power_consumption') | int ] | max }}"

@CentralCommand would you mind sharing a template in your config that shows the new format?
Believe this is the new format (which I cannot seem to get working outside of my configuration.yaml

template:
  - sensors:
      ## HUUM Template
      sauna_temperature:
        value_template: "{{ state_attr('sensor.sauna_status', 'temperature') }}"
        device_class: temperature

This isn’t valid. It should be like this:

template:
  - sensors:
      ## HUUM Template
      - name: Sauna temperature
        state: "{{ state_attr('sensor.sauna_status', 'temperature') }}"
        device_class: temperature

All the _template fields are gone. If you’re familiar with the old format, the new format mostly has the same fields but with _template removed. Some were tweaked like value_template has become state and friendly_name_template is just name.

Also sensors takes a list not a dictionary. name gets slugified to become the entity ID.

thank you for this info… I will restructure these and see how it works out, be back later today with a report.
and appreciate the eyes on it

worked perfect… final some relief from getting the lingering templates out of my configuration.yaml