Generic configuration challenge

Hello to all,

I’m working an a generic configuration regarding four modbus devices on the same modbus.

My idea/goal is to have one generic description of the modbus devices and that I can use it multiple times. I’m almost there but I’m overlooking something that’s making me stuck. Who can help me further?

The file base.energy-meters.yaml is the main file of the config and is including .base.meter.yaml four times. The problem I’m phasing is that only the first part of
- platform: modbus_controller is added to the generated output. In summary: only address: 0 is added to the generated output and address: 2 and address: 4 are not.

See the source config and generated output below.

base.energy-meters.yaml

esphome:
  name: energy-meters
  friendly_name: energy-meters

esp32:
  board: m5stack-atom
  framework:
    type: esp-idf
    version: recommended

<<: !include .base.yaml

# Uart interface definition
uart:
  id: uart_energy_meters
  tx_pin: GPIO26
  rx_pin: GPIO32
#  baud_rate: 115200
  baud_rate: 38400
  parity: EVEN

# Modbus interface definition
modbus:
  uart_id: uart_energy_meters
  #send_wait_time: 500ms
  id: modbus_energy_meters


substitutions:
  first: pv
  second: heat_pump_outside
  third: heat_pump_inside
  fourth: ev
  
  
# Modbus devices definition
modbus_controller:
  - id: ${first}
    address: 1
    modbus_id: modbus_energy_meters
    setup_priority: -10
    update_interval: 5s
    
  - id: ${second}
    address: 2
    modbus_id: modbus_energy_meters
    setup_priority: -10
    update_interval: 5s
    
  - id: ${third}
    address: 3
    modbus_id: modbus_energy_meters
    setup_priority: -10
    update_interval: 5s

  - id: ${fourth}
    address: 4
    modbus_id: modbus_energy_meters
    setup_priority: -10
    update_interval: 5s

sensor:
  - <<: !include { file: .base.meter.yaml, vars: { device_name: "${first}" } }
  - <<: !include { file: .base.meter.yaml, vars: { device_name: "${second}" } }
  - <<: !include { file: .base.meter.yaml, vars: { device_name: "${third}" } }
  - <<: !include { file: .base.meter.yaml, vars: { device_name: "${fourth}" } }

.base.meter.yaml

  - platform: modbus_controller
    modbus_controller_id: ${device_name}
    name: "${device_name}_Phase_1_line_to_neutral_volts"
    id: "${device_name}_Phase_1_line_to_neutral_volts"
    <<: &volts_sensor
        address: 0
        register_type: read
        value_type: FP32
        unit_of_measurement: V
        device_class: voltage
        state_class: measurement
  - platform: modbus_controller
    modbus_controller_id: ${device_name}
    name: "${device_name}_Phase_2_line_to_neutral_volts"
    id: "${device_name}_Phase_2_line_to_neutral_volts"
    <<: *volts_sensor
    address: 2
  - platform: modbus_controller
    modbus_controller_id: pv
    name: "${device_name}_Phase_3_line_to_neutral_volts"
    id: "${device_name}_Phase_3_line_to_neutral_volts"
    <<: *volts_sensor
    address: 4

Generated output:

INFO Reading configuration /config/esphome/base.energy-meters.yaml...
INFO Configuration is valid!
substitutions:
  first: pv
  second: heat_pump_outside
  third: heat_pump_inside
  fourth: ev
esphome:
  name: energy-meters
  friendly_name: energy-meters
  build_path: .esphome/build/energy-meters
  platformio_options: {}
  includes: []
  libraries: []
  name_add_mac_suffix: false
  min_version: 2023.3.2
esp32:
  board: m5stack-atom
  framework:
    version: 4.4.4
    sdkconfig_options: {}
    advanced:
      ignore_efuse_mac_crc: false
    components: []
    source: ~3.40404.0
    platform_version: platformio/espressif32 @ 5.3.0
    type: esp-idf
  variant: ESP32
