Using attributes of entity passed as script's variable

hi

trying to create a variable using attribute of an entity passed as a variable to the script:

  wled_turn_on_via_effect:
    description: "turn WLED on via an effect"
    fields:
      entity:
        description: "WLED entity"
        example: light.wled
    variables:
        old_speed: {{ state_attr(entity, 'speed') }}

getting:

missed comma between flow collection entries at line 15, column 49:
     ... d: {{ state_attr(entity, 'speed') }}
                                         ^

if I try to access as

        old_speed: {{ states(entity.speed) }}

or

        old_speed: '{{ entity.speed }}'

I get a null value later on when casting to int in script’s sequence:

      - service: wled.effect
        target:
          entity_id: "{{ entity }}"
        data:
          effect: 'Candy Cane'
          speed: "{{ old_speed | int }}"

At the very least, you need to quote the old_speed variable’s template:

    variables:
        old_speed: "{{ state_attr(entity, 'speed') }}"

If the attribute is a number already (i.e., not a string), then you shouldn’t need to cast it to an int later (unless you want to truncate a value with a non-zero fractional part.)

thanks, did the thing. I thought I have tried that though. really appreciated.