Tidy/splitting up configuration.yaml not working

Hello everyone,

after I got some sensors working via configuration.yaml I soon want to tidy up this file and split it to “sub-yamls”.

I want following yaml files to include in the configuration.yaml:

config/sensors/devices.yaml
config/sensors/temperature.yaml

In configuration.yaml I include those two files via
template: !include_dir_merge_named sensors
I tried with trailing / and without.

# temperature.yaml

- sensor:
    - name: "Konstant Schwellwert Temperaturdifferenz"
      unique_id: konstant_schwellwert_temperaturdifferenz
      state: >
        25
      unit_of_measurement: "°C"
      device_class: temperature

- sensor:
    - name: "Konstant Minimum Aussen"
      unique_id: konstant_minimum_aussen
      state: >
        10
      unit_of_measurement: "°C"
      device_class: temperature

- binary_sensor:
    - unique_id: temperaturdifferenz_schlafzimmer_aussen
      name : Temperaturdifferenz Schlafzimmer - aussen
      state : >
        {% set temperatur_schlafzimmer = states('sensor.temperatur_schlafzimmer') | float(100) %}
        {% set temperatur_aussen = states('sensor.temperatur_aussen') | float(-100) %}
        {% set konstant_minimum_aussen = states('sensor.konstant_minimum_aussen') | float(0) %}
        {% set diff = temperatur_schlafzimmer - temperatur_aussen %}
        {% if diff < konstant_minimum_aussen %}
          True
        {% else %}
          False
        {% endif %}
#devices.yaml

- sensor:
  - name: Starte Geschirrspueler
    unique_id: sensor.starte_geschirrspueler
    state: >
        {% if states("sensor.siemens_geschirrspueler_remainingprogramtime") not in ["unknown", "unavailable", "", None] %}
          {% set sensor = 'sensor.epex_spot_data_net_price' %}
          {% set date1 = as_timestamp(now()) %}
          {#{ date1 | timestamp_custom('%D-%H:%M', local=True) }#}

          {% set date2 = as_timestamp(states('sensor.siemens_geschirrspueler_remainingprogramtime')) %}
          {#{ date2 | timestamp_custom('%D-%H:%M', local=True) }#}

          {% set difference = date2 - date1 %}
          {% set hours = (difference / 3600) | round(2) %}

          {% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=hours, start='06:00', end='22:00', include_tomorrow=false) }}
        {% endif %}
    availability: >
        {{
          is_state('switch.siemens_geschirrspueler_powerstate', 'on')
          and is_state('binary_sensor.siemens_geschirrspueler_remotecontrolstartallowed', 'on')
          and is_state('binary_sensor.siemens_geschirrspueler_doorstate', 'off')
        }}

The sensors in the two extra files will not load > developer tools say unavailable > not integrated any more.

I have Studio Code Server installed, wich is very helpful, but it shows a platform error when editing the two extra yamls.

I tried around a day, but cant find what’s wrong. Pls help. :slight_smile:

template sensors are lists so you are using the wrong merge directive.

try this:

template: !include_dir_merge_list sensors/

then in the first yaml file remove the second "- sensor: "

# temperature.yaml

- sensor:
    - name: "Konstant Schwellwert Temperaturdifferenz"
      unique_id: konstant_schwellwert_temperaturdifferenz
      state: >
        25
      unit_of_measurement: "°C"
      device_class: temperature

    - name: "Konstant Minimum Aussen"
      unique_id: konstant_minimum_aussen
      state: >
        10
      unit_of_measurement: "°C"
      device_class: temperature

- binary_sensor:
    - unique_id: temperaturdifferenz_schlafzimmer_aussen
      name : Temperaturdifferenz Schlafzimmer - aussen
      state : >
        {% set temperatur_schlafzimmer = states('sensor.temperatur_schlafzimmer') | float(100) %}
        {% set temperatur_aussen = states('sensor.temperatur_aussen') | float(-100) %}
        {% set konstant_minimum_aussen = states('sensor.konstant_minimum_aussen') | float(0) %}
        {% set diff = temperatur_schlafzimmer - temperatur_aussen %}
        {% if diff < konstant_minimum_aussen %}
          True
        {% else %}
          False
        {% endif %}

Also I’m not sure why you are using the template multi-line indicator (>) for use with a constant. I’m not sure it will work like that since it expects a template in that location. So I don’t know why you are using a template sensor for that usage instead of some other more appropriate thing like an input_number since it’s just a constant.

2 Likes

Hello @finity ,

the combination of !include_dir_merge_list
and removing the second - sensor-line in the temperatures.yaml did the trick.

thanks alot!

1 Like