uart:
- id: uart_energy_meters
  tx_pin:
    number: 26
    mode:
      output: true
      input: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
    drive_strength: 20.0
  rx_pin:
    number: 32
    mode:
      input: true
      output: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
    drive_strength: 20.0
  baud_rate: 38400
  parity: EVEN
  rx_buffer_size: 256
  stop_bits: 1
  data_bits: 8
modbus:
- uart_id: uart_energy_meters
  id: modbus_energy_meters
  send_wait_time: 250ms
  disable_crc: false
modbus_controller:
- id: pv
  address: 0x01
  modbus_id: modbus_energy_meters
  setup_priority: -10.0
  update_interval: 5s
  command_throttle: 0ms
- id: heat_pump_outside
  address: 0x02
  modbus_id: modbus_energy_meters
  setup_priority: -10.0
  update_interval: 5s
  command_throttle: 0ms
- id: heat_pump_inside
  address: 0x03
  modbus_id: modbus_energy_meters
  setup_priority: -10.0
  update_interval: 5s
  command_throttle: 0ms
- id: ev
  address: 0x04
  modbus_id: modbus_energy_meters
  setup_priority: -10.0
  update_interval: 5s
  command_throttle: 0ms
sensor:
- platform: modbus_controller
  modbus_controller_id: pv
  name: pv_Phase_1_line_to_neutral_volts
  id: pv_Phase_1_line_to_neutral_volts
  address: 0
  register_type: read
  value_type: FP32
  unit_of_measurement: V
  device_class: voltage
  state_class: measurement
  disabled_by_default: false
  force_update: false
  bitmask: 0xFFFFFFFF
  skip_updates: 0
  force_new_range: false
  response_size: 0
  register_count: 0
- platform: modbus_controller
  modbus_controller_id: heat_pump_outside
  name: heat_pump_outside_Phase_1_line_to_neutral_volts
  id: heat_pump_outside_Phase_1_line_to_neutral_volts
  address: 0
  register_type: read
  value_type: FP32
  unit_of_measurement: V
  device_class: voltage
  state_class: measurement
  disabled_by_default: false
  force_update: false
  bitmask: 0xFFFFFFFF
  skip_updates: 0
  force_new_range: false
  response_size: 0
  register_count: 0
- platform: modbus_controller
  modbus_controller_id: heat_pump_inside
  name: heat_pump_inside_Phase_1_line_to_neutral_volts
  id: heat_pump_inside_Phase_1_line_to_neutral_volts
  address: 0
  register_type: read
  value_type: FP32
  unit_of_measurement: V
  device_class: voltage
  state_class: measurement
  disabled_by_default: false
  force_update: false
  bitmask: 0xFFFFFFFF
  skip_updates: 0
  force_new_range: false
  response_size: 0
  register_count: 0
- platform: modbus_controller
  modbus_controller_id: ev
  name: ev_Phase_1_line_to_neutral_volts
  id: ev_Phase_1_line_to_neutral_volts
  address: 0
  register_type: read
  value_type: FP32
  unit_of_measurement: V
  device_class: voltage
  state_class: measurement
  disabled_by_default: false
  force_update: false
  bitmask: 0xFFFFFFFF
  skip_updates: 0
  force_new_range: false
  response_size: 0
  register_count: 0
wifi:
  domain: .local
  reboot_timeout: 15min
  power_save_mode: LIGHT
  fast_connect: false
  enable_btm: false
  enable_rrm: false
  networks:
  - ssid: !secret 'wifi_ssid'
    password: !secret 'wifi_password'
    priority: 0.0
  use_address: energy-meters.local
logger:
  baud_rate: 0
  tx_buffer_size: 512
  deassert_rts_dtr: false
  hardware_uart: UART0
  level: DEBUG
  logs: {}
api:
  encryption:
    key: !secret 'api'
  port: 6053
  password: ''
  reboot_timeout: 15min
ota:
  password: !secret 'ota'
  safe_mode: true
  port: 3232
  reboot_timeout: 5min
  num_attempts: 10