Multiple Common Components

I’m trying to do exactly (i think) what the OP in the link below was trying to do. Otto mentioned in a reply that it’s a limitation of yaml and to use the !include_dir_list directive instead. However, I can’t figure out how to actually do this. I’ve created a directory with an example file in it but don’t know the syntax to call it from the main yaml file. Ideally, I’d have multiple files in that directory that each define a sensor or set of sensors that get merged at compile time.


Reference File:

- platform: wifi_signal
  id: wifi
  name: ${friendly_name} - RSSI
  icon: "mdi:wifi"
  update_interval: 60s
  unit_of_measurement: 'dB'
  accuracy_decimals: 0

- platform: uptime
  id: uptime
  name: ${friendly_name} - Uptime
  icon: "mdi:timer"
  update_interval: 60s

Things I’ve tried in the main yaml file without success:

sensor:  !include_dir_list   path/to/files/
  !include_dir_list   path/to/files/
sensor:  <<: !include_dir_list   path/to/files/
  <<: !include_dir_list   path/to/files/

Anyone have any ideas? (I’m on version 1.12.1)


here is an example using a sonoff basic. i have two files that i created in my esphome config directory:


  name: boot_dryer
  friendly_name: Boot Dryer
<<: !include common_sonoff_basic.yaml


  name: ${name}
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout

  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  reboot_timeout: 0s
  fast_connect: true
    static_ip: ${ip}
# Enable logging

# Enable Home Assistant API
  reboot_timeout: 0s

  - platform: gpio
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    # name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
      - switch.toggle: relay_template
    - timing:
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at least 0.2s
        - switch.turn_on: restart_sonoff
  - platform: gpio
    pin: GPIO12
    id: relay
  - platform: template
    name: ${friendly_name}
    id: relay_template
    lambda: |-
      if (id(relay).state) {
        return true;
      } else {
        return false;
      - light.turn_on: status_led
      - switch.turn_on: relay
      - light.turn_off: status_led
      - switch.turn_off: relay
    # optimistic: true # this will change the toggle switch to individual on/off buttons
  - platform: restart
    id: restart_sonoff

  ## create a PWM pin to control
  - platform: esp8266_pwm
    id: basic_green_led
      number: GPIO13
      inverted: True

  ## attach a monochrome light to the PWM pin
  - platform: monochromatic
    # name: "Sonoff Basic Green LED" # uncomment to expose the led as a light with brightness control
    output: basic_green_led
    id: status_led
    default_transition_length: 1ms # controls the light fade/transition time
  - platform: version
    name: ${friendly_name} ESPHome Version
  - platform: wifi_signal
    name: ${friendly_name} WiFi Signal Strength
    update_interval: 60s

The substitutions pass those variables to the !included yaml file.

I have all of that working great. The problem is if I include two files that, for example, both have a sensor entry, the latest one takes precedence and overtired any other services sensors. (See link in original post)
I’m looking to be able to add multiple files that couple define entities and Otto hinted at a method to do so but I can’t figure out the syntax.


Just tripped over your post looking to do the same thing. I have 1 of 10 (ish) sonoff basics I would like a extra template switch on and would have prefered shared YAML for the rest

As Otto said it’s a YAML limitation. I think what we would like here is the equivalent of HA packages for ESPHome

@finity’s example above is designed for multiple devices all with the same config except names. This appears to be about as good as it gets at the moment.

If it helps any I have had success with multiple includes as long as you avoid using the same key in them. This allows me to at least split out core config such as wifi, logger, ota etc.

“I think what we would like here is the equivalent of HA packages for ESPHome”

Exactly! :slight_smile: