Parameters in esphome script lambdas

I am trying to set brightness of a number of lights in a script with a lambda approach.

I don´t get the parameter to work though:

api:
  services:  
    - service: set_name_brightness
      variables:
        brightness: float
      then:
        - script.execute: 
            id: set_name_brightness
            brightness: brightness

# Light Control Scripts
script:
  - id: set_name_brightness
    parameters:
      brightness: float
    then:
      - lambda: |-
          id(id_L_OUTBD_name).turn_on().set_brightness(brightness).perform();
          id(id_R_OUTBD_name).turn_on().set_brightness(brightness).perform();

get´s me here:

/config/esphome/eh8266-panel.yaml: In function 'void setup()':
/config/esphome/eh8266-panel.yaml:1291:43: error: 'brightness' was not declared in this scope
*** [.pioenvs/eh8266-panel/src/main.cpp.o] Error 1

So far I tried:
Other variable name, other type, Assigning it in the lambda to a temporary variable first… All with the same outcome.

Hi, I was just working with parameters today and I was researching a different issue and saw your post.
You need to pass the arrays first, example is here:

Hope it helps!

Hi Ronnie(Last),
I am having a bit of trouble comprehending…
First of all I do not need an array, just a simple value. Then I do not have an issue with non-templatable IDs which seems to be the case in the post you linked.

Do you suggest to use an array instead of a simple float because the “pre-access” in a (helper) binary_sensor would make it work for my example? Or is the array not necessary for me and I only need to access the variable in a lambda somewhere before the actual script?

Sorry, seems to me as if I am not getting what you are trying to point me to.

Yes, the arrays confused me initially too, but as I’m not a programmer I just rolled with it.
To show my working example, this is a button on an ESP32:

  - platform: gpio  #      UPSTAIRS ZONE - physical button
    pin: 
      number: GPIO17
      mode:
        input: true
        pullup: true
      inverted: True
    id: upstairs_button_1
    on_press: # Single press
      then:
        - lambda: |-
            std::vector<std::string> text_content = {"BOOST"};
            std::vector<int> duration_in_min = {60};
            id(upstairs_heating_generic)->execute(text_content, duration_in_min);

When you press the button it passes two parameters - one a string called “text_content” with the word BOOST and the second an int called “duration_in_min” with the integer 60 , to the script called “upstairs_heating_generic”.

The script then takes in both “parameters:” and in my case I use (rightly or wrongly) index [0] of both parameters which I use in lambdas as I need. Index [0] is just the first and only object in the array.

  - id: upstairs_heating_generic
    mode: restart
    parameters:
      text_content: string[]
      duration_in_min: int[]
    then:
            - switch.turn_on: brb_us_direct
            - text_sensor.template.publish:
                id: text_state_us_heating
                state: !lambda return text_content[0];
            - text_sensor.template.publish:
                id: text_time_us_heating # When run, send a text string to HA with the boost completion time
                state: !lambda |-
                    char str[17];
                    time_t currTime = id(ds1307_time).now().timestamp + (duration_in_min[0] * 60);
                    strftime(str, sizeof(str), "%H:%M", localtime(&currTime));
                    return  { str };

Hope it helps!