Script Works Fine, VSCode Says I Have Errors

I have this issue with a lot of my scripts. This is a simpler one to work with here. I’ve added the “max” option to this one just to include it, even though the default is fine.

I have my scripts, each in their own file.

script: !include_dir_named ../scripts

so this script is…

/config/scripts/light_ramp_down.yaml

This script works just fine.

alias: "Light Ramp Down"
description: "..."
mode: "queued"
max: 40

fields:
  entities:
    description: "The entities to ramp down."
    example: "[light.desk_lamps, light.kitchen_lights]"

sequence:
  - repeat:
      count: "{{ entities | length }}"
      sequence:
        - variables:
            logger_name: "eav.script.util.light_ramp_down"
            debug_level: "{{ states('input_select.automation_log_level') }}"
            entity: "{{ entities[repeat.index-1] }}"
            brightness: "{{ (state_attr(entity, 'brightness')|int(0) / 255 * 100)|int }}"
            step: >
              {% if brightness|int >= 30 %}10{% else %}5{% endif %}
        - service: light.turn_on
          data:
            entity_id: "{{ entity }}"
            brightness_pct: >
              {{ [brightness|int(0) - step|int(0), 5]|max }}
            transition: 0
        - service: system_log.write
          data:
            message: "Ramping down {{entity}} from {{brightness}} by {{step}}."
            level: "{{debug_level}}"
            logger: "{{logger_name}}"

Here is a screenshot to show VSCode…

As soon as I put the fields section it, VSCode starts detecting an error.

Just wondering if I am doing something wrong.

Your script needs an object_id and to be indented under that. e.g.

light_ramp_down:   ### <--- object_id
  alias: "Light Ramp Down"
  description: "..."
  mode: "queued"
  max: 40

  fields:
    entities:
      description: "The entities to ramp down."
      example: "[light.desk_lamps, light.kitchen_lights]"

  sequence:
    - repeat:
        count: "{{ entities | length }}"
        etc...

Look at the example here: https://www.home-assistant.io/integrations/script/#full-configuration

I should have mentioned I have each script in it’s own file. I’ll update my first post.

script: !include_dir_named ../scripts

so this script is…

/config/scripts/light_ramp_down.yaml