Moving YAML code from configuration.yaml to whatever.yaml

Hello good home automation people!

I have this conde in my configuration.yaml file and want to move it to whatever.yaml for example or sonoff.yaml in my case.

# Sonoff RF bridge settings
sonoff:    
  rfbridge:
    Basement contact sensor S opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor S  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor S closed  # button/alarm name in eWeLink application (close signal)

    Basement contact sensor L opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor L  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor L closed  # button/alarm name in eWeLink application (close signal)

    Basement motion sensor:  # button/alarm name in eWeLink application
      device_class: motion
      timeout: 30  # optional (default 120), timeout in seconds for auto turn off

so added this to my configuration.yaml

sonoff: !include sonoff.yaml

then created sonoff.yaml in the same folder where configuration.yaml is and pasted the whole conde inside sonoff.yaml but does not work at all. Why? I removed the sonoff: line and moved the whole code 2 character backwards ALT+TAB

# Sonoff RF bridge settings
  rfbridge:
    Basement contact sensor S opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor S  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor S closed  # button/alarm name in eWeLink application (close signal)

    Basement contact sensor L opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor L  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor L closed  # button/alarm name in eWeLink application (close signal)

    Basement motion sensor:  # button/alarm name in eWeLink application
      device_class: motion
      timeout: 30  # optional (default 120), timeout in seconds for auto turn off

Isnt this the right way?

I even tried just leaving in the configuration.yaml this:

sonoff:

and then pasting the code info sensors.yaml that I know is linked properly as there are other multiple working sensors:

# Sonoff RF bridge settings
- platform: sonoff
  reload: always
  rfbridge:
    Basement contact sensor S opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor S  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor S closed  # button/alarm name in eWeLink application (close signal)

    Basement contact sensor L opened:  # button/alarm name in eWeLink application (open signal)
      name: Basement door contact sensor L  # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: Basement contact sensor L closed  # button/alarm name in eWeLink application (close signal)

    Basement motion sensor:  # button/alarm name in eWeLink application
      device_class: motion
      timeout: 30  # optional (default 120), timeout in seconds for auto turn off

If possible let me know how I can move this code from current working state at configuration.yaml TO:

  1. TO a brand new sonoff.yaml
  2. TO the existing sensors.yaml

thank you!!

This video have a section on includes.

Are you seeing any errors in the home-assistant.log? I think it’s probably a very simple thing to fix but I’m not very well versed on how !include works with some of the vagaries of YAML indentation.

In all my !include files the lines are indented exactly as they would have been in configuration.yaml - not moved back, in other words.

I do not think it matter with the initial indentation.
I think the include ignores all indentation until the first character.

Splitting up the configuration - Home Assistant

!include customize.yaml is the statement that tells Home Assistant to insert the parsed contents of customize.yaml at that point. The contents of the included file must be yaml data that is valid at the location it is included.

If you write sensor: !include file.yaml, then you will get

sensor:
  <content of file.yaml>

The indentation will be made for you and I can change the indentation in front of the first key in the file.yaml as long as the indentations under the first key is correct.

I myself can strongly recommend to use ‘packages’ to avoid having to add each yaml in the config.

  packages: !include_dir_named packages

Then, in the config/packages folder you can add any yaml (if formatted correctly) and this allows you to have grouped yamls like sonoff but also combining multiple sensor/binary/rest/template in e.g. a my_weather.yaml

Thanks, I will watch the video for !include and try again. It all works inside the configuration.yaml so It must be an easy fix to move it to another yaml of my liking.

Thanks, I never knew about packages? Where can I learn all about it?

Packages - Home Assistant

Roughly speaking I have 10 yml files with each their own area. Electricity, weather, location, etc. and each have different types in them. My main benefit: I donot have to page back/forth between type-related file to find out which utility meter is based on what template sensor which might be based on a rest integration

1 Like