esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Inclusion is not considered #5963

Closed dominik4545 closed 3 weeks ago

dominik4545 commented 3 weeks ago

The problem

Hey there,

As I have multiple ESP32/ESP8266 components with the same sensors, I want to use substitutions to avoid copy-paste-issues and just re-use my configuration.

Unfortunately, it's only working for me as long as the domain e.g. sensor is first used like in the configuration below: The BME680 sensor is loaded as the logs in the dashboard show but the DHT-22-configuration and the LDR-configuration is completely ignored. If I copy exact the same content of the sensor-yamls to the outpost.yaml instead of including it, everything works properly. The example below uses the esp32 (denky32) platform but this also occurs when using the esp8266 (d1_mini)

Do I have any issue in my inclusion/substitution process? What can I improve to not face this issue anymore?

Thanks and best regards, Dominik

Which version of ESPHome has the issue?

2024.6.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.6.4

What platform are you using?

ESP32

Board

denky32

Component causing the issue

No response

Example YAML snippet

### outpost.yaml
~~~yaml
##########################################################################
#
# ESPHome configuration for the outpost sensor module based on WROOM-32.
# Introduced in May 2024
#
##########################################################################

# Device information and settings
substitutions:
  device_name: "outpost"
  location: "outdoor"
  encryption_key: !secret outpost_encryption_key
  ota_password: !secret outpost_ota_password
  ip: !secret outpost_ip
  wifi_ssid: !secret wifi_ssid
  wifi_password: !secret wifi_password
  wifi_gateway: !secret wifi_gateway

# Include overall packages
packages:
  # Generic device configuration for WROOM-32
  device_base: !include esp32_denky32/board.yaml

  # Generic wifi configuration
  wifi: !include common/wifi.yaml

# Add I²C bus
<<: !include esp32_denky32/i2c.yaml

# Add BME680 sensor
<<: !include esp32_denky32/sensor_bme680.yaml

# Add DHT-22 sensor
<<: !include 
  file: esp32_denky32/sensor_dht22.yaml
  vars:
    location: ${location}_dht

# Add LDR sensor
<<: !include esp32_denky32/sensor_ldr.yaml
~~~

### i2c.yaml
~~~yaml
##########################################################################
#
# ESPHome generic configuration for I²C bus.
# Introduced in May 2024
#
##########################################################################

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: i2c_bus
~~~

### sensor_bme680.yaml
~~~yaml
##########################################################################
#
# ESPHome configuration for sensor BME680.
# Introduced in January 2024
#
##########################################################################

# Add configuration for the sensor itself
bme680_bsec:
  address: 0x77

sensor:
  - platform: bme680_bsec
    temperature:
      name: temperature_${location}
    pressure:
      name: pressure_${location}
    humidity:
      name: humidity_${location}
    iaq:
      name: iaq_${location}
      id: iaq
    co2_equivalent:
      name: co2_equivalent_${location}
    breath_voc_equivalent:
      name: breath_voc_equivalent_${location}

text_sensor:
  - platform: bme680_bsec
    iaq_accuracy:
      name: iaq_accuracy_${location}

  - platform: template
    name: iaq_classification_${location}
    icon: "mdi:checkbox-marked-circle-outline"
    lambda: |-
      if (int(id(iaq).state) <= 50) {
        return {"Hervorragend"};
      } else if (int(id(iaq).state) <= 100) {
        return {"Gut"};
      } else if (int(id(iaq).state) <= 150) {
        return {"Leicht verschmutzt"};
      } else if (int(id(iaq).state) <= 200) {
        return {"Mäßig verschmutzt"};
      } else if (int(id(iaq).state) <= 250) {
        return {"Schwer verschmutzt"};
      } else if (int(id(iaq).state) <= 350) {
        return {"Sehr stark verschmutzt"};
      } else if (int(id(iaq).state) >= 351) {
        return {"Extrem stark verschmutzt"};
      } else {
        return {"Unbekannt"};
      }
~~~

### sensor_ldr.yaml
~~~yaml
##########################################################################
#
# ESPHome generic configuration for LDR sensor.
# Introduced in June 2024
#
##########################################################################

sensor:
  # Light Dependent Resistor (LDR)
  - accuracy_decimals: 0
    filters:
      - multiply: 100
    icon: mdi:white-balance-sunny
    name: brightness_${location}
    platform: adc
    pin: GPIO34
    unit_of_measurement: "%"
    update_interval: 60s
~~~

### sensor_dht22.yaml
~~~yaml
##########################################################################
#
# ESPHome generic configuration for sensor DHT-22.
# Introduced in January 2024
#
##########################################################################

sensor:
  # Temperature and humidity sensor (DHT-22)
  - platform: dht
    model: DHT22
    pin: GPIO35
    humidity:
      name: humidity_${location}
      filters:
        - offset: ${humidity_offset}
    temperature:
      name: temperature_${location}
      filters:
        - offset: ${temperature_offset}
    update_interval: 60s
~~~

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 3 weeks ago

github issues are not for support requests. Come ask on the esphome discord server or one of the forums. You're using bare includes instead of putting them as packages. You can't have the same section twice which is what you get with the bare include. Packages combine things.