About to split configuration.yaml up and use !include - any advice welcome

Are there any pitfalls I need to be aware of before I split up my configuration file?
I’ve been using HA for over a year and I’ve got a big config file that could do with being split up as there are two large and very separate topics. I’ve done the cut/paste to create a cut down config plus a new file with one of the sets of code. Both files have a green tick in the editor.
Can I just replace configuration.yaml with my cut down version whith !include thenewone.yaml?
The new one has:
REST sensors
Template sensors
and sensors on the statistics, trigger and integration platforms.

Have a look here

it is @Tinkerer ‘s config and has it ‘all’ :grin:

1 Like

Thanks for the steer. As I see it, he has split his config into a vast number of single function small files. I was hoping to be able to group everything to do with an area of functionality into each yaml. Specifically, I have a lot of sensors and processing relating to my heating system that I feel belong in one file, and separately tons of stuff relating to local coastal conditions (tides, sea states, weather) that belong together but separately from the heating.
In the absence of any stronger warnins I’m just going to try it later today & see if it works!

So, you want packages then.

Thanks, that looks like it should do it. I’ll have a go…

Clearly not as simple as I hoped. Ive got the error

Invalid config for [sensor]: required key not provided @ data['platform']. Got None. (See ?, line ?).

Some of my setup is described below in the hope someone can spot what I’ve done wrong.
Near the start of my new configuration.yaml i put

homeassistant:
  packages: !include_dir_named packages

and in a packages directory I’ve got a myheatingmonitor.yaml containing a number of sections like…

template:
  - sensor:
# now we derive or infer the status of the heat pump
# 1 = DHW cycle, 2 = Htg cycle, 0 = OFF
    - name: HP pump status 
      unique_id: HP_pump_status
      state:

and

sensor:
  - platform: integration
    source: sensor.energy_calcs_hp_power_output
    name: Energy calcs HP output energy
    unique_id: energy_calcs_hp_output_energy
    round: 3
    unit_time: h
    unit_prefix: k
    method: left
  - platform: integration
    source: sensor.energy_calcs_hw_power_output
    name: Energy calcs HW output energy
    unique_id: energy_calcs_hw_output_energy
    round: 3
    unit_time: h
    unit_prefix: k
    method: left

etc

One of the etc files is the problem. Use a code share site to share them all

Sorry, didn’t mean to imply there are other files yet. ‘etc’ was a placeholder for lots of other instances of sensors in the one file. So in this, under the section starting

template:
  - sensor:

i have around 10 sensors - name:
In the section starting

- sensor:
  - platform:

there are 6 or so integration platform sensors, 15 or so statistics platform sensors and one trigger sensor.
Then I also have a single REST section with a dozen or so sensors in it.
Are you asking that I post the whole thing somewhere? I havent done that before - where can I learn how?
This is the file in the packages directory cut down to a couple of each sensor type:

# This is what I'm using to keep track of all the numbers used in my own heating analysis
# starting with knowing or guessing what the heatpump is doing 
rest:
  - resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=DDDbuildingID=BBB
    scan_interval: 60
    headers:
      X-MitsContextKey: XXXX
    sensor:
      - name: "HP_WaterPump1Status"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['WaterPump1Status'] | bool}}"
        unique_id: HP_WaterPump1Status

      - name: "HP_WaterPump2Status"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['WaterPump2Status'] |  bool}}"
        unique_id: HP_WaterPump2Status

      - name: "HP_Flow_delta_T"
        value_template: "{{ [value_json[0]['Structure']['Devices'][0]['Device']['FlowTemperature'] | float(0) - value_json[0]['Structure']['Devices'][0]['Device']['ReturnTemperature'] | float(0) , 0] | max }}"
        unique_id: HP_Flow_delta_T
        unit_of_measurement: °C
        device_class: temperature
        icon: mdi:thermometer
# **more like these** then:
template:
  - sensor:
