Switch output ID() in a for() loop

Hi

I have searched a bunch and tried to get both grok and ChatGPT to help me :wink:

I am trying to control an schneider electric (LK) IHC output module, they communicate very simply by sending the ON / OFF signal depending on the period og high/low :slight_smile:
the communication to the module from my esp32 is working and not the question in this post.

I have an issue where I am trying to call different switches states by their ID in a for loop.
and then use the loop index to call different switches/outputs, but, it wonโ€™t compile.

The outputs I would like to control is in 16 sets of 8. there could be โ€˜1โ€™ to โ€˜16โ€™ sets active. thats why I really want to have a loop :wink:

This is my for loop,

script:
- id: pulse_train_output_01
  then:
      - lambda: |-
          id(pulse_output_01).turn_off(); // turn off signal
          esphome::delay_microseconds_safe (id(Pulselenthperiod)); 
      - lambda: |- 
          for (int i = 0; i < 16; i++) {
            if(id(Output_module_enabled)[i]){
              for (int y = 0; y < 8; y++) {
                char buf[10];
                sprintf(buf,"output_%d_%d", i+1, y+1);
                std::string buf_str(buf);
                auto mid_component = id(output_ids)[i][y].c_str();
                id(Output_active)[y] = id(mid_component).state;
              }
              for (int x = 0; x < 16; x++) { // send the 16 states
              id(pulse_output_01).turn_on();
              if (id(Output_active)[x]) {
                esphome::delay_microseconds_safe (159); // if input in ON, 
                id(pulse_output_01).turn_off();
                esphome::delay_microseconds_safe (465); // turn off signal
              } else {
                esphome::delay_microseconds_safe (311); // if input is OFF
                id(pulse_output_01).turn_off();
                esphome::delay_microseconds_safe (312); // turn off signal
              }
              }
            }
          }
          id(pulse_output_01).turn_on();

But I keep getting compile errors with the ID() not existing or not in correct format.
ChatGPT suggested that the ID should be an argument and not a string. so created the array of actual output ID names โ€˜output_idsโ€™ in the following format:

  - id: output_ids
    type: std::string[16][8]
    initial_value: '{
      {"output_1_1", "output_1_2", "output_1_3", "

When I only had the first 8 outputs, I made it like this, worked fine. trying to do the same in the loop :wink:

id(Output_active)[0] = id(output_1_1).state; 
id(Output_active)[1] = id(output_1_2).state; 
id(Output_active)[2] = id(output_1_3).state; 
...

compile error:

/config/esphome/heatingcontrollertest.yaml:148:56: error: request for member 'state' in '* mid_component', which is of non-class type 'const char'
                 id(Output_active)[y] = id(mid_component).state;

Anyone with an idea how to adress the IDโ€™s in the for loop :slight_smile: ?
I have from output_1_1 to output_16_8