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.
esphome:
name: ${name}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pwd
reboot_timeout: 0s
fast_connect: true
manual_ip:
static_ip: ${ip}
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
id: button
# name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
on_press:
- switch.toggle: relay_template
on_multi_click:
- 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
then:
- switch.turn_on: restart_sonoff
switch:
- platform: gpio
pin: GPIO12
id: relay
- platform: template
name: ${friendly_name}
id: relay_template
lambda: |-
if (id(relay).state) {
return true;
} else {
return false;
}
turn_on_action:
- light.turn_on: status_led
- switch.turn_on: relay
turn_off_action:
- 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
output:
## https://esphomelib.com/esphomeyaml/components/output/esp8266_pwm.html
## create a PWM pin to control
- platform: esp8266_pwm
id: basic_green_led
pin:
number: GPIO13
inverted: True
light:
## https://esphomelib.com/esphomeyaml/components/light/monochromatic.html
## 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
text_sensor:
- platform: version
name: ${friendly_name} ESPHome Version
sensor:
- 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.
Another way to modularize and reuse your configuration is to use packages. This feature allows you to put common pieces of configuration in separate files and keep only unique pieces of your config in the main yaml file. All definitions from packages will be merged with your main config in non-destructive way so you could always override some bits and pieces of package configuration.
By resuscitate a 3 year old thread and adding 2 sentences with value to the topic?
Packages in esphome aren’t a secret at all. Like the secrets.yaml most of the people with a couple of nodes probably use packages as it just simplifies things and avoids repeating configs across devices.
And you didn’t gave a thought that a topic from 2019 might be heavily outdated in 2023 (that’s 4 years later) specially for projects involving/growing fast like esphome or HA?