# now we derive or infer the status of the heat pump
# 1 = DHW cycle, 2 = Htg cycle, 0 = OFF
    - name: HP pump status 
      unique_id: HP_pump_status
      state: > 
        {% if states('sensor.hp_pump_status') in ['unavailable', 'unknown'] %}
          {% set status = 0 %}
        {% else %}
          {% set status = states('sensor.HP_pump_status')|float(0) %}
        {% endif %}  
        {% if states('sensor.hp_waterpump2status') in ['unavailable', 'unknown'] or states('sensor.hp_waterpump1status') in ['unavailable', 'unknown']%}
          {{status}}
        {% elif states('sensor.hp_waterpump2status') | bool %}
          2
        {% elif states('sensor.hp_waterpump1status') | bool %}
          1
        {% elif states('sensor.shellyem_244cab419108_channel_2_power') | float(0) > 1400 %} 
          1
        {% elif states('sensor.shellyem_244cab419108_channel_2_power') | float(0) > 30 %} 
          2
        {% else %}
          0
        {% endif %}
# from which we get the rate at which the pump is flowing, stored as litres / min, convert to l/s
# which is then multiplied by the temperature loss in the heating circuits
# using the temp differential from the REST sensor is available, otherwise from the MELCloud integration 
# heat capacity of water 4.186 kJ/kgC, glycol correction factor = 0.959
# result is in kg/s * kJ/kgC ie kilowatts, convert to W for compatibility with heat loss calcs
    - name: Energy calcs HP power output
      unique_id: energy_calcs_hp_power_output
      unit_of_measurement: W
      state_class: measurement
      state: >
        {% set flows = [0, states('input_number.flow_rate_hw'), states('input_number.flow_rate_htg')] %}
        {% set flow = flows[states('sensor.HP_pump_status')|int]|default(0)|float(0)/60 %}
        {% if states('sensor.HP_Flow_delta_T') in ['unavailable', 'unknown','0'] %}
          {% set delta_t = states('sensor.ithaca_zone_1_flow_temperature') | float(0) - states('sensor.ithaca_zone_1_flow_return_temperature') | float(0) | default(0) %}
        {% else %}
          {% set delta_t = states('sensor.HP_Flow_delta_T')|float(0) %}
        {% endif %}
        {% set SHwater, GlycolFactor = 4.186, 0.959 %}
        {{ flow * delta_t * SHwater * GlycolFactor  * 1000}} 
# **more like these** then:

# now we integrate these over time to give kWh
sensor:
  - platform: integration
    source: sensor.energy_calcs_hp_power_output
    name: Energy calcs HP output energy
    unique_id: energy_calcs_hp_output_energy
    round: 3
    unit_time: h
    unit_prefix: k
    method: left
  - platform: integration
    source: sensor.energy_calcs_hw_power_output
    name: Energy calcs HW output energy
    unique_id: energy_calcs_hw_output_energy
    round: 3
    unit_time: h
    unit_prefix: k
    method: left
##################################################
## Gathering data for Ithaca energy spreadsheet ##
## yesterday stats using trigger see later      ##
##################################################
  - platform: statistics
    name: "HPin last 24hrs"
    unique_id: hpin_last_24hrs
    entity_id: sensor.shellyem_244cab419108_channel_2_energy
    state_characteristic: change
    max_age:
      hours: 24
  - platform: statistics
    name: "HWin last 24hrs"
    unique_id: hwin_last_24hrs
    entity_id: sensor.energy_calcs_hw_input_energy
    state_characteristic: change
    max_age:
      hours: 24

I found a misplaced trigger sensor which belongs in the templates section (just discovered the FOLD button in file editor that helped me). Will try this once the current hotwater cycle finishes so I don’t ruin another days stats.
Thanks for the patient support…

Yes that worked. Thanks to Tinkerer for your help. The lesson learned was to be really careful with how the sensors are organised in the packages file, which was actually the point of doing the split originally as I felt the edifice had got out of control, or at any rate I could no longer follow how I’d done it all over the months of ‘tinkering’ - so to speak!

1 Like