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
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.
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.
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:
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:
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.
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# 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
- 